Skip to content

Commit e113ec1

Browse files
authored
fix (#14042)
Co-authored-by: Cyprien Huet <chuet@palantir.com>
1 parent 40f1ddd commit e113ec1

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

datafusion/functions-window/src/nth_value.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ impl PartitionEvaluator for NthValueEvaluator {
360360
})
361361
.unwrap_or_default();
362362
if valid_indices.is_empty() {
363-
return ScalarValue::try_from(arr.data_type());
363+
None
364+
} else {
365+
Some(valid_indices)
364366
}
365-
Some(valid_indices)
366367
} else {
367368
None
368369
};

datafusion/sqllogictest/test_files/window.slt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ logical_plan
17671767
01)Projection: count(*) AS global_count
17681768
02)--Aggregate: groupBy=[[]], aggr=[[count(Int64(1)) AS count(*)]]
17691769
03)----SubqueryAlias: a
1770-
04)------Projection:
1770+
04)------Projection:
17711771
05)--------Aggregate: groupBy=[[aggregate_test_100.c1]], aggr=[[]]
17721772
06)----------Projection: aggregate_test_100.c1
17731773
07)------------Filter: aggregate_test_100.c13 != Utf8("C2GT5KVyOPZpgKVl110TyZO0NcJ434")
@@ -4625,6 +4625,38 @@ NULL 1
46254625
statement ok
46264626
DROP TABLE t;
46274627

4628+
4629+
# Test for ignore nulls in nth_VALUE without null values
4630+
statement ok
4631+
CREATE TABLE t AS VALUES (3, 3), (4, 4), (5, 5), (6, 6);
4632+
4633+
query I
4634+
SELECT column1 FROM t ORDER BY column2;
4635+
----
4636+
3
4637+
4
4638+
5
4639+
6
4640+
4641+
query I
4642+
SELECT nth_VALUE(column1, 1) OVER(ORDER BY column2) FROM t;
4643+
----
4644+
3
4645+
3
4646+
3
4647+
3
4648+
4649+
query I
4650+
SELECT nth_VALUE(column1, 1) IGNORE NULLS OVER(ORDER BY column2) FROM t;
4651+
----
4652+
3
4653+
3
4654+
3
4655+
3
4656+
4657+
statement ok
4658+
DROP TABLE t;
4659+
46284660
# Test for ignore nulls with ORDER BY in nth_VALUE
46294661
statement ok
46304662
CREATE TABLE t AS VALUES (3, 3), (4, 4), (null::bigint, 1), (null::bigint, 2), (5, 5), (6, 6);
@@ -5055,7 +5087,7 @@ select b, row_number() over (order by a) from (select TRUE as a, 1 as b);
50555087

50565088
# test window functions on boolean columns
50575089
statement count 0
5058-
create table t1 (id int, bool_col boolean) as values
5090+
create table t1 (id int, bool_col boolean) as values
50595091
(1, true),
50605092
(2, false),
50615093
(3, true),
@@ -5110,7 +5142,7 @@ select ntile(2) over (order by bool_col) from t1;
51105142
2
51115143

51125144
query IIIRRI
5113-
select
5145+
select
51145146
row_number() over (order by bool_col) as row_num,
51155147
rank() over (order by bool_col) as rank,
51165148
dense_rank() over (order by bool_col) as dense_rank,

0 commit comments

Comments
 (0)