Skip to content

Commit 8514d00

Browse files
committed
优化日志及异常提示
1 parent 850ca0a commit 8514d00

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

core/src/main/java/com/dtstack/flink/sql/parser/InsertSqlParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ private static void rebuildSelectNode(SqlNodeList selectList, SqlSelect sqlSelec
170170
}
171171

172172
if (!selectList.get(index).getClass().equals(SqlIdentifier.class)) {
173+
if (selectList.get(index).getKind().equals(SqlKind.LITERAL)) {
174+
throw new IllegalArgumentException(String.format("Constants %s in the SELECT statement must be aliased!",
175+
selectList.get(index).toString()));
176+
}
173177
throw new RuntimeException(String.format("Illegal statement! Please check the statement: %s",
174178
selectList.get(index).toString()));
175179
}

core/src/main/java/com/dtstack/flink/sql/parser/SqlParser.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
19+
2020

2121
package com.dtstack.flink.sql.parser;
2222

@@ -27,6 +27,8 @@
2727
import org.apache.commons.lang3.StringUtils;
2828
import com.google.common.collect.Lists;
2929
import com.google.common.base.Strings;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032

3133
import java.util.ArrayList;
3234
import java.util.List;
@@ -42,6 +44,7 @@
4244
*/
4345

4446
public class SqlParser {
47+
private static final Logger LOG = LoggerFactory.getLogger(SqlParser.class);
4548

4649
private static final char SQL_DELIMITER = ';';
4750

@@ -84,13 +87,18 @@ public static SqlTree parseSql(String sql, String pluginLoadMode) throws Excepti
8487
}
8588
boolean result = false;
8689
for(IParser sqlParser : sqlParserList){
87-
if(!sqlParser.verify(childSql)){
88-
continue;
89-
}
90+
try {
91+
if (!sqlParser.verify(childSql)) {
92+
continue;
93+
}
9094

91-
sqlParser.parseSql(childSql, sqlTree);
92-
result = true;
93-
break;
95+
sqlParser.parseSql(childSql, sqlTree);
96+
result = true;
97+
break;
98+
} catch (Exception e) {
99+
LOG.error("'{}' parser error, detail info: {}", childSql, e.getMessage(), e);
100+
throw e;
101+
}
94102
}
95103

96104
if(!result){

0 commit comments

Comments
 (0)