Repository navigation
Conversation
…r results with `take`
comphead
force-pushed
the
nth-value-ignore-nulls
branch
from
October 23, 2026 16:00
9384811 to
40c848f
Compare
comphead
marked this pull request as ready for review
October 23, 2026 16:07
LAST_VALUE and NTH_VALUE with IGNORE NULLS, gather results with takeLAST_VALUE and NTH_VALUE with IGNORE NULLS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
LAST_VALUEandNTH_VALUEwithIGNORE NULLSsoBoundedWindowAggExeccan prune its buffer #26537.NTH_VALUE(expr, -n) IGNORE NULLSis quadratic in the partition size #26538.LAST_VALUEandNTH_VALUEwithIGNORE NULLSkeep the whole partition buffered #26539.FIRST_VALUE,LAST_VALUEandNTH_VALUEbuild aScalarValuefor every row #26540.Rationale for this change
With
IGNORE NULLS,LAST_VALUEandNTH_VALUEover a frame that starts at the partition's first row kept the whole partition buffered and rescanned long NULL runs for every row. #26533 already fixed the common case of #26538.FIRST_VALUE,LAST_VALUEandNTH_VALUEalso built aScalarValueper row, which is slow for nested types.What changes are included in this PR?
memoizemoves the frame start underIGNORE NULLStoo.LAST_VALUEkeeps its last non-NULL value and drops the whole frame.PartitionEvaluator::evaluate_rangesevaluates all frames of a batch at once, andNthValueEvaluatorimplements it with onetake. Unlike the row index thatFIRST_VALUE,LAST_VALUEandNTH_VALUEbuild aScalarValuefor every row #26540 suggests, this also covers a finalFIRST_VALUEresult whose row is already pruned.NTH_VALUE(expr, ±n)withn > 1still keeps the rows from the first valid row it needs.What is the testing strategy for this PR?
New
window.sltcases and amemoizeunit test. Indatafusion-cliwith therelease-nonltoprofile:mainlast_value(v) IGNORE NULLS, one 10M-row partitionlast_value(v) IGNORE NULLS, 1M rows with one non-NULL valuelast_value(st)over a struct, 64-row partitionsThe built-in function cases of
window_query_sqlare 9% to 73% faster, except one-row partitions (u64_wide), which are unchanged.Are there any user-facing changes?
PartitionEvaluatorgainsevaluate_ranges, with a default implementation.