[Fix](dialect) Fix trino dialect converter when sql does not end with delimiter. (#29106)
Co-authored-by: wangxiangyu <wangxiangyu@360shuke.com>
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user