Skip to content

Commit b287cda

Browse files
compheadmustafasrepoalamb
authored
minor: fix to support scalars (#8559)
* minor: fix to support scalars * Update datafusion/sql/src/expr/function.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> --------- Co-authored-by: Mustafa Akur <106137913+mustafasrepo@users.noreply.github.com> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent fc6cc48 commit b287cda

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

datafusion/sql/src/expr/function.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
9090
let partition_by = window
9191
.partition_by
9292
.into_iter()
93+
// ignore window spec PARTITION BY for scalar values
94+
// as they do not change and thus do not generate new partitions
95+
.filter(|e| !matches!(e, sqlparser::ast::Expr::Value { .. },))
9396
.map(|e| self.sql_expr_to_logical_expr(e, schema, planner_context))
9497
.collect::<Result<Vec<_>>>()?;
9598
let mut order_by = self.order_by_to_sort_expr(

datafusion/sqllogictest/test_files/window.slt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,8 +3794,36 @@ select a,
37943794
1 1
37953795
2 1
37963796

3797+
# support scalar value in ORDER BY
37973798
query I
37983799
select rank() over (order by 1) rnk from (select 1 a union all select 2 a) x
37993800
----
38003801
1
38013802
1
3803+
3804+
# support scalar value in both ORDER BY and PARTITION BY, RANK function
3805+
# TODO: fix the test, some issue in RANK
3806+
#query IIIIII
3807+
#select rank() over (partition by 1 order by 1) rnk,
3808+
# rank() over (partition by a, 1 order by 1) rnk1,
3809+
# rank() over (partition by a, 1 order by a, 1) rnk2,
3810+
# rank() over (partition by 1) rnk3,
3811+
# rank() over (partition by null) rnk4,
3812+
# rank() over (partition by 1, null, a) rnk5
3813+
#from (select 1 a union all select 2 a) x
3814+
#----
3815+
#1 1 1 1 1 1
3816+
#1 1 1 1 1 1
3817+
3818+
# support scalar value in both ORDER BY and PARTITION BY, ROW_NUMBER function
3819+
query IIIIII
3820+
select row_number() over (partition by 1 order by 1) rn,
3821+
row_number() over (partition by a, 1 order by 1) rn1,
3822+
row_number() over (partition by a, 1 order by a, 1) rn2,
3823+
row_number() over (partition by 1) rn3,
3824+
row_number() over (partition by null) rn4,
3825+
row_number() over (partition by 1, null, a) rn5
3826+
from (select 1 a union all select 2 a) x;
3827+
----
3828+
1 1 1 1 1 1
3829+
2 1 1 2 2 1

0 commit comments

Comments
 (0)