kasakrisz commented on code in PR #5681: URL: https://github.com/apache/hive/pull/5681#discussion_r1986656702
########## parser/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g: ########## @@ -341,24 +341,47 @@ castExpression -> ^(TOK_FUNCTION {adaptor.create(Identifier, "cast_format")} NumberLiteral[Integer.toString(((CommonTree)toType.getTree()).token.getType())] expression StringLiteral NumberLiteral[((CommonTree)toType.getTree()).getChild(0).getText()]) ; -caseExpression +whenExpression @init { gParent.pushMsg("case expression", state); } @after { gParent.popMsg(state); } : - KW_CASE expression - (KW_WHEN expression KW_THEN expression)+ + KW_CASE + ( KW_WHEN expression KW_THEN expression)+ (KW_ELSE expression)? - KW_END -> ^(TOK_FUNCTION KW_CASE expression*) + KW_END -> ^(TOK_FUNCTION KW_WHEN expression*) ; -whenExpression +// Make caseExpression to build a whenExpression tree +// Rewrite +// CASE a +// WHEN b THEN c +// [WHEN d THEN e]* [ELSE f] +// END +// to +// CASE +// WHEN a=b THEN c +// [WHEN a=d THEN e]* [ELSE f] +// END +caseExpression @init { gParent.pushMsg("case expression", state); } @after { gParent.popMsg(state); } : - KW_CASE - ( KW_WHEN expression KW_THEN expression)+ - (KW_ELSE expression)? - KW_END -> ^(TOK_FUNCTION KW_WHEN expression*) + KW_CASE caseOperand=expression + // Pass the case operand to the rule parses the when branches + whenBranches[$caseOperand.tree] + (KW_ELSE elseResult=expression)? + KW_END -> ^(TOK_FUNCTION Identifier["when"] whenBranches $elseResult?) Review Comment: This is the way we reference a function with its name when constructing the AST. Some examples: https://github.com/apache/hive/blob/56a18bbba94f7cc099cb8dd1ab5e243a77fecd3f/parser/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g#L172C10-L172C43 https://github.com/apache/hive/blob/56a18bbba94f7cc099cb8dd1ab5e243a77fecd3f/parser/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g#L373 https://github.com/apache/hive/blob/56a18bbba94f7cc099cb8dd1ab5e243a77fecd3f/parser/src/java/org/apache/hadoop/hive/ql/parse/IdentifiersParser.g#L505 -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org