Skip to content

Commit cbf1d20

Browse files
author
gituser
committed
Merge branch 'hotfix_1.10_4.0.x_31011' into 1.10_release_4.0.x
2 parents 76f133f + 8514d00 commit cbf1d20

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,21 @@ private static void rebuildSelectNode(SqlNodeList selectList, SqlSelect sqlSelec
163163

164164
for (int index = 0; index < selectList.size(); index++) {
165165
if (selectList.get(index).getKind().equals(SqlKind.AS)
166-
|| ((SqlIdentifier) selectList.get(index)).names.size() == 1) {
166+
|| (selectList.get(index).getClass().equals(SqlIdentifier.class)
167+
&& ((SqlIdentifier) selectList.get(index)).names.size() == 1)) {
167168
sqlNodes.add(selectList.get(index));
168169
continue;
169170
}
171+
172+
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+
}
177+
throw new RuntimeException(String.format("Illegal statement! Please check the statement: %s",
178+
selectList.get(index).toString()));
179+
}
180+
170181
sqlNodes.add(transformToAsNode(selectList.get(index)));
171182
}
172183
sqlSelect.setSelectList(sqlNodes);

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.List;
3234
import java.util.Set;
@@ -41,6 +43,7 @@
4143
*/
4244

4345
public class SqlParser {
46+
private static final Logger LOG = LoggerFactory.getLogger(SqlParser.class);
4447

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

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

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

95103
if(!result){

0 commit comments

Comments
 (0)