This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 4266432d111 [Fix](dialect) Fix trino dialect converter when sql does
not end with delimiter. (#29106)
4266432d111 is described below
commit 4266432d11160c66d52c2e2b4c67b824556dc831
Author: Xiangyu Wang <[email protected]>
AuthorDate: Fri Dec 29 18:02:57 2023 +0800
[Fix](dialect) Fix trino dialect converter when sql does not end with
delimiter. (#29106)
Co-authored-by: wangxiangyu <[email protected]>
---
.../doris/nereids/parser/trino/TrinoParser.java | 20 ++++++++++++++++----
.../doris/nereids/parser/NereidsParserTest.java | 14 ++++++++++++++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/trino/TrinoParser.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/trino/TrinoParser.java
index 671af5e7f05..82d9b9e93a6 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/trino/TrinoParser.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/trino/TrinoParser.java
@@ -42,9 +42,8 @@ public class TrinoParser {
public static final Logger LOG = LogManager.getLogger(TrinoParser.class);
- private static final io.trino.sql.parser.ParsingOptions PARSING_OPTIONS =
- new io.trino.sql.parser.ParsingOptions(
-
io.trino.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DECIMAL);
+ private static final io.trino.sql.parser.ParsingOptions PARSING_OPTIONS =
new io.trino.sql.parser.ParsingOptions(
+
io.trino.sql.parser.ParsingOptions.DecimalLiteralTreatment.AS_DECIMAL);
/**
* Parse with trino syntax, return null if parse failed
@@ -52,7 +51,8 @@ public class TrinoParser {
public static @Nullable List<StatementBase> parse(String sql,
SessionVariable sessionVariable) {
final List<StatementBase> logicalPlans = new ArrayList<>();
try {
- io.trino.sql.parser.StatementSplitter splitter = new
io.trino.sql.parser.StatementSplitter(sql);
+ io.trino.sql.parser.StatementSplitter splitter = new
io.trino.sql.parser.StatementSplitter(
+ addDelimiterIfNeeded(sql));
ParserContext parserContext = new
ParserContext(ParseDialect.TRINO_395);
StatementContext statementContext = new StatementContext();
for (io.trino.sql.parser.StatementSplitter.Statement statement :
splitter.getCompleteStatements()) {
@@ -87,4 +87,16 @@ public class TrinoParser {
io.trino.sql.tree.Statement statement = TrinoParser.parse(sql);
return (T) new TrinoLogicalPlanBuilder().visit(statement,
parserContext);
}
+
+ /**
+ * {@link io.trino.sql.parser.StatementSplitter} use ";" as the delimiter
if not set
+ * So add ";" if sql does not end with ";",
+ * otherwise {@link
io.trino.sql.parser.StatementSplitter#getCompleteStatements()} will return
empty list
+ */
+ private static String addDelimiterIfNeeded(String sql) {
+ if (!sql.trim().endsWith(";")) {
+ return sql + ";";
+ }
+ return sql;
+ }
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
index 9baee503cfc..dc7e336433f 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/parser/NereidsParserTest.java
@@ -206,6 +206,20 @@ public class NereidsParserTest extends ParserTestBase {
Assertions.assertTrue(logicalPlan1 instanceof ExplainCommand);
}
+ @Test
+ public void testParseSingleStmtWithTrinoDialect() {
+ String sql = "select `AD``D` from t1 where a = 1";
+ NereidsParser nereidsParser = new NereidsParser();
+ SessionVariable sessionVariable = new SessionVariable();
+ sessionVariable.setSqlDialect("trino");
+ // test fall back to doris parser
+ List<StatementBase> statementBases = nereidsParser.parseSQL(sql,
sessionVariable);
+ Assertions.assertEquals(1, statementBases.size());
+ Assertions.assertTrue(statementBases.get(0) instanceof
LogicalPlanAdapter);
+ LogicalPlan logicalPlan0 = ((LogicalPlanAdapter)
statementBases.get(0)).getLogicalPlan();
+ Assertions.assertTrue(logicalPlan0 instanceof UnboundResultSink);
+ }
+
@Test
public void testParseSQLWithSparkSqlDialect() {
// doris parser will throw a ParseException when derived table does
not have alias
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]