Skip to content

Commit 729b356

Browse files
chore: fix last_value coercion (#10783)
* chore: fix regression in `last_value` coercion * Add regression test for first_value / last_value for timestamps * Update for fixed issue * cleanup --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 5a544d0 commit 729b356

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use datafusion_common::{
2929
arrow_datafusion_err, internal_err, DataFusionError, Result, ScalarValue,
3030
};
3131
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
32-
use datafusion_expr::type_coercion::aggregates::NUMERICS;
3332
use datafusion_expr::utils::{format_state_name, AggregateOrderSensitivity};
3433
use datafusion_expr::{
3534
Accumulator, AggregateUDFImpl, ArrayFunctionSignature, Signature, TypeSignature,
@@ -374,7 +373,8 @@ impl LastValue {
374373
vec![
375374
// TODO: we can introduce more strict signature that only numeric of array types are allowed
376375
TypeSignature::ArraySignature(ArrayFunctionSignature::Array),
377-
TypeSignature::Uniform(1, NUMERICS.to_vec()),
376+
TypeSignature::Numeric(1),
377+
TypeSignature::Uniform(1, vec![DataType::Utf8]),
378378
],
379379
Volatility::Immutable,
380380
),

datafusion/sqllogictest/test_files/window.slt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,12 +925,43 @@ SELECT
925925
2022-09-29T15:16:34 2 1 1
926926
2022-09-30T19:03:14 1 1 1
927927

928+
928929
statement ok
929930
drop table t
930931

931932
statement ok
932933
drop table temp
933934

935+
statement ok
936+
CREATE TABLE table1 (
937+
bar DECIMAL(10,1),
938+
foo VARCHAR(10),
939+
time TIMESTAMP WITH TIME ZONE
940+
);
941+
942+
statement ok
943+
INSERT INTO table1 (bar, foo, time) VALUES
944+
(200.0, 'me', '1970-01-01T00:00:00.000000010Z'),
945+
(1.0, 'me', '1970-01-01T00:00:00.000000030Z'),
946+
(1.0, 'me', '1970-01-01T00:00:00.000000040Z'),
947+
(2.0, 'you', '1970-01-01T00:00:00.000000020Z');
948+
949+
query TP
950+
SELECT foo, first_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1 GROUP BY foo ORDER BY foo;
951+
----
952+
me 1970-01-01T00:00:00.000000040Z
953+
you 1970-01-01T00:00:00.000000020Z
954+
955+
query TP
956+
SELECT foo, last_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1 GROUP BY foo ORDER BY foo;
957+
----
958+
me 1970-01-01T00:00:00.000000010Z
959+
you 1970-01-01T00:00:00.000000020Z
960+
961+
statement ok
962+
drop table table1;
963+
964+
934965

935966
#fn window_frame_ranges_unbounded_preceding_err
936967
statement error DataFusion error: Error during planning: Invalid window frame: end bound cannot be UNBOUNDED PRECEDING

0 commit comments

Comments
 (0)