[
https://issues.apache.org/jira/browse/CALCITE-5348?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Julian Hyde updated CALCITE-5348:
---------------------------------
Description:
The connection configuration string defaultNullCollation=LOW can't take effect
for order by in over clause. When translating ORDER BY in OVER, Calcite should
use the session's default null collation (e.g. NULLS LAST).
After debug, I found that the convertSortExpression in
SqlToRelConverter.convertOver was changed to bb::sortToRex and the
bb::sortToRex didn't read default configuration.
[https://github.com/apache/calcite/blob/c945b7f49b99538748c871557f6ac80957be2b6e/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L2247]
Also, The corresponding test case is incorrect at
org.apache.calcite.test.SqlToRelConverterTest#testUserDefinedOrderByOver .
sql :
{code:java}
select deptno,rank() over(partition by empno order by deptno)
from emp
order by row_number() over(partition by empno order by deptno) {code}
correct result
{code:java}
LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY
$7 NULLS FIRST)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7 NULLS
FIRST)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
but was
{code:java}
LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY
$7)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
was:
The connection configuration string defaultNullCollation=LOW can't take effect
for order by in over clause.
After debug, I found that the convertSortExpression in
SqlToRelConverter.convertOver was changed to bb::sortToRex and the
bb::sortToRex didn't read default configuration.
[https://github.com/apache/calcite/blob/c945b7f49b99538748c871557f6ac80957be2b6e/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L2247]
Also, The corresponding test case is incorrect at
org.apache.calcite.test.SqlToRelConverterTest#testUserDefinedOrderByOver .
sql :
{code:java}
select deptno,rank() over(partition by empno order by deptno)
from emp
order by row_number() over(partition by empno order by deptno) {code}
correct result
{code:java}
LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY
$7 NULLS FIRST)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7 NULLS
FIRST)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
but was
{code:java}
LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY
$7)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7)])
LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> When translating ORDER BY in OVER, use the session's default null collation
> (e.g. NULLS LAST)
> ---------------------------------------------------------------------------------------------
>
> Key: CALCITE-5348
> URL: https://issues.apache.org/jira/browse/CALCITE-5348
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.32.0
> Reporter: shampoo liu
> Priority: Major
> Fix For: 1.33.0
>
>
> The connection configuration string defaultNullCollation=LOW can't take
> effect for order by in over clause. When translating ORDER BY in OVER,
> Calcite should use the session's default null collation (e.g. NULLS LAST).
> After debug, I found that the convertSortExpression in
> SqlToRelConverter.convertOver was changed to bb::sortToRex and the
> bb::sortToRex didn't read default configuration.
> [https://github.com/apache/calcite/blob/c945b7f49b99538748c871557f6ac80957be2b6e/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java#L2247]
> Also, The corresponding test case is incorrect at
> org.apache.calcite.test.SqlToRelConverterTest#testUserDefinedOrderByOver .
> sql :
> {code:java}
> select deptno,rank() over(partition by empno order by deptno)
> from emp
> order by row_number() over(partition by empno order by deptno) {code}
> correct result
> {code:java}
> LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
> LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
> LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY
> $7 NULLS FIRST)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7
> NULLS FIRST)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
> but was
> {code:java}
> LogicalProject(DEPTNO=[$0], EXPR$1=[$1])
> LogicalSort(sort0=[$2], dir0=[ASC-nulls-first])
> LogicalProject(DEPTNO=[$7], EXPR$1=[RANK() OVER (PARTITION BY $0 ORDER BY
> $7)], EXPR$2=[ROW_NUMBER() OVER (PARTITION BY $0 ORDER BY $7)])
> LogicalTableScan(table=[[CATALOG, SALES, EMP]]) {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)