[ 
https://issues.apache.org/jira/browse/CALCITE-7289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18038402#comment-18038402
 ] 

Steve Carlin commented on CALCITE-7289:
---------------------------------------

Ok, actually, I want to backtrack a little.

The reason I had to turn off the Simplifier is because of CALCITE-4467

NaN is a weird thing.  I'm currently in the process of upgrading our current 
custom compiler into a Calcite compiler.  I'd like to match the results that 
our current compiler produces, and NaN is causing issues with the way that the 
simplifier handles it.  

My current way of handling this is to have a custom simplifier that avoids 
double comparisons. 

But regardless:  I don't want to use the simplifier, and theoretically things 
should work without simplification?  I'm not sure if this can be fixed, but it 
would really help me out.  Otherwise, I'll have to either probably either a) 
change the current simplifier to make my stuff work (already rejected in the 
above Jira), b) create a feature where I can use my own simplifier (a bit 
complicated, but prolly doable, but seems weird), or c) Create my own 
RelBuilder to run my own Simplifier (a lot of copied code out of Calcite).  Or 
perhaps there's another option I can't think of.

Thanks, and let me know what you decide.  If you don't want to fix it, I may 
take a crack at it, or at least try to understand what simplify is doing to 
make this work.  Or maybe it is impossible, idk.

> Select NULL subquery throwing exception
> ---------------------------------------
>
>                 Key: CALCITE-7289
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7289
>             Project: Calcite
>          Issue Type: Bug
>    Affects Versions: 1.41.0
>            Reporter: Steve Carlin
>            Assignee: Mihai Budiu
>            Priority: Major
>
> Ok, gonna ask for community help here while I continue to debug this, but 
> lemme give the legwork I've done so far.  [~mbudiu] , tagging you because git 
> blame shows a commit you made as being part of this stack trace.
> The following query is failing in my environment:
> {code:java}
> SELECT 1 from mytbl WHERE NULL IN (SELECT null){code}
> The relevant part of my stack trace is here:
>  
> {code:java}
> I20251112 17:02:52.111802 2311327 LogUtil.java:47] 
> 4a4ec6519f2d1bff:86f4b29300000000] [Plan after conversion from Abstract 
> Syntax Tree]
> LogicalProject(EXPR$0=[1:TINYINT]), id = 6
>   LogicalFilter(condition=[IN(null:NULL, {
> LogicalValues(tuples=[[{ null }]])
> })]), id = 4
>     LogicalTableScan(table=[[functional, alltypestiny]]), id = 1
> I20251112 17:02:52.189169 2311327 jni-util.cc:321] 
> 4a4ec6519f2d1bff:86f4b29300000000] java.lang.AssertionError: Comparison with 
> NULL in pulledUpPredicates
>         at org.apache.calcite.util.Litmus.lambda$static$0(Litmus.java:31)
>         at org.apache.calcite.util.Litmus.check(Litmus.java:76)
>         at 
> org.apache.calcite.plan.RelOptPredicateList.<init>(RelOptPredicateList.java:128)
>         at 
> org.apache.calcite.plan.RelOptPredicateList.of(RelOptPredicateList.java:206)
>         at 
> org.apache.calcite.plan.RelOptPredicateList.of(RelOptPredicateList.java:159)
>         at 
> org.apache.calcite.rel.metadata.RelMdPredicates.getPredicates(RelMdPredicates.java:325)
>         at 
> org.apache.calcite.rel.metadata.janino.GeneratedMetadata_PredicatesHandler.getPredicates_$(Unknown
>  Source)
>         at 
> org.apache.calcite.rel.metadata.janino.GeneratedMetadata_PredicatesHandler.getPredicates(Unknown
>  Source)
>         at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.getPulledUpPredicates(RelMetadataQuery.java:914)
>         at 
> org.apache.calcite.rel.metadata.RelMdPredicates.getPredicates(RelMdPredicates.java:193)
>         at 
> org.apache.calcite.rel.metadata.janino.GeneratedMetadata_PredicatesHandler.getPredicates_$(Unknown
>  Source)
>         at 
> org.apache.calcite.rel.metadata.janino.GeneratedMetadata_PredicatesHandler.getPredicates(Unknown
>  Source)
>         at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.getPulledUpPredicates(RelMetadataQuery.java:914)
>         at 
> org.apache.calcite.rel.metadata.RelMdColumnUniqueness.decorateWithConstantColumnsFromPredicates(RelMdColumnUniqueness.java:516)
>         at 
> org.apache.calcite.rel.metadata.RelMdColumnUniqueness.areColumnsUnique(RelMdColumnUniqueness.java:232)
>         at 
> org.apache.calcite.rel.metadata.janino.GeneratedMetadata_ColumnUniquenessHandler.areColumnsUnique_$(Unknown
>  Source)
>         at 
> org.apache.calcite.rel.metadata.janino.GeneratedMetadata_ColumnUniquenessHandler.areColumnsUnique(Unknown
>  Source)
>         at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.areColumnsUnique(RelMetadataQuery.java:615)
>         at 
> org.apache.calcite.rel.metadata.RelMetadataQuery.areColumnsUnique(RelMetadataQuery.java:595)
>         at 
> org.apache.calcite.tools.RelBuilder.alreadyUnique(RelBuilder.java:2710)
>         at 
> org.apache.calcite.tools.RelBuilder.aggregate_(RelBuilder.java:2495)
>         at org.apache.calcite.tools.RelBuilder.distinct(RelBuilder.java:2441)
>         at 
> org.apache.calcite.rel.rules.SubQueryRemoveRule.rewriteIn(SubQueryRemoveRule.java:684)
> {code}
>  
> In terms of due diligence I've done so far: I am not very familiar with the 
> Calcite build environment and have only used gradlew to build a couple of 
> times, so I'm just feeling my way around here.  But in the meantime, I did 
> some unorthodox ways of trying to reproduce and failed.
> I added this to RelOptRulesTest:
>  
> {code:java}
> +  /** Test case for testing type created by SubQueryRemoveRule: an
> +   * ANY sub-query is non-nullable therefore plan should have cast. */
> +  @Test void testSJC() {
> +    final String sql = "select 1 from emp where NULL in (SELECT NULL)\n";
> +    sql(sql).withSubQueryRules().withLateDecorrelate(true).check();
> +  }
> +
> {code}
>  
> But this does not reproduce the problem.  From my really hacky weird 
> debugging, the best I can tell is that maybe it uses a different RelBuilder 
> when running so it doesn't come anywhere near the code I'm trying to get to 
> crash?  So I'm not sure how to reproduce it yet.  Still working on it.
> Thanks!



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to