You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2020/04/28 08:18:15 UTC
[kylin] branch 2.6.x updated: KYLIN-4245 SqlConverter returns wrong
syntax SQL when SqlParser fails for JDBC source
This is an automated email from the ASF dual-hosted git repository.
shaofengshi pushed a commit to branch 2.6.x
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/2.6.x by this push:
new 2841bb3 KYLIN-4245 SqlConverter returns wrong syntax SQL when SqlParser fails for JDBC source
2841bb3 is described below
commit 2841bb399e9c094f58b4d935e9a77464d82859db
Author: yaqian.zhang <59...@qq.com>
AuthorDate: Tue Apr 14 11:30:51 2020 +0800
KYLIN-4245 SqlConverter returns wrong syntax SQL when SqlParser fails for JDBC source
---
.../kylin/sdk/datasource/framework/conv/SqlConverter.java | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/SqlConverter.java b/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/SqlConverter.java
index e8302e8..13af472 100644
--- a/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/SqlConverter.java
+++ b/datasource-sdk/src/main/java/org/apache/kylin/sdk/datasource/framework/conv/SqlConverter.java
@@ -41,8 +41,7 @@ public class SqlConverter {
}
public String convertSql(String orig) {
- // for jdbc source, convert quote from backtick to double quote
- String converted = orig.replaceAll("`", "\"");
+ String converted = orig;
if (!configurer.skipHandleDefault()) {
String escapedDefault = SqlDialect.CALCITE
@@ -52,12 +51,17 @@ public class SqlConverter {
}
if (!configurer.skipDefaultConvert()) {
+ String beforeConvert = converted;
try {
+ // calcite cannot recognize `, convert ` to " before parse
+ converted = converted.replaceAll("`", "\"");
SqlNode sqlNode = SqlParser.create(converted).parseQuery();
sqlNode = sqlNode.accept(sqlNodeConverter);
converted = sqlWriter.format(sqlNode);
} catch (Throwable e) {
- logger.error("Failed to default convert sql, will use the input: {}", orig, e);
+ logger.error("Failed to default convert sql, will use the input: {}", beforeConvert, e);
+ // revert to beforeConvert when occur Exception
+ converted = beforeConvert;
} finally {
sqlWriter.reset();
}