Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coalesce on unnest row mismatch fix #15019

Merged
merged 5 commits into from
Oct 3, 2023
Merged

Conversation

somu-imply
Copy link
Contributor

@somu-imply somu-imply commented Sep 20, 2023

A query of form

select coalesce(c,s_int) as col from test_unnest_test_sql_array, unnest(json_value(a_nested, '$[1]' returning bigint array)) as u(c) 

due to a type mismatch while working on nested arrays with the trace

Caused by: java.lang.IllegalArgumentException: Type mismatch:
rel rowtype: RecordType(BIGINT NOT NULL ARRAY $f0, BIGINT NOT NULL $f00) NOT NULL
equiv rowtype: RecordType(BIGINT NOT NULL ARRAY $f11, BIGINT col) NOT NULL
Difference:
$f00: BIGINT NOT NULL -> BIGINT

        at org.apache.calcite.plan.volcano.VolcanoPlanner.register(VolcanoPlanner.java:592) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.plan.volcano.VolcanoPlanner.ensureRegistered(VolcanoPlanner.java:613) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.plan.volcano.VolcanoRuleCall.transformTo(VolcanoRuleCall.java:144) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:273) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:288) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.druid.sql.calcite.rule.DruidCorrelateUnnestRule.onMatch(DruidCorrelateUnnestRule.java:178) ~[druid-sql-28.0.0-SNAPSHOT.jar:28.0.0-SNAPSHOT]
        at org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:223) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.plan.volcano.IterativeRuleDriver.drive(IterativeRuleDriver.java:59) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:523) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.tools.Programs$RuleSetProgram.run(Programs.java:317) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.calcite.tools.Programs$SequenceProgram.run(Programs.java:337) ~[calcite-core-1.35.0.jar:1.35.0]
        at org.apache.druid.sql.calcite.planner.CalcitePlanner.transform(CalcitePlanner.java:452) ~[druid-sql-28.0.0-SNAPSHOT.jar:28.0.0-SNAPSHOT]
        at org.apache.druid.sql.calcite.planner.QueryHandler.planWithDruidConvention(QueryHandler.java:590) ~[druid-sql-28.0.0-SNAPSHOT.jar:28.0.0-SNAPSHOT]
        at org.apache.druid.sql.calcite.planner.QueryHandler$SelectHandler.planForDruid(QueryHandler.java:738) ~[druid-sql-28.0.0-SNAPSHOT.jar:28.0.0-SNAPSHOT]
        at org.apache.druid.sql.calcite.planner.QueryHandler.plan(QueryHandler.java:220) ~[druid-sql-28.0.0-SNAPSHOT.jar:28.0.0-SNAPSHOT]
        ... 83 more

After this change, the query executes correctly.
Screen Shot 2023-09-20 at 5 26 04 PM

This is a work in progress towards handling it. Although this fixes it, am looking into casts in the NestedDataExpressions if we can handle casts correctly there

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@somu-imply somu-imply marked this pull request as ready for review September 29, 2023 19:20
@soumyava soumyava removed the WIP label Sep 29, 2023
@soumyava soumyava merged commit 261f54d into apache:master Oct 3, 2023
@LakshSingla LakshSingla added this to the 28.0 milestone Oct 12, 2023
ektravel pushed a commit to ektravel/druid that referenced this pull request Oct 16, 2023
* coalesce on unnest row mismatch fix

* new example with coalesce over unnest with nested array columns

* New example with change in order which triggers the nvl

* new test plan update for useDefault=true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants