Jefffrey commented on code in PR #19496:
URL: https://github.com/apache/datafusion/pull/19496#discussion_r2665102087
##########
datafusion/functions-window/src/nth_value.rs:
##########
@@ -370,6 +371,33 @@ impl PartitionEvaluator for NthValueEvaluator {
fn memoize(&mut self, state: &mut WindowAggState) -> Result<()> {
let out = &state.out_col;
let size = out.len();
+ if self.ignore_nulls {
+ match self.state.kind {
+ // Prune on first non-null output in case of FIRST_VALUE
+ NthValueKind::First => {
+ if let Some(nulls) = out.nulls() {
+ if self.state.finalized_result.is_none() {
+ if let Some(valid_index) =
nulls.valid_indices().next() {
+ let result =
+ ScalarValue::try_from_array(out,
valid_index)?;
+ self.state.finalized_result = Some(result);
Review Comment:
I notice for below we memoize the last value in the `out` column whereas
here we do the first; does it make a difference?
##########
datafusion/functions-window/src/nth_value.rs:
##########
@@ -370,6 +371,33 @@ impl PartitionEvaluator for NthValueEvaluator {
fn memoize(&mut self, state: &mut WindowAggState) -> Result<()> {
let out = &state.out_col;
let size = out.len();
+ if self.ignore_nulls {
+ match self.state.kind {
+ // Prune on first non-null output in case of FIRST_VALUE
+ NthValueKind::First => {
+ if let Some(nulls) = out.nulls() {
+ if self.state.finalized_result.is_none() {
+ if let Some(valid_index) =
nulls.valid_indices().next() {
+ let result =
+ ScalarValue::try_from_array(out,
valid_index)?;
+ self.state.finalized_result = Some(result);
+ } else {
+ // The output is empty or all nulls, ignore
+ }
+ }
+ if state.window_frame_range.start <
state.window_frame_range.end {
+ state.window_frame_range.start =
+ state.window_frame_range.end - 1;
+ }
Review Comment:
Is this equivalent to the `is_prunable` check (for `NthValueKind::First`)
where it ensures `n_range` > 0 and then if pruning it does
`state.window_frame_range.start =
state.window_frame_range.end.saturating_sub(buffer_size)`?
##########
datafusion/functions-window/src/nth_value.rs:
##########
@@ -370,6 +371,33 @@ impl PartitionEvaluator for NthValueEvaluator {
fn memoize(&mut self, state: &mut WindowAggState) -> Result<()> {
let out = &state.out_col;
let size = out.len();
+ if self.ignore_nulls {
+ match self.state.kind {
+ // Prune on first non-null output in case of FIRST_VALUE
+ NthValueKind::First => {
+ if let Some(nulls) = out.nulls() {
+ if self.state.finalized_result.is_none() {
Review Comment:
There's a small pedantic case here; so if we have no null buffer (no nulls)
then we fallback to existing behaviour below. If we have a null buffer, we try
memoize if we haven't already but we'll still return from this point onwards
(we won't fallback). But if the null buffer has no nulls then we don't fall
through like before, we just handle the return here.
I guess it is the same result and I don't think it's too much of a concern
at runtime, but it's just a potential path I find inconsistent when reading
this code flow 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]