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

Bohdan Kazydub commented on CALCITE-3020:
-----------------------------------------

We observe a similar problem in Drill when updating to Calcite 1.19.0:
the following query
{code}
CREATE VIEW nation_view_testunionall_expandable_star AS select n_name, 
n_nationkey FROM cp.`tpch/nation.parquet`;
(SELECT n_comment, n_regionkey FROM cp.`tpch/nation.parquet` LIMIT 5) UNION ALL 
(SELECT * FROM nation_view_testunionall_expandable_star  LIMIT 5)
{code}
fails with
{code}
15:46:06.005 [2333c7f1-89f3-0b80-8369-68e24895729e:foreman] ERROR 
o.a.drill.exec.work.foreman.Foreman - SYSTEM ERROR: AssertionError: Type 
mismatch:
left:
RecordType(DYNAMIC_STAR **, ANY n_comment, ANY n_regionkey) NOT NULL
right:
RecordType(DYNAMIC_STAR **, ANY n_comment, ANY n_regionkey, ANY n_name, ANY 
n_nationkey) NOT NULL
{code}
when Volcano planner is registering rel nodes. The initial plan is the 
following:
{code}
LogicalUnion(all=[true]): rowcount = 10.0, cumulative cost = {520.0 rows, 
940.755032994728 cpu, 0.0 io, 0.0 network, 0.0 memory}, id = 74
  LogicalSort(fetch=[5]): rowcount = 5.0, cumulative cost = {205.0 rows, 
365.377516497364 cpu, 0.0 io, 0.0 network, 0.0 memory}, id = 68
    LogicalProject(n_comment=[$1], n_regionkey=[$2]): rowcount = 100.0, 
cumulative cost = {200.0 rows, 301.0 cpu, 0.0 io, 0.0 network, 0.0 memory}, id 
= 67
      EnumerableTableScan(table=[[cp, tpch/nation.parquet]]): rowcount = 100.0, 
cumulative cost = {100.0 rows, 101.0 cpu, 0.0 io, 0.0 network, 0.0 memory}, id 
= 29
  LogicalSort(fetch=[5]): rowcount = 5.0, cumulative cost = {305.0 rows, 
565.377516497364 cpu, 0.0 io, 0.0 network, 0.0 memory}, id = 73
    LogicalProject(n_name=[$0], n_nationkey=[$1]): rowcount = 100.0, cumulative 
cost = {300.0 rows, 501.0 cpu, 0.0 io, 0.0 network, 0.0 memory}, id = 72
      LogicalProject(n_name=[$3], n_nationkey=[$4]): rowcount = 100.0, 
cumulative cost = {200.0 rows, 301.0 cpu, 0.0 io, 0.0 network, 0.0 memory}, id 
= 71
        EnumerableTableScan(table=[[cp, tpch/nation.parquet]]): rowcount = 
100.0, cumulative cost = {100.0 rows, 101.0 cpu, 0.0 io, 0.0 network, 0.0 
memory}, id = 34
{code}

It contains two EnumerableTableScan operators with different row types 
specified in the error message above. In the scope of CALCITE-2454 was removed 
rel data type from the key in the {{VolcanoPlanner.mapDigestToRel}} map.

I think, {{RelNode}}s with no input (like scan) should include {{rowType}} item 
in {{AbstractRelNode#explainTerms(RelWriter)}} method because in case of 
dynamic tables there is the same digest for different operators. The same thing 
was done for Values operator and literals in conditions.

> throws AssertionError:Type mismatch in VolcanoPlanner
> -----------------------------------------------------
>
>                 Key: CALCITE-3020
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3020
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.19.0
>            Reporter: godfrey he
>            Priority: Major
>
> after [CALCITE-2454|https://issues.apache.org/jira/browse/CALCITE-2454] 
> merged, an AssertionError:Type mismatch will be thrown in VolcanoPlanner when 
> running the following sql:
> {code:sql}
> WITH t1 AS (SELECT CAST(a as BIGINT) AS a, SUM(b) AS b FROM x GROUP BY CAST(a 
> as BIGINT)),
>      t2 AS (SELECT CAST(a as DOUBLE) AS a, SUM(b) AS b FROM x GROUP BY CAST(a 
> as DOUBLE))
> SELECT t1.*, t2.* FROM t1, t2 WHERE t1.b = t2.b
> {code}
> Caused by: java.lang.AssertionError: Type mismatch:
> left:
> RecordType(BIGINT a, BIGINT b) NOT NULL
> right:
> RecordType(DOUBLE a, BIGINT b) NOT NULL
>       at org.apache.calcite.util.Litmus$1.fail(Litmus.java:31)
>       at org.apache.calcite.plan.RelOptUtil.equal(RelOptUtil.java:1858)
>       at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.registerImpl(VolcanoPlanner.java:1705)
>       at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.register(VolcanoPlanner.java:850)
>       at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.ensureRegistered(VolcanoPlanner.java:872)
>       at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.ensureRegistered(VolcanoPlanner.java:1958)
>       at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.transformTo(VolcanoRuleCall.java:126)
>       at 
> org.apache.calcite.plan.RelOptRuleCall.transformTo(RelOptRuleCall.java:234)
>       at 
> org.apache.calcite.rel.convert.ConverterRule.onMatch(ConverterRule.java:141)
>       at 
> org.apache.calcite.plan.volcano.VolcanoRuleCall.onMatch(VolcanoRuleCall.java:205)
>       at 
> org.apache.calcite.plan.volcano.VolcanoPlanner.findBestExp(VolcanoPlanner.java:637)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to