You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "xiedeyantu (via GitHub)" <gi...@apache.org> on 2025/04/04 14:09:37 UTC

[PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

xiedeyantu opened a new pull request, #4288:
URL: https://github.com/apache/calcite/pull/4288

   Please see: [CALCITE-6938](Please see: https://issues.apache.org/jira/browse/CALCITE-6938)


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2037372554


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,27 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
+    switch (type.getSqlTypeName()) {
+    case ARRAY:
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;
+      break;
+    case MULTISET:
+      op = SqlStdOperatorTable.MULTISET_VALUE;
+      break;
+    case MAP:
+      op = SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR;
+      break;
+    case ROW:
+      op = SqlStdOperatorTable.ROW;

Review Comment:
   Done!



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2033718813


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,27 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
+    switch (type.getSqlTypeName()) {
+    case ARRAY:
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;
+      break;
+    case MULTISET:
+      op = SqlStdOperatorTable.MULTISET_VALUE;
+      break;
+    case MAP:
+      op = SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR;
+      break;
+    case ROW:
+      op = SqlStdOperatorTable.ROW;

Review Comment:
   I don't think this works for ROW. For ROW your original solution was correct: you need to create a zero for each field using a recursive call.



##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   I don't think this would pass validation.
   Which means that these tests are not really conclusive, since they can generate incorrect programs. Is there a way you could make sure that these programs are valid?



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032109262


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   When using CAST, may need to write something like ARRAY[]::INTEGER? I may not be clear about the correct way to write it, but I think it need to write all types.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032109262


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   When using CAST, you may need to write something like ARRAY[INTEGER]



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029480377


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   Got it, thanks a lot!



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2780352027

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [87.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288)
   
   


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032109262


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   When using CAST, may need to write something like ARRAY[INTEGER]



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029476811


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   Oh! I may have over-complicated it. I will modify the logic according to your suggestion. I have another question. If it is ARRAY<ARRAY<INTEGER>>>, the zero value should be ARRAY[ARRAY[]], right?



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032125406


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   Thanks! I will fix it soon.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2037381607


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   Should I keep the test case writing similar to makeZeroLiteral?



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2795331974

   > Please squash the commits so we can merge this.
   
   @mihaibudiu Thanks, I have rebased.


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034164569


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   Sorry, I didn't express myself clearly. I changed the zero value logic of ROW, and its corresponding validation will also be changed. I will keep the rest as it is.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034165504


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   the fact that there was no error shows that the validation is not strong enough. I don't think you should be able to create a ROW value with no fields when the type has fields.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032121424


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   You mean to keep the actual type and the writing consistent to avoid problems with `CAST(ARRAY[] AS type)` in SQL, right? I'll think about it and may need to adjust it again.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032122844


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   This should be a simple change. Just wrap the constructor call into a cast that produces `type`.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034157260


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   Is it that the test for ROW needs to be modified, but not the others? I saw that makeZoreLiteral also verifies how the zero value is constructed, and I referred to its logic.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2778904794

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288)
   
   


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2794576587

   Please squash the commits so we can merge this.


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2795365312

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288)
   
   


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034165734


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   if you find a way to validate the row, it will work for all other values.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2031796643


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   What is the type of the constructed array?
   I wonder whether this will create problems because the type needs to be inferred.
   But you know the type already, so you can synthesize a `CAST(ARRAY[] AS type)`.
   Same below.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2793206860

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288)
   
   


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034158504


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   it would be nice if there was a way to validate all of them.
   I didn't think exactly how.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029218662


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   so you think a zero array is an array containing a zero?
   or should it be an empty array?
   the question is "zero for what algebraic operation"?
   for concatenation the empty array is the zero.



##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   same question for multisets and maps



##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   I think an empty object makes more sense



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2032111209


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1918,31 +1918,24 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
   }
 
   public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
     switch (type.getSqlTypeName()) {
     case ARRAY:
-      ArraySqlType arrayType = (ArraySqlType) type;
-      RexNode zeroElement = makeZeroForNestedType(arrayType.getComponentType());
-      return makeCall(type, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
-          ImmutableList.of(zeroElement));
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;

Review Comment:
   I am not sure what this statements means. This is not legal SQL.
   And here I am talking about the internal representation.
   



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029478214


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   Yes, but I think it will just work, no need to worry about it.
   Just invoke the constructor for array with no arguments and cast it to the correct type.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034161869


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   I think zero was correct for ROW previously.
   For validation you can keep this, but can you make sure that there is additional validation? I haven't looked to see how builder results are validated.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034160053


##########
core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java:
##########
@@ -1104,6 +1107,140 @@ private static Stream<Arguments> testData4testMakeZeroLiteral() {
             relDataType -> new TimestampWithTimeZoneString(0, 1, 1, 0, 0, 0, "GMT+00:00")));
   }
 
