feat: Enable expressions as default value in lead/lag function - #22134
feat: Enable expressions as default value in lead/lag function#22134sandugood wants to merge 19 commits into
Conversation
|
Added the tests in the window.slt file |
…efault-value-window
…fault-value-window
|
Would be nice if you could review this @comphead, if you have time |
|
Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days. |
| let default_array = values.get(1).cloned().unwrap_or_else(|| { | ||
| Arc::new(arrow::array::NullArray::new(value.len())) | ||
| }); | ||
| let default_array = if default_array.data_type() != value.data_type() { | ||
| arrow::compute::kernels::cast::cast(&default_array, value.data_type()) | ||
| .map_err(|e| arrow_datafusion_err!(e))? | ||
| } else { | ||
| default_array | ||
| }; |
There was a problem hiding this comment.
i do wonder if theres a way to pull this casting logic away from execution and into planning, perhaps by changing to a user defined signature for the window function and ensuring the default argument is coerced to the same type as the primary expression
There was a problem hiding this comment.
Moved it to the expressions() method of the WindowShift
There was a problem hiding this comment.
i still feel this is something that can be handled via signature planning 🤔
|
Thanks for comments, @Jefffrey |
|
Thanks @sandugood I will check the PR soon |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22134 +/- ##
==========================================
- Coverage 80.66% 80.65% -0.02%
==========================================
Files 1095 1095
Lines 372294 372423 +129
Branches 372294 372423 +129
==========================================
+ Hits 300324 300364 +40
- Misses 54055 54138 +83
- Partials 17915 17921 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
cc @xudong963 since you worked on optimizing lead/lag recently |
| # test LAG default is sum of two columns | ||
| query II | ||
| WITH t(a, b, c) AS (VALUES (1, 10, 100), (2, 20, 200), (3, 30, 300)) | ||
| SELECT a, lag(a, 1, b + c) OVER (ORDER BY a) FROM t |
|
I made an initial review with assistance of LLM and it comes up with some high severity issues that needed to be checked
|
Which issue does this PR close?
ColumnExprin LAG/LEAD for default parameter #22082.Rationale for this change
In the current DataFusion implementation we can only use a
ScalarValueas the default value in bothLAGandLEADwindow functions. That means that users can't reference other columns' values from the table as default value and create various combinations of them.It means that currently we cannot perform something like:
lead(col1, 1, col1 / col2) as lead_resultWhat changes are included in this PR?
DefaultValueenum that can be either aLiteralvalue or anExpressionparse_default_valuefunction to takedefault_value's type into considerationshift_with_array_defaultandevaluate_all_with_ignore_null_and_array_defaultfor the situations, whendefault_valueis ofDefaultValue::ExpressiontypeAre these changes tested?
Yes, changes were tested:
Are there any user-facing changes?
There are user-facing changes in terms of documentation and DataFusion usage (no syntax changes per se). Also, docs were updated