morrySnow commented on code in PR #39113: URL: https://github.com/apache/doris/pull/39113#discussion_r1710599086
########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilderForCreateView.java: ########## @@ -56,6 +56,10 @@ /**LogicalPlanBuilderForCreateView*/ public class LogicalPlanBuilderForCreateView extends LogicalPlanBuilder { + public LogicalPlanBuilderForCreateView() { + super(null); Review Comment: i think it should use hint too? for example we could use hint to change sql mode, if create view cannot process it correctly it could generate wrong column type. or cannot analyze create view statement correctly. ########## fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4: ########## @@ -72,6 +72,19 @@ lexer grammar DorisLexer; public void markUnclosedComment() { has_unclosed_bracketed_comment = true; } + + // This variable will hold the external state + private boolean channel2; Review Comment: why need this var? i think we should always let hint go to channel 2 ? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java: ########## @@ -290,9 +292,37 @@ public Optional<String> parseForSyncMv(String sql) { return logicalPlanBuilderForSyncMv.getQuerySql(); } + /** get hint map */ + public static Map<Integer, ParserRuleContext> getHintMap(String sql, + Function<DorisParser, ParserRuleContext> parseFunction) { + // parse hint first round + DorisLexer hintLexer = new DorisLexer(new CaseInsensitiveStream(CharStreams.fromString(sql))); + hintLexer.setChannel2(true); + CommonTokenStream hintTokenStream = new CommonTokenStream(hintLexer); Review Comment: antlr could generate one stream and get specific channel token from it by `getHiddenTokensToRight`, so could we use it to get hint in `visitRegularQuerySpecification`? ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilderForSyncMv.java: ########## @@ -49,6 +49,10 @@ public class LogicalPlanBuilderForSyncMv extends LogicalPlanBuilder { private Optional<String> querySql; + public LogicalPlanBuilderForSyncMv() { + super(null); Review Comment: same as create view ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/plsql/PLSqlLogicalPlanBuilder.java: ########## @@ -36,6 +36,10 @@ */ public class PLSqlLogicalPlanBuilder extends LogicalPlanBuilder { + public PLSqlLogicalPlanBuilder() { + super(null); Review Comment: same as create view ########## fe/fe-core/src/main/java/org/apache/doris/nereids/parser/NereidsParser.java: ########## @@ -290,9 +292,37 @@ public Optional<String> parseForSyncMv(String sql) { return logicalPlanBuilderForSyncMv.getQuerySql(); } + /** get hint map */ + public static Map<Integer, ParserRuleContext> getHintMap(String sql, + Function<DorisParser, ParserRuleContext> parseFunction) { + // parse hint first round + DorisLexer hintLexer = new DorisLexer(new CaseInsensitiveStream(CharStreams.fromString(sql))); + hintLexer.setChannel2(true); + CommonTokenStream hintTokenStream = new CommonTokenStream(hintLexer); + + Map<Integer, ParserRuleContext> selectHintMap = Maps.newHashMap(); + + Token hintToken = hintTokenStream.getTokenSource().nextToken(); + while (hintToken != null && hintToken.getType() != DorisLexer.EOF) { + int tokenType = hintToken.getType(); + if (tokenType == DorisLexer.HINT_WITH_CHANNEL) { + String hintSql = sql.substring(hintToken.getStartIndex(), hintToken.getStopIndex() + 1); + DorisLexer newHintLexer = new DorisLexer(new CaseInsensitiveStream(CharStreams.fromString(hintSql))); + newHintLexer.setChannel2(false); + CommonTokenStream newHintTokenStream = new CommonTokenStream(newHintLexer); + DorisParser hintParser = new DorisParser(newHintTokenStream); + ParserRuleContext hintContext = parseFunction.apply(hintParser); Review Comment: we could write a new parser to process hint seperately? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org