You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/06/03 06:48:52 UTC
(datafusion) branch gh-readonly-queue/main/pr-22304-a786471abc04b7271bf4d764054473f9317fb90c created (now e2db7668f6)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-22304-a786471abc04b7271bf4d764054473f9317fb90c
in repository https://gitbox.apache.org/repos/asf/datafusion.git
at e2db7668f6 fix nth_value window function negates i64::MIN (#22304)
This branch includes the following new commits:
new e2db7668f6 fix nth_value window function negates i64::MIN (#22304)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion) 01/01: fix nth_value window function negates i64::MIN (#22304)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-22304-a786471abc04b7271bf4d764054473f9317fb90c
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit e2db7668f621aafb1a09aacdbdb8b0bd37b0caa3
Author: Zhen Chen <cz...@163.com>
AuthorDate: Wed Jun 3 14:48:29 2026 +0800
fix nth_value window function negates i64::MIN (#22304)
## Which issue does this PR close?
- Closes #22222.
## Rationale for this change
`nth_value` could panic at execution time when called with `i64::MIN` as
the `n` argument. The implementation supports negative `n` for reverse
indexing and negated the value internally, but negating `i64::MIN`
overflows. This caused a runtime panic instead of returning a normal
DataFusion error for invalid input.
## What changes are included in this PR?
This PR adds validation for the second argument of `nth_value` so that
`i64::MIN` is rejected before any negation occurs. Instead of panicking
during execution, the function now returns a regular execution error.
This PR also adds regression coverage at two levels:
- a unit test for the `nth_value` window function implementation
- a sqllogictest case covering the SQL query shape that previously
triggered the panic
## Are these changes tested?
Yes.
The change is covered by:
1. a focused unit test in the window function implementation
2. a SQL logic test in `window.slt`
Validated with:
1. `cargo test -p datafusion-functions-window nth_value --lib`
2. `cargo test -p datafusion-sqllogictest --test sqllogictests window`
## Are there any user-facing changes?
Yes. Queries that previously panicked when calling `nth_value(...,
-9223372036854775808)` now return a proper execution error instead.
---
datafusion/functions-window/src/nth_value.rs | 29 +++++++++++++++++++++++++++
datafusion/sqllogictest/test_files/window.slt | 4 ++++
2 files changed, 33 insertions(+)
diff --git a/datafusion/functions-window/src/nth_value.rs b/datafusion/functions-window/src/nth_value.rs
index 437b4ecdb3..df72377216 100644
--- a/datafusion/functions-window/src/nth_value.rs
+++ b/datafusion/functions-window/src/nth_value.rs
@@ -125,6 +125,14 @@ impl NthValue {
}
}
+fn validate_nth_value_n(n: i64) -> Result<i64> {
+ if n == i64::MIN {
+ return exec_err!("The second argument of nth_value must not be i64::MIN");
+ }
+
+ Ok(n)
+}
+
static FIRST_VALUE_DOCUMENTATION: LazyLock<Documentation> = LazyLock::new(|| {
Documentation::builder(
DOC_SECTION_ANALYTICAL,
@@ -287,6 +295,7 @@ impl WindowUDFImpl for NthValue {
.map(|v| get_signed_integer(&v))
{
Some(Ok(n)) => {
+ let n = validate_nth_value_n(n)?;
if partition_evaluator_args.is_reversed() {
-n
} else {
@@ -660,4 +669,24 @@ mod tests {
)?;
Ok(())
}
+
+ #[test]
+ fn nth_value_i64_min_returns_error() {
+ let expr = Arc::new(Column::new("c3", 0)) as Arc<dyn PhysicalExpr>;
+ let n_value = Arc::new(Literal::new(ScalarValue::Int64(Some(i64::MIN))))
+ as Arc<dyn PhysicalExpr>;
+
+ let err = NthValue::nth()
+ .partition_evaluator(PartitionEvaluatorArgs::new(
+ &[expr, n_value],
+ &[Field::new("f", DataType::Int32, true).into()],
+ false,
+ false,
+ ))
+ .unwrap_err();
+
+ assert!(err.to_string().starts_with(
+ "Execution error: The second argument of nth_value must not be i64::MIN"
+ ));
+ }
}
diff --git a/datafusion/sqllogictest/test_files/window.slt b/datafusion/sqllogictest/test_files/window.slt
index 1c614f6a22..bc2f1bfcbc 100644
--- a/datafusion/sqllogictest/test_files/window.slt
+++ b/datafusion/sqllogictest/test_files/window.slt
@@ -1215,6 +1215,10 @@ NULL 3917
-1114 -1114
15673 15673
+statement error Execution error: The second argument of nth_value must not be i64::MIN
+SELECT nth_value(x, -9223372036854775808) OVER (ORDER BY x)
+FROM (VALUES (1)) AS t(x);
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org