[
https://issues.apache.org/jira/browse/CALCITE-7289?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18038303#comment-18038303
]
Stamatis Zampetakis commented on CALCITE-7289:
----------------------------------------------
For reproducing the problem it would be helpful to have the exact query plan
before hitting the issue. For example, having the plan close the top of the
stacktrace (e.g., RelBuilder.distinct(RelBuilder.java:2441)) would make things
much easier.
Anyways, by debugging the code and trying to match the stacktrace reported in
the ticket I was able to infer that the RelBuilder that was used when the
problem appeared has some non-default configurations. Those that are important
for the reproduction scenario are the following:
* withSimplifyValues -> false
* withSimplify -> false
All in all, the problem can be reproduced by adding the following test in
RelOptRulesTest:
{code:java}
@Test void testSJC() {
final String sql = "select 1 from emp where NULL in (SELECT NULL)\n";
RelBuilder.Config config =
RelBuilder.Config.DEFAULT.withSimplifyValues(false).withSimplify(false);
RelOptRule subQueryFilterRule =
SubQueryRemoveRule.Config.FILTER.withRelBuilderFactory(RelBuilder.proto(config)).toRule();
sql(sql).withRule(subQueryFilterRule).withLateDecorrelate(true).check();
}
{code}
> 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)