+  /** Test case for
+   * <a href="https://issues.apache.org/jira/browse/CALCITE-6938">[CALCITE-6938]
+   * Support zero value creation of nested data types</a>. */
+  @ParameterizedTest
+  @MethodSource("testData4testMakeZeroForNestedType")
+  void testMakeZeroForNestedType(RelDataType type, RexNode expected) {
+    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+    assertThat(rexBuilder.makeZeroForNestedType(type), is(equalTo(expected)));
+  }
+
+  @Test void testCreateCoalesce() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    RelDataType arrayType = new ArraySqlType(varcharType, false);
+    RexNode arrayZero = b.makeZeroForNestedType(arrayType);
+
+    RexNode array =
+        b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+        ImmutableList.of(
+            b.makeLiteral("1", varcharType)));
+
+    RexNode coalesce1 = b.makeCall(SqlStdOperatorTable.COALESCE, array, arrayZero);
+    assertThat(
+        coalesce1, hasToString(
+        "COALESCE(ARRAY('1'), CAST(ARRAY()):VARCHAR NOT NULL ARRAY NOT NULL)"));
+
+    RelDataType mapType = new MapSqlType(arrayType, arrayType, true);
+    RexNode mapZero = b.makeZeroForNestedType(mapType);
+
+    RexNode map =
+        b.makeCall(new MapSqlType(arrayType, arrayType, true),
+        SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+        ImmutableList.of(array, array));
+
+    RexNode coalesce2 = b.makeCall(SqlStdOperatorTable.COALESCE, map, mapZero);
+    assertThat(
+        coalesce2, hasToString(
+        "COALESCE(MAP(ARRAY('1'), ARRAY('1')), "
+        + "CAST(MAP()):(VARCHAR NOT NULL ARRAY NOT NULL, VARCHAR NOT NULL ARRAY NOT NULL) MAP)"));
+  }
+
+  private static Stream<Arguments> testData4testMakeZeroForNestedType() {
+    RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+    RexBuilder b = new RexBuilder(typeFactory);
+
+    RelDataType integerType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType varcharType = typeFactory.createSqlType(SqlTypeName.VARCHAR);
+
+    // ARRAY<INTEGER>
+    RelDataType arrayType = new ArraySqlType(integerType, false);
+    RexNode expectedArray =
+        b.makeCast(
+            arrayType, b.makeCall(arrayType, SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // MULTISET<INTEGER>
+    RelDataType multisetType = new MultisetSqlType(integerType, false);
+    RexNode expectedMultiset =
+        b.makeCast(
+            multisetType, b.makeCall(multisetType, SqlStdOperatorTable.MULTISET_VALUE,
+            ImmutableList.of()));
+
+    // MAP<VARCHAR, INTEGER>
+    RelDataType mapType = new MapSqlType(varcharType, integerType, false);
+    RexNode expectedMap =
+        b.makeCast(
+            mapType, b.makeCall(mapType, SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR,
+            ImmutableList.of()));
+
+    // ROW<INTEGER, VARCHAR>
+    RelDataType rowType =

Review Comment:
   Should I keep this validation logic? Should I restore the zero value implementation logic of ROW to the previous version?



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034157075


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,27 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
+    switch (type.getSqlTypeName()) {
+    case ARRAY:
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;
+      break;
+    case MULTISET:
+      op = SqlStdOperatorTable.MULTISET_VALUE;
+      break;
+    case MAP:
+      op = SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR;
+      break;
+    case ROW:
+      op = SqlStdOperatorTable.ROW;

Review Comment:
   Yes, ROW needs real zeros, MAP, ARRAY, and MULTISET should be empty.
   The empty value is the zero value for monoid provided by the concatenation operation for these data structures.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029764815


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   Please take a look, I have addressed, thanks!



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029465263


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   Yes, I also think what you said is very reasonable. Maybe I should implement an XxxZero for each nested type and implement the Comparable interface. I am trying to modify it. Could you give some suggestions?



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2029470542


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,34 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    switch (type.getSqlTypeName()) {
+    case ARRAY:

Review Comment:
   Why do you need the Comparable interface?
   Just modify this function to return empty collections for ARRAY, MAP, MULTISET.



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #4288:
URL: https://github.com/apache/calcite/pull/4288#issuecomment-2785237146

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4288&issueStatuses=ACCEPTED)
   
   Measures  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4288&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [87.5% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_coverage&view=list)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4288&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4288)
   
   


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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on code in PR #4288:
URL: https://github.com/apache/calcite/pull/4288#discussion_r2034155889


##########
core/src/main/java/org/apache/calcite/rex/RexBuilder.java:
##########
@@ -1917,6 +1917,27 @@ public RexLiteral makeZeroLiteral(RelDataType type) {
     return makeLiteral(zeroValue(type), type);
   }
 
+  public RexNode makeZeroForNestedType(RelDataType type) {
+    SqlOperator op;
+    switch (type.getSqlTypeName()) {
+    case ARRAY:
+      op = SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR;
+      break;
+    case MULTISET:
+      op = SqlStdOperatorTable.MULTISET_VALUE;
+      break;
+    case MAP:
+      op = SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR;
+      break;
+    case ROW:
+      op = SqlStdOperatorTable.ROW;

Review Comment:
   I tried to sort out the logic according to your suggestion. ROW needs to be processed recursively and filled with real zero values. Should MAP have the same logic as ROW or ARRAY? If both use recursive logic, then ARRAY and MULITSET only need to do a CAST at the innermost level?



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


Re: [PR] [CALCITE-6938] Support zero value creation of nested data types [calcite]

Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu merged PR #4288:
URL: https://github.com/apache/calcite/pull/4288


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