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


##########
core/src/main/java/org/apache/calcite/sql/SqlDialect.java:
##########
@@ -784,6 +784,11 @@ public boolean supportsWindowFunctions() {
     return true;
   }
 
+  /** Returns whether this dialect supports case when return boolean type. */
+  public boolean supportBooleanCaseWhen() {

Review Comment:
   can you add a test that combines the two, e.g., `CASE WHEN x > 1 THEN TRUE 
...`? 



##########
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:
   the comment looks wrong, is the last comparison supposed to be there?



-- 
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