mihaibudiu commented on code in PR #3897:
URL: https://github.com/apache/calcite/pull/3897#discussion_r1702191693


##########
core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java:
##########
@@ -726,6 +726,31 @@ public SqlNode toSql(@Nullable RexProgram program, RexNode 
rex) {
           }
         }
         elseNode = caseNodeList.get(caseNodeList.size() - 1);
+
+        if (caseCall.getType().getSqlTypeName() == SqlTypeName.BOOLEAN
+            && !dialect.supportBooleanCaseWhen()) {
+          // Transformed when expressions of boolean type in SqlCase
+          // For example, given
+          //     CASE WHEN x > 1 THEN y > 1 ELSE y < 10 END
+          // Transformed:
+          //     CASE WHEN x > 1 THEN CASE WHEN y > 1 THEN 1 ELSE 0 END
+          // ELSE CASE WHEN y < 10 THEN 1 ELSE 0 END END = 1

Review Comment:
   Can you use some parentheses to make the order of evaluation clearer?
   It's not obvious how the expression is parsed. 
   I guess it's parsed as (CASE ... END) = 1
   Now I am worried about a CASE expression that mixes boolean and non-boolean 
values.
   How about something like `(CASE WHEN ... x > 1 ELSE 2 END)`?
   Is the translation of this also preserving its semantics?
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to