Skip to content

Commit

Permalink
fix: Panic non-integer for the second argument of nth_value function (
Browse files Browse the repository at this point in the history
#12076)

* fix: Panic non-integer for nth_value function

* chore: Display actual value

* Update datafusion/physical-plan/src/windows/mod.rs

Co-authored-by: Marco Neumann <[email protected]>

* chore

---------

Co-authored-by: Marco Neumann <[email protected]>
  • Loading branch information
Weijun-H and crepererum committed Aug 21, 2024
1 parent 7eeac2f commit 9d076bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions datafusion/physical-plan/src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ use crate::{

use arrow::datatypes::Schema;
use arrow_schema::{DataType, Field, SchemaRef};
use datafusion_common::{exec_err, DataFusionError, Result, ScalarValue};
use datafusion_common::{
exec_datafusion_err, exec_err, DataFusionError, Result, ScalarValue,
};
use datafusion_expr::{
BuiltInWindowFunction, PartitionEvaluator, WindowFrame, WindowFunctionDefinition,
WindowUDF,
Expand Down Expand Up @@ -284,7 +286,9 @@ fn create_built_in_window_expr(
args[1]
.as_any()
.downcast_ref::<Literal>()
.unwrap()
.ok_or_else(|| {
exec_datafusion_err!("Expected a signed integer literal for the second argument of nth_value, got {}", args[1])
})?
.value()
.clone(),
)?;
Expand Down
13 changes: 13 additions & 0 deletions datafusion/sqllogictest/test_files/window.slt
Original file line number Diff line number Diff line change
Expand Up @@ -4861,3 +4861,16 @@ select a, row_number(a) over (order by b) as rn from t;

statement ok
drop table t;

statement ok
DROP TABLE t1;

# https://github.com/apache/datafusion/issues/12073
statement ok
CREATE TABLE t1(v1 BIGINT);

query error DataFusion error: Execution error: Expected a signed integer literal for the second argument of nth_value, got v1@0
SELECT NTH_VALUE('+Inf'::Double, v1) OVER (PARTITION BY v1) FROM t1;

statement ok
DROP TABLE t1;

0 comments on commit 9d076bd

Please sign in to comment.