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/01/07 01:25:32 UTC

[PR] [CALCITE-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

   https://issues.apache.org/jira/browse/CALCITE-7358
   
   This PR essentially strengthens the type checking rules for casts involving arrays and maps.
   There were some additional inconsistencies; for example, a test allowed casting a `MAP<DECIMAL, INT>` to a `MAP<FLOAT, BINARY>`, but the coercion rules prohibited casts from `INT` to `BINARY`.
   
   
   


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

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


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

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


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

   My apologies, I misunderstood the comment in your JavaDoc. I thought it was a note to yourself to undo the changes before merging. I have no further questions.


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java:
##########
@@ -163,6 +164,20 @@ private static SqlSingleOperandTypeChecker getChecker(SqlCallBinding callBinding
       if (sqlTypeName == SqlTypeName.VARIANT) {
         // Allow any key type to be used when the map keys have a VARIANT type
         return OperandTypes.family(SqlTypeFamily.ANY);
+      } else if (sqlTypeName == SqlTypeName.ROW) {
+        // Check that the type of the argument is exactly the key type
+        return new SqlSingleOperandTypeChecker() {
+          @Override public boolean checkSingleOperandType(
+              SqlCallBinding callBinding, SqlNode operand,
+              int iFormalOperand, boolean throwOnFailure) {
+            RelDataType operandType = callBinding.getOperandType(0);
+            return operandType.equals(keyType);

Review Comment:
   Yes, this was wrong, and not throwing when throwOnFailure was also wrong.
   Thanks for catching 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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java:
##########
@@ -163,6 +164,20 @@ private static SqlSingleOperandTypeChecker getChecker(SqlCallBinding callBinding
       if (sqlTypeName == SqlTypeName.VARIANT) {
         // Allow any key type to be used when the map keys have a VARIANT type
         return OperandTypes.family(SqlTypeFamily.ANY);
+      } else if (sqlTypeName == SqlTypeName.ROW) {
+        // Check that the type of the argument is exactly the key type
+        return new SqlSingleOperandTypeChecker() {
+          @Override public boolean checkSingleOperandType(
+              SqlCallBinding callBinding, SqlNode operand,
+              int iFormalOperand, boolean throwOnFailure) {
+            RelDataType operandType = callBinding.getOperandType(0);
+            return operandType.equals(keyType);

Review Comment:
   ```
   // For mapp1[user_def(1, 'a')]
   final SqlNode left = callBinding.operand(0);     // mapp1
   final SqlNode right = callBinding.operand(1);  // user_def(1, 'a')
   ......
   final SqlSingleOperandTypeChecker checker = getChecker(callBinding);
   if (!checker.checkSingleOperandType(callBinding, right, 0, throwOnFailure)) {
     return false;
   }
   ......
   ```
   Based on the context, `operand` is the parameter, so it seems we should compare the type of `operand` with `keyType`.



-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

   What is wrong with the change in QuidemTest? I added the `data(.., ..)` function on purpose to make it easier to debug.


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

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


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

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


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

   I don't think that the CI errors are related to my changes.


-- 
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-7358] Casts involving MAP and ROW types cause compile-time exceptions [calcite]

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

   Clearly, I have sine trouble with mixing commit messages when I work on too many issues concurrently. I fixed this one.


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