fix(数据集): 修复SQL片段分号结尾后有空格、换行符报错的问题

This commit is contained in:
junjun 2024-08-23 10:18:00 +08:00
parent 8259f4df38
commit 5af122cfe9
3 changed files with 4 additions and 6 deletions

View File

@ -19,9 +19,7 @@ import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.*; import net.sf.jsqlparser.statement.select.*;
import net.sf.jsqlparser.util.deparser.ExpressionDeParser; import net.sf.jsqlparser.util.deparser.ExpressionDeParser;
import net.sf.jsqlparser.util.deparser.SelectDeParser; import net.sf.jsqlparser.util.deparser.SelectDeParser;
import org.apache.calcite.config.Lex;
import org.apache.calcite.sql.*; import org.apache.calcite.sql.*;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser; import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.sql.util.SqlShuttle; import org.apache.calcite.sql.util.SqlShuttle;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@ -59,7 +57,7 @@ public class SqlparserUtils {
Statement statement = CCJSqlParserUtil.parse(tmpSql); Statement statement = CCJSqlParserUtil.parse(tmpSql);
Select select = (Select) statement; Select select = (Select) statement;
if(CollectionUtils.isNotEmpty(select.getWithItemsList())){ if (CollectionUtils.isNotEmpty(select.getWithItemsList())) {
for (Iterator<WithItem> iter = select.getWithItemsList().iterator(); iter.hasNext(); ) { for (Iterator<WithItem> iter = select.getWithItemsList().iterator(); iter.hasNext(); ) {
WithItem withItem = iter.next(); WithItem withItem = iter.next();
ParenthesedSelect parenthesedSelect = (ParenthesedSelect) withItem.getSelect(); ParenthesedSelect parenthesedSelect = (ParenthesedSelect) withItem.getSelect();
@ -484,7 +482,7 @@ public class SqlparserUtils {
DEException.throwException(Translator.get("i18n_sql_not_empty")); DEException.throwException(Translator.get("i18n_sql_not_empty"));
} }
if (sql.trim().endsWith(";")) { if (sql.trim().endsWith(";")) {
sql = sql.substring(0, sql.length() - 1); sql = sql.trim().substring(0, sql.length() - 1);
} }
if (StringUtils.isNotEmpty(sqlVariableDetails)) { if (StringUtils.isNotEmpty(sqlVariableDetails)) {

View File

@ -451,7 +451,7 @@ public class CopilotManage {
if (type.equals("oracle") || type.equals("sqlServer")) { if (type.equals("oracle") || type.equals("sqlServer")) {
try { try {
if (copilotSQL.trim().endsWith(";")) { if (copilotSQL.trim().endsWith(";")) {
copilotSQL = copilotSQL.substring(0, copilotSQL.length() - 1); copilotSQL = copilotSQL.trim().substring(0, copilotSQL.length() - 1);
} }
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
datasourceSchemaDTO.setType(type); datasourceSchemaDTO.setType(type);

View File

@ -21,7 +21,7 @@ public class SqlUtils {
public static String addSchema(String sql, String schema) { public static String addSchema(String sql, String schema) {
if (sql.trim().endsWith(";")) { if (sql.trim().endsWith(";")) {
sql = sql.substring(0, sql.length() - 1); sql = sql.trim().substring(0, sql.length() - 1);
} }
SqlParser.Config config = SqlParser.Config config =