You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by al...@apache.org on 2025/01/14 11:45:45 UTC
(datafusion) branch main updated: clarify logic in nth_value window function (#14104)
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 888df6a97a clarify logic in nth_value window function (#14104)
888df6a97a is described below
commit 888df6a97a0e6539cba8465e4fa3be5ee742562a
Author: zjregee <zj...@gmail.com>
AuthorDate: Tue Jan 14 19:45:39 2025 +0800
clarify logic in nth_value window function (#14104)
---
datafusion/functions-window/src/nth_value.rs | 32 +++++++++++++++-------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/datafusion/functions-window/src/nth_value.rs b/datafusion/functions-window/src/nth_value.rs
index e5d866940c..16caa5293e 100644
--- a/datafusion/functions-window/src/nth_value.rs
+++ b/datafusion/functions-window/src/nth_value.rs
@@ -345,24 +345,26 @@ impl PartitionEvaluator for NthValueEvaluator {
return ScalarValue::try_from(arr.data_type());
}
- // Extract valid indices if ignoring nulls.
+ // If null values exist and need to be ignored, extract the valid indices.
let valid_indices = if self.ignore_nulls {
- // Calculate valid indices, inside the window frame boundaries
+ // Calculate valid indices, inside the window frame boundaries.
let slice = arr.slice(range.start, n_range);
- let valid_indices = slice
- .nulls()
- .map(|nulls| {
- nulls
+ match slice.nulls() {
+ Some(nulls) => {
+ let valid_indices = nulls
.valid_indices()
- // Add offset `range.start` to valid indices, to point correct index in the original arr.
- .map(|idx| idx + range.start)
- .collect::<Vec<_>>()
- })
- .unwrap_or_default();
- if valid_indices.is_empty() {
- None
- } else {
- Some(valid_indices)
+ .map(|idx| {
+ // Add offset `range.start` to valid indices, to point correct index in the original arr.
+ idx + range.start
+ })
+ .collect::<Vec<_>>();
+ if valid_indices.is_empty() {
+ // If all values are null, return directly.
+ return ScalarValue::try_from(arr.data_type());
+ }
+ Some(valid_indices)
+ }
+ None => None,
}
} else {
None
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org