Apache DataFusion SQL Query Engine
chore: fix `last_value` coercion (#10783)
Chunchun Ye729b356ef543
diff --git a/datafusion/functions-aggregate/src/first_last.rs b/datafusion/functions-aggregate/src/first_last.rsindex 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 allowedTypeSignature::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.sltindex 2d5dd439d7..13729d6e49 100644--- a/datafusion/sqllogictest/test_files/window.slt+++ b/datafusion/sqllogictest/test_files/window.slt@@ -925,12 +925,43 @@ SELECT2022-09-29T15:16:34 2 1 12022-09-30T19:03:14 1 1 1+statement okdrop table tstatement okdrop 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_errstatement error DataFusion error: Error during planning: Invalid window frame: end bound cannot be UNBOUNDED PRECEDING