Feng Zhu created CALCITE-3079:
---------------------------------
Summary: Successive dependent windows cannot be implemented in
same expression level
Key: CALCITE-3079
URL: https://issues.apache.org/jira/browse/CALCITE-3079
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.20.0
Reporter: Feng Zhu
Recently, we encountered an IndexOutOfBoundsException when running a
complicated query containing successive dependent windows.The issue can be
reproduced by the following simple query on table *t1(a, b, c)*.
{code:java}
Q1:
select sum(s) over (partition by aa) as ss " +
from (
select a as aa, sum(b) over (partition by a, c) as s
from t1
) t2";{code}
However, the modified query below can be executed in a right way.
{code:java}
Q2:
select sum(s) over (partition by aa) as ss " +
from (
select a as aa, sum(b) over (partition by a, c) + 0 as s
from t1
) t2{code}
This issue is caused by
*_ProjectToWindowRule_*({color:#FF0000}CalcRelSplitter{color}). When splitting
window expressions in Project node, the rule ignores to check whether a window
and its input window are in the same level.Due to such beheavior, two
successive window expressions are implemented in same level and the RelNode
after transformation is:
{code:java}
LogicalProject($0=[$4])
LogicalWindow(window#0=[window(partition {0, 2} order by [] range between
UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING aggs [SUM($1)])],
window#1=[window(partition {0} order by [] range between UNBOUNDED PRECEDING
and UNBOUNDED FOLLOWING aggs [SUM($3)])])
EnumerableTableScan(subset=[rel#7:Subset#0.ENUMERABLE.[]], table=[[ttt,
test]]){code}
As for *Q2*, two window expressions are not "successive", an _*Add(+)*_
operation results to implementing them in different levels. The RelNode after
transformation is:
{code:java}
LogicalProject($0=[$2])
LogicalWindow(window#0=[window(partition {0} order by [] range between
UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING aggs [SUM($1)])])
LogicalProject(a=[$0], $1=[+($3, 0)])
LogicalWindow(window#0=[window(partition {0, 2} order by [] range between
UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING aggs [SUM($1)])])
EnumerableTableScan(subset=[rel#7:Subset#0.ENUMERABLE.[]], table=[[ttt,
test]]){code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)