kasakrisz commented on code in PR #5681: URL: https://github.com/apache/hive/pull/5681#discussion_r1986773610
########## 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: I found that the rule `whenExpression` uses `KW_WHEN` but in that case the left side of the rule definition also has `KW_WHEN`. However the new `caseExpression` does not contain `KW_WHEN` explicitly. Based on my current knowledge it makes sense to use `Identifier["when"]`. -- 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