fx19880617 commented on a change in pull request #5461:
URL: https://github.com/apache/incubator-pinot/pull/5461#discussion_r435745019
##########
File path:
pinot-common/src/main/java/org/apache/pinot/sql/parsers/CalciteSqlParser.java
##########
@@ -610,6 +611,40 @@ private static Expression toExpression(SqlNode node) {
}
asFuncExpr.getFunctionCall().addToOperands(RequestUtils.getIdentifierExpression(aliasName));
return asFuncExpr;
+ case CASE:
+ // CASE WHEN Statement is model as a function with variable length
parameters.
+ // Assume N is number of WHEN Statements, total number of parameters
is (2 * N + 1).
+ // - N: Convert each WHEN Statement into a function Expression;
+ // - N: Convert each THEN Statement into an Expression;
+ // - 1: Convert ELSE Statement into an Expression.
+ SqlCase caseSqlNode = (SqlCase) node;
+ SqlNodeList whenOperands = caseSqlNode.getWhenOperands();
+ SqlNodeList thenOperands = caseSqlNode.getThenOperands();
+ SqlNode elseOperand = caseSqlNode.getElseOperand();
+ Expression caseFuncExpr =
RequestUtils.getFunctionExpression(SqlKind.CASE.name());
+ for (SqlNode whenSqlNode : whenOperands.getList()) {
+ Expression whenExpression = toExpression(whenSqlNode);
+ if (isAggregateExpression(whenExpression)) {
+ throw new SqlCompilationException(
+ "Aggregation functions inside WHEN Clause is not supported - "
+ whenSqlNode);
+ }
+ caseFuncExpr.getFunctionCall().addToOperands(whenExpression);
+ }
+ for (SqlNode thenSqlNode : thenOperands.getList()) {
Review comment:
1. For THEN part, we support both transform function and literal,
technically it could be another CASE statement inside.
2. Since it's modeled as a transform function, then it could be used any
where allowing this. e.g. predicate, group bys.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]