Skip to content

[MINOR]: Update get range implementation for lead lag window functions#10614

Merged
ozankabak merged 1 commit intoapache:mainfrom
synnada-ai:feature/lead_lag_get_range
May 22, 2024
Merged

[MINOR]: Update get range implementation for lead lag window functions#10614
ozankabak merged 1 commit intoapache:mainfrom
synnada-ai:feature/lead_lag_get_range

Conversation

@mustafasrepo
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

While working on another PR, I have recognized that get_range implementation for LEAD, LAG window functions generates unnecessarily wide ranges when ignore_nulls flag is false. This PR, fixes this problem. This enables BoundedWindowAggExec to prune its input data better for LEAD, LAG window functions.

What changes are included in this PR?

Are these changes tested?

Yes, unit test is added

Are there any user-facing changes?

@github-actions github-actions bot added the physical-expr Changes to the physical-expr crates label May 22, 2024
idx.saturating_sub(offset)
} else if !self.ignore_nulls {
let offset = self.shift_offset as usize;
idx.saturating_sub(offset)
Copy link
Copy Markdown
Contributor Author

@mustafasrepo mustafasrepo May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of 0, we now return idx-offset(can be larger than 0, which will trigger pruning) for LAG

min(idx + offset + 1, n_rows)
} else if !self.ignore_nulls {
let offset = (-self.shift_offset) as usize;
min(idx + offset, n_rows)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of n_rows, we now return idx+offset(can be smaller than n_rows, which will required less data for correct result) for LEAD

Copy link
Copy Markdown
Contributor

@ozankabak ozankabak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ozankabak
Copy link
Copy Markdown
Contributor

Will go ahead and merge this quickly since it is trivial

@ozankabak ozankabak merged commit 8008413 into apache:main May 22, 2024
Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thanks @mustafasrepo

findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants