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

[PR] [CALCITE-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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

   …teral, Sarg) when pointCount >= 2
   
   RexSimplify.simplifySearch only evaluated a SEARCH(subject, Sarg) call against its Sarg when sarg.isPoints() && sarg.pointCount <= 1, with no check for whether the subject itself is a constant. A single-point Sarg with any subject folded correctly, and a multi-point Sarg with a column-reference subject simplified correctly elsewhere, but a literal subject compared against a multi-point Sarg (for example, SEARCH(5, Sarg[1, 2])) fell through every branch unevaluated instead of folding to a boolean constant.
   
   This can occur whenever a rule substitutes a literal for a column reference in a SEARCH condition, such as when
   FilterSetOpTransposeRule pushes a filter through a branch of a Union that projects a constant.
   
   ## Jira Link
   [CALCITE-7747](https://issues.apache.org/jira/browse/CALCITE-7747)
   
   ## Changes Proposed
   <!--
   Fix simplifySearch so that when the search subject is itself a RexLiteral, the call is expanded via the existing RexUtil.expandSearch and the result is simplified recursively, regardless of point count. This matches the treatment already given to a single-point Sarg, but adds the recursive simplify() call needed to fold the expanded comparison tree down to a constant.
   -->
   


-- 
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-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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


##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2547,10 +2547,12 @@ private RexNode simplifySearch(RexCall call, RexUnknownAs unknownAs) {
               call.clone(call.type, ImmutableList.of(searchOperand, literal2)),
               unknownAs);
         }
-      } else if (sarg.isPoints() && sarg.pointCount <= 1) {
-        // Expand "SEARCH(x, Sarg([point])" to "x = point"
-        // and "SEARCH(x, Sarg([])" to "false"
-        return RexUtil.expandSearch(rexBuilder, null, call);
+      } else if (searchOperand instanceof RexLiteral || (sarg.isPoints() && sarg.pointCount <= 1)) {

Review Comment:
   Yes, agreed.  That is better.



-- 
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-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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

   ## [![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=5226) **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=5226&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=5226&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=5226&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=5226&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=5226&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5226)
   
   


-- 
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-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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

   @mihaibudiu Is there anything else I need to do on 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


Re: [PR] [CALCITE-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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

   ## [![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=5226) **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=5226&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=5226&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=5226&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=5226&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=5226&metric=new_duplicated_lines_density&view=list)  
     
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=5226)
   
   


-- 
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-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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

   I think you can squash. But I will wait a bit to merge to see if there are other comments.


-- 
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-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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


-- 
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-7747] RexSimplify.simplifySearch does not simplify SEARCH(li… [calcite]

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


##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -2547,10 +2547,12 @@ private RexNode simplifySearch(RexCall call, RexUnknownAs unknownAs) {
               call.clone(call.type, ImmutableList.of(searchOperand, literal2)),
               unknownAs);
         }
-      } else if (sarg.isPoints() && sarg.pointCount <= 1) {
-        // Expand "SEARCH(x, Sarg([point])" to "x = point"
-        // and "SEARCH(x, Sarg([])" to "false"
-        return RexUtil.expandSearch(rexBuilder, null, call);
+      } else if (searchOperand instanceof RexLiteral || (sarg.isPoints() && sarg.pointCount <= 1)) {

Review Comment:
   wouldn't this be clearer as two separate ifs?



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