You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/01/07 02:40:45 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #1724: [CALCITE-3675] SQL to Rel conversion is broken for coalesce on nullable field

chunweilei commented on a change in pull request #1724: [CALCITE-3675] SQL to Rel conversion is broken for coalesce on nullable field
URL: https://github.com/apache/calcite/pull/1724#discussion_r363570799
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/sql/fun/SqlCaseOperator.java
 ##########
 @@ -293,16 +294,26 @@ private RelDataType inferTypeFromValidator(
     return ret;
   }
 
-  private RelDataType inferTypeFromOperands(
-      RelDataTypeFactory typeFactory,
-      List<RelDataType> argTypes) {
+  private RelDataType inferTypeFromOperands(SqlOperatorBinding opBinding) {
+    final RelDataTypeFactory typeFactory = opBinding.getTypeFactory();
+    final List<RelDataType> argTypes = opBinding.collectOperandTypes();
     assert (argTypes.size() % 2) == 1 : "odd number of arguments expected: "
         + argTypes.size();
     assert argTypes.size() > 1 : "CASE must have more than 1 argument. Given "
       + argTypes.size() + ", " + argTypes;
     List<RelDataType> thenTypes = new ArrayList<>();
     for (int j = 1; j < (argTypes.size() - 1); j += 2) {
-      thenTypes.add(argTypes.get(j));
+      RelDataType argType = argTypes.get(j);
+      if (opBinding instanceof RexCallBinding) {
+        RexNode whenNode = ((RexCallBinding) opBinding).getOperands().get(j - 1);
+        RexNode thenNode = ((RexCallBinding) opBinding).getOperands().get(j);
+        if (whenNode.getKind() == SqlKind.IS_NOT_NULL && argType.isNullable()) {
+          if (((RexCall) whenNode).getOperands().get(0).equals(thenNode)) {
 
 Review comment:
   It might be better if we put the if condition out of the loop.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services