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 2021/11/04 02:43:52 UTC

[GitHub] [calcite] chunweilei commented on a change in pull request #2598: [CALCITE-4875] Preserve Operand Nullability in NVL rewrite

chunweilei commented on a change in pull request #2598:
URL: https://github.com/apache/calcite/pull/2598#discussion_r742496382



##########
File path: core/src/main/java/org/apache/calcite/sql2rel/StandardConvertletTable.java
##########
@@ -308,12 +308,20 @@ private static RexNode convertNvl(SqlRexContext cx, SqlCall call) {
         cx.convertExpression(call.getOperandList().get(1));
     final RelDataType type =
         cx.getValidator().getValidatedNodeType(call);
+    // Preserve Operand Nullability
     return rexBuilder.makeCall(type, SqlStdOperatorTable.CASE,
         ImmutableList.of(
             rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL,
                 operand0),
-            rexBuilder.makeCast(type, operand0),
-            rexBuilder.makeCast(type, operand1)));
+            rexBuilder.makeCast(
+                cx.getTypeFactory()
+                    .createTypeWithNullability(type, operand0.getType().isNullable()),
+                operand0),
+            rexBuilder.makeCast(
+                cx.getTypeFactory()
+                    .createTypeWithNullability(type, operand1.getType().isNullable()),
+                operand1)
+        ));
   }

Review comment:
       Could you add a test case, @jaystarshot ?




-- 
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: commits-unsubscribe@calcite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org