[
https://issues.apache.org/jira/browse/CALCITE-7369?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
lincoln lee updated CALCITE-7369:
---------------------------------
Description:
When compile over window queries, the optimized result lost some column alias
Take the following case as an example(also the existing cases,e.g.,
testExpressionPreceding/
testWindowMissingConstantInDigest/testExpressionInWindowFunction):
{code}
@Test void testProjectToWindowRuleForNestedOver() {
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ProjectToWindowRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW);
final String sql = "select deptno, f1, f2 from (select *,
last_value(deptno) over (order by empno) f2\n"
+ "from (select *, first_value(deptno) over (order by empno) f1
from emp))\n";
sql(sql).withPlanner(hepPlanner)
.check();
}
{code}
the final output column alias 'F2' lost(became '$2'):
{code}
LogicalProject(DEPTNO=[$7], F1=[$9], $2=[$10])
LogicalWindow(window#0=[window(order by [0] aggs [LAST_VALUE($7)])])
LogicalWindow(window#0=[window(order by [0] aggs [FIRST_VALUE($7)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
was:
When compile a nested over window query, the optimized result lost some column
alias
Take the following case as an example:
{code}
@Test void testProjectToWindowRuleForNestedOver() {
HepProgramBuilder builder = new HepProgramBuilder();
builder.addRuleClass(ProjectToWindowRule.class);
HepPlanner hepPlanner = new HepPlanner(builder.build());
hepPlanner.addRule(CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW);
final String sql = "select deptno, f1, f2 from (select *,
last_value(deptno) over (order by empno) f2\n"
+ "from (select *, first_value(deptno) over (order by empno) f1
from emp))\n";
sql(sql).withPlanner(hepPlanner)
.check();
}
{code}
the final output column alias 'F2' lost(became '$2'):
{code}
LogicalProject(DEPTNO=[$7], F1=[$9], $2=[$10])
LogicalWindow(window#0=[window(order by [0] aggs [LAST_VALUE($7)])])
LogicalWindow(window#0=[window(order by [0] aggs [FIRST_VALUE($7)])])
LogicalTableScan(table=[[CATALOG, SALES, EMP]])
{code}
> ProjectToWindowRule loses column alias when optimizing OVER window queries
> --------------------------------------------------------------------------
>
> Key: CALCITE-7369
> URL: https://issues.apache.org/jira/browse/CALCITE-7369
> Project: Calcite
> Issue Type: Improvement
> Components: core
> Affects Versions: 1.41.0
> Reporter: lincoln lee
> Assignee: lincoln lee
> Priority: Major
>
> When compile over window queries, the optimized result lost some column alias
> Take the following case as an example(also the existing cases,e.g.,
> testExpressionPreceding/
> testWindowMissingConstantInDigest/testExpressionInWindowFunction):
> {code}
> @Test void testProjectToWindowRuleForNestedOver() {
> HepProgramBuilder builder = new HepProgramBuilder();
> builder.addRuleClass(ProjectToWindowRule.class);
> HepPlanner hepPlanner = new HepPlanner(builder.build());
> hepPlanner.addRule(CoreRules.PROJECT_TO_LOGICAL_PROJECT_AND_WINDOW);
> final String sql = "select deptno, f1, f2 from (select *,
> last_value(deptno) over (order by empno) f2\n"
> + "from (select *, first_value(deptno) over (order by empno) f1
> from emp))\n";
> sql(sql).withPlanner(hepPlanner)
> .check();
> }
> {code}
> the final output column alias 'F2' lost(became '$2'):
> {code}
> LogicalProject(DEPTNO=[$7], F1=[$9], $2=[$10])
> LogicalWindow(window#0=[window(order by [0] aggs [LAST_VALUE($7)])])
> LogicalWindow(window#0=[window(order by [0] aggs [FIRST_VALUE($7)])])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]])
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)