You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jiajun Xie (Jira)" <ji...@apache.org> on 2023/03/31 12:47:00 UTC
[jira] [Commented] (CALCITE-5506) RelToSqlConverter should retain the aggregation logic
[ https://issues.apache.org/jira/browse/CALCITE-5506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17707249#comment-17707249 ]
Jiajun Xie commented on CALCITE-5506:
-------------------------------------
[~libenchao] , yes.
RelFieldTrimmer is correct.
I found the case after column trimming, and I think it is useful for other people reproduce the issue because
it is difficult for us to directly build such a logical plan by writing SQL.
> RelToSqlConverter should retain the aggregation logic
> -----------------------------------------------------
>
> Key: CALCITE-5506
> URL: https://issues.apache.org/jira/browse/CALCITE-5506
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Reporter: Jiajun Xie
> Assignee: Jiajun Xie
> Priority: Major
> Labels: pull-request-available
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Here is a sql
> {code:java}
> select l.v as l_cost
> from (
> select 0 as v,
> 1 as k
> ) l
> join (
> select sum("cost") as v,
> 1 as k
> from (
> select 1 as "cost"
> union
> select 2 as "cost"
> )
> ) r
> on l.k = r.k {code}
> Before trimming, the RelNode is
> {code:java}
> LogicalProject(L_COST=[$0])
> LogicalJoin(condition=[=($1, $3)], joinType=[inner])
> LogicalValues(tuples=[[{ 0, 1 }]])
> LogicalProject(V=[$0], K=[1])
> LogicalAggregate(group=[{}], V=[SUM($0)]) <!-- Here is SUM() -->
> LogicalUnion(all=[false])
> LogicalValues(tuples=[[{ 1 }]])
> LogicalValues(tuples=[[{ 2 }]]) {code}
> After trimming, the RelNode is
> {code:java}
> LogicalProject(L_COST=[$0])
> LogicalJoin(condition=[=($1, $2)], joinType=[inner])
> LogicalValues(tuples=[[{ 0, 1 }]])
> LogicalProject(K=[1])
> LogicalAggregate(group=[{}], DUMMY=[COUNT()]) <!-- Missing SUM() -->
> LogicalUnion(all=[false])
> LogicalValues(tuples=[[{ 1 }]])
> LogicalValues(tuples=[[{ 2 }]]){code}
> If we convert trimmed RelNode to sql, the sql will be
> {code:java}
> SELECT *
> FROM
> (VALUES (0, 1)) AS "t" ("V", "K")
> INNER JOIN
> (SELECT 1 AS "K" -- Missing SUM()
> FROM (SELECT *
> FROM (VALUES (1)) AS "t" ("cost")
> UNION
> SELECT *
> FROM (VALUES (2)) AS "t" ("cost")) AS "t2"
> ) AS "t4"
> ON "t"."K" = "t4"."K" {code}
> The origin sql only has one row result, but the new sql that be trimmed has two row result.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)