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/27 06:49:55 UTC

[GitHub] [calcite] danny0405 commented on a change in pull request #2615: [CALCITE-4897] Fix incomplete implicit type cast

danny0405 commented on a change in pull request #2615:
URL: https://github.com/apache/calcite/pull/2615#discussion_r757749317



##########
File path: core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
##########
@@ -104,14 +104,17 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
       updateInferredColumnType(scope1, query, columnIndex, targetType);
       return true;
     case VALUES:
+      boolean coercedValues = true;
       for (SqlNode rowConstructor : ((SqlCall) query).getOperandList()) {
         if (!coerceOperandType(scope, (SqlCall) rowConstructor, columnIndex, targetType)) {
-          return false;
+          coercedValues = false;
         }
       }
-      updateInferredColumnType(
-          requireNonNull(scope, "scope"), query, columnIndex, targetType);
-      return true;
+      if (coercedValues) {
+        updateInferredColumnType(
+            requireNonNull(scope, "scope"), query, columnIndex, targetType);

Review comment:
       What's the difference here ? The original code does the same behavior: `#updateInferredColumnType` only if all the operands are coerced.

##########
File path: core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java
##########
@@ -894,6 +894,13 @@ public MockCatalogReader init() {
       t2.addColumn("t2_binary", binaryType);
       t2.addColumn("t2_boolean", booleanType);
       registerTable(t2);
+
+      final MockTable t3 =
+          MockTable.create(this, tSchema, "T3", false, 7.0, null);
+      t3.addColumn("t3_varchar20", varchar20Type);
+      t3.addColumn("t3_int", intType);

Review comment:
       Why add a new table here ? 't1' and 't2' have all the data types you needed.

##########
File path: core/src/main/java/org/apache/calcite/sql/validate/implicit/TypeCoercionImpl.java
##########
@@ -121,8 +124,8 @@ public TypeCoercionImpl(RelDataTypeFactory typeFactory, SqlValidator validator)
       // Set operations are binary for now.
       final SqlCall operand0 = ((SqlCall) query).operand(0);
       final SqlCall operand1 = ((SqlCall) query).operand(1);
-      final boolean coerced = rowTypeCoercion(scope, operand0, columnIndex, targetType)
-          && rowTypeCoercion(scope, operand1, columnIndex, targetType);
+      boolean coerced = rowTypeCoercion(scope, operand0, columnIndex, targetType);

Review comment:
       Change `&&` directly to `||` ?




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