You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "mihaibudiu (via GitHub)" <gi...@apache.org> on 2026/08/13 23:37:22 UTC

[PR] [CALCITE-7717] Add a Collect.isValid method to check type invariants [calcite]

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

   ## Jira Link
   
   [CALCITE-7717](https://issues.apache.org/jira/browse/CALCITE-7717)
   


-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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

   ## [![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=5180) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5180&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=5180&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=5180&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [92.9% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=5180&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=5180&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5180)
   
   


-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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


##########
core/src/main/java/org/apache/calcite/rel/core/Collect.java:
##########
@@ -184,6 +187,32 @@ public RelNode copy(RelTraitSet traitSet, RelNode input) {
     return new Collect(getCluster(), traitSet, input, rowType());
   }
 
+  @Override public boolean isValid(Litmus litmus, @Nullable Context context) {
+    final RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
+    final RelDataType inputRow = getInput().getRowType();
+    if (getCollectionType() == SqlTypeName.MAP && inputRow.getFieldCount() != 2) {
+      return litmus.fail("MAP requires an input with exactly two fields;"
+          + " input row type is {}", inputRow);
+    }
+    final RelDataType derived =
+        deriveRowType(typeFactory, getCollectionType(), getFieldName(), inputRow);
+    if (rowType().equals(derived)) {
+      return super.isValid(litmus, context);
+    }
+    if (getCollectionType() != SqlTypeName.MAP && inputRow.getFieldCount() == 1) {
+      // ARRAY or MULTISET over an input row with a single column: the type of
+      // the column should match the type of the array element
+      final RelDataType derivedFromColumn =

Review Comment:
   Yes, thanks. This is what I had in mind.



-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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


-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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

   ## [![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=5180) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5180&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=5180&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=5180&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=5180&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=5180&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5180)
   
   


-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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


##########
core/src/main/java/org/apache/calcite/rel/core/Collect.java:
##########
@@ -184,6 +187,32 @@ public RelNode copy(RelTraitSet traitSet, RelNode input) {
     return new Collect(getCluster(), traitSet, input, rowType());
   }
 
+  @Override public boolean isValid(Litmus litmus, @Nullable Context context) {
+    final RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
+    final RelDataType inputRow = getInput().getRowType();
+    if (getCollectionType() == SqlTypeName.MAP && inputRow.getFieldCount() != 2) {
+      return litmus.fail("MAP requires an input with exactly two fields;"
+          + " input row type is {}", inputRow);
+    }
+    final RelDataType derived =
+        deriveRowType(typeFactory, getCollectionType(), getFieldName(), inputRow);
+    if (rowType().equals(derived)) {
+      return super.isValid(litmus, context);
+    }
+    if (getCollectionType() != SqlTypeName.MAP && inputRow.getFieldCount() == 1) {
+      // ARRAY or MULTISET over an input row with a single column: the type of
+      // the column should match the type of the array element
+      final RelDataType derivedFromColumn =

Review Comment:
   If you like this, you can approve it.



-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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

   ## [![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=5180) **Quality Gate passed**  
   Issues  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=5180&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=5180&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=5180&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=5180&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=5180&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5180)
   
   


-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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

   The new method is invoked automatically by the planner so it is already used by the existing tests that create Collect nodes.


-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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


##########
core/src/main/java/org/apache/calcite/rel/core/Collect.java:
##########
@@ -184,6 +187,32 @@ public RelNode copy(RelTraitSet traitSet, RelNode input) {
     return new Collect(getCluster(), traitSet, input, rowType());
   }
 
+  @Override public boolean isValid(Litmus litmus, @Nullable Context context) {
+    final RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
+    final RelDataType inputRow = getInput().getRowType();
+    if (getCollectionType() == SqlTypeName.MAP && inputRow.getFieldCount() != 2) {
+      return litmus.fail("MAP requires an input with exactly two fields;"
+          + " input row type is {}", inputRow);
+    }
+    final RelDataType derived =
+        deriveRowType(typeFactory, getCollectionType(), getFieldName(), inputRow);
+    if (rowType().equals(derived)) {
+      return super.isValid(litmus, context);
+    }
+    if (getCollectionType() != SqlTypeName.MAP && inputRow.getFieldCount() == 1) {
+      // ARRAY or MULTISET over an input row with a single column: the type of
+      // the column should match the type of the array element
+      final RelDataType derivedFromColumn =

Review Comment:
   I hope I understood your question
   I have pushed a second commit, please take a look



-- 
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-7717] Add a Collect.isValid method to check type invariants [calcite]

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


##########
core/src/main/java/org/apache/calcite/rel/core/Collect.java:
##########
@@ -184,6 +187,32 @@ public RelNode copy(RelTraitSet traitSet, RelNode input) {
     return new Collect(getCluster(), traitSet, input, rowType());
   }
 
+  @Override public boolean isValid(Litmus litmus, @Nullable Context context) {
+    final RelDataTypeFactory typeFactory = getCluster().getTypeFactory();
+    final RelDataType inputRow = getInput().getRowType();
+    if (getCollectionType() == SqlTypeName.MAP && inputRow.getFieldCount() != 2) {
+      return litmus.fail("MAP requires an input with exactly two fields;"
+          + " input row type is {}", inputRow);
+    }
+    final RelDataType derived =
+        deriveRowType(typeFactory, getCollectionType(), getFieldName(), inputRow);
+    if (rowType().equals(derived)) {
+      return super.isValid(litmus, context);
+    }
+    if (getCollectionType() != SqlTypeName.MAP && inputRow.getFieldCount() == 1) {
+      // ARRAY or MULTISET over an input row with a single column: the type of
+      // the column should match the type of the array element
+      final RelDataType derivedFromColumn =

Review Comment:
   Should we also compare against a type derived via SqlTypeUtil.deriveCollectionQueryComponentType here for the ARRAY/MULTISET query-constructor case, as Collect.create(..., SqlKind, ...) does?



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