You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Jiajun Xie (Jira)" <ji...@apache.org> on 2023/01/28 09:30:00 UTC
[jira] [Created] (CALCITE-5506) RelToSqlConverter get error result because RelFieldTrimmer lost aggregate function
Jiajun Xie created CALCITE-5506:
-----------------------------------
Summary: RelToSqlConverter get error result because RelFieldTrimmer lost aggregate function
Key: CALCITE-5506
URL: https://issues.apache.org/jira/browse/CALCITE-5506
Project: Calcite
Issue Type: Improvement
Components: core
Reporter: Jiajun Xie
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)