LiBinfeng-01 commented on code in PR #39113: URL: https://github.com/apache/doris/pull/39113#discussion_r1712613817
########## 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: I think it is no need to write a new parser but use exist parser logic as hint syntax, the only thing we need to care about is position and new hint type, position is solved by selectHintMap we added, new hint type is filtered by original hint parser. So it is no needed to add a new parser with same logic, we can only use channel 2 to deal with 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