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/02/26 07:03:00 UTC

[jira] [Commented] (CALCITE-5506) RelToSqlConverter should retain the aggregation logic even if the aggregation function is trimmed

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

Jiajun Xie commented on CALCITE-5506:
-------------------------------------

[~libenchao], I changed the title. 
Does it precise?

> RelToSqlConverter should retain the aggregation logic even if the aggregation function is trimmed
> -------------------------------------------------------------------------------------------------
>
>                 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)