Skip to content

Conversation

@nseekhao
Copy link
Contributor

Which issue does this PR close?

Closes # 5390.

Rationale for this change

Added the ability to producer/consume Substrait plans with WindowFunction

What changes are included in this PR?

  • Producer
    • Added LogicalPlan::Window case
      • If the input to this relation is a ProjectRel, append WindowFunction expressions before returning the parsed ProjectRel
      • If the input is NOT a projection, create a ProjectRel, add column reference expressions to represent ALL of the fields of the input relation's output. Then append WindowFunction expressions.
  • Consumer
    • Added case to parse WindowFunction
      • Note that the output WindowFrameUnits are currently set to either Rows or Range depending on whether ORDER BY is present in the WindowFunction. May need to revisit the cases when frame is explicitly defined.
    • Moved all sort fields logic into from_substrait_sorts()
  • Test
    • A single case that tests
      • Single/no argument
      • With/without ORDER BY
      • With PARTITION BY
      • Multiple WindowFunction expressions with column reference

Are these changes tested?

Yes. (cases explained above)

Are there any user-facing changes?

No

@github-actions github-actions bot added the substrait Changes to the substrait crate label Mar 20, 2023
@andygrove
Copy link
Member

@waynexia fyi

@nseekhao nseekhao force-pushed the substrait-window-function branch from 3f9d65b to 3a37ebc Compare March 21, 2023 18:49
},
Some(RexType::WindowFunction(window)) => {
let fun = match extensions.get(&window.function_reference) {
Some(function_name) => Ok(find_df_window_func(function_name)),
Copy link
Member

Choose a reason for hiding this comment

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

Should we return an error if find_df_window_func returns None here? We unwrap this later on currently, which could fail?

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

LGTM. There are a few option unwraps in here (some already existed), and I am not sure if they could cause a panic or not? Perhaps we can follow up with some improved checks for those.

@nseekhao
Copy link
Contributor Author

Makes sense. Should I create an issue for this?

@andygrove
Copy link
Member

Makes sense. Should I create an issue for this?

Yes, that would be great. Thanks.

Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

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

Looking good, thanks!

@andygrove andygrove merged commit 11ac836 into apache:main Mar 22, 2023
@andygrove andygrove added the enhancement New feature or request label Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request substrait Changes to the substrait crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants