This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 729b356ef5 chore: fix `last_value` coercion (#10783)
729b356ef5 is described below
commit 729b356ef543ffcda6813c7b5373507a04ae0109
Author: Chunchun Ye <[email protected]>
AuthorDate: Tue Jun 4 05:38:26 2024 -0500
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]>
---
datafusion/functions-aggregate/src/first_last.rs | 4 +--
datafusion/sqllogictest/test_files/window.slt | 31 ++++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/datafusion/functions-aggregate/src/first_last.rs
b/datafusion/functions-aggregate/src/first_last.rs
index fe4501c149..435d277473 100644
--- a/datafusion/functions-aggregate/src/first_last.rs
+++ b/datafusion/functions-aggregate/src/first_last.rs
@@ -29,7 +29,6 @@ use datafusion_common::{
arrow_datafusion_err, internal_err, DataFusionError, Result, ScalarValue,
};
use datafusion_expr::function::{AccumulatorArgs, StateFieldsArgs};
-use datafusion_expr::type_coercion::aggregates::NUMERICS;
use datafusion_expr::utils::{format_state_name, AggregateOrderSensitivity};
use datafusion_expr::{
Accumulator, AggregateUDFImpl, ArrayFunctionSignature, Signature,
TypeSignature,
@@ -374,7 +373,8 @@ impl LastValue {
vec![
// TODO: we can introduce more strict signature that only
numeric of array types are allowed
TypeSignature::ArraySignature(ArrayFunctionSignature::Array),
- TypeSignature::Uniform(1, NUMERICS.to_vec()),
+ TypeSignature::Numeric(1),
+ TypeSignature::Uniform(1, vec![DataType::Utf8]),
],
Volatility::Immutable,
),
diff --git a/datafusion/sqllogictest/test_files/window.slt
b/datafusion/sqllogictest/test_files/window.slt
index 2d5dd439d7..13729d6e49 100644
--- a/datafusion/sqllogictest/test_files/window.slt
+++ b/datafusion/sqllogictest/test_files/window.slt
@@ -925,12 +925,43 @@ SELECT
2022-09-29T15:16:34 2 1 1
2022-09-30T19:03:14 1 1 1
+
statement ok
drop table t
statement ok
drop table temp
+statement ok
+CREATE TABLE table1 (
+ bar DECIMAL(10,1),
+ foo VARCHAR(10),
+ time TIMESTAMP WITH TIME ZONE
+);
+
+statement ok
+INSERT INTO table1 (bar, foo, time) VALUES
+(200.0, 'me', '1970-01-01T00:00:00.000000010Z'),
+(1.0, 'me', '1970-01-01T00:00:00.000000030Z'),
+(1.0, 'me', '1970-01-01T00:00:00.000000040Z'),
+(2.0, 'you', '1970-01-01T00:00:00.000000020Z');
+
+query TP
+SELECT foo, first_value(time ORDER BY time DESC NULLS LAST) AS time FROM
table1 GROUP BY foo ORDER BY foo;
+----
+me 1970-01-01T00:00:00.000000040Z
+you 1970-01-01T00:00:00.000000020Z
+
+query TP
+SELECT foo, last_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1
GROUP BY foo ORDER BY foo;
+----
+me 1970-01-01T00:00:00.000000010Z
+you 1970-01-01T00:00:00.000000020Z
+
+statement ok
+drop table table1;
+
+
#fn window_frame_ranges_unbounded_preceding_err
statement error DataFusion error: Error during planning: Invalid window frame:
end bound cannot be UNBOUNDED PRECEDING
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]