Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes missing nth_value UDAF expr function #12279

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

jcsherin
Copy link
Contributor

@jcsherin jcsherin commented Sep 1, 2024

Which issue does this PR close?

Closes #12278.

Rationale for this change

Same as #12278.

What changes are included in this PR?

The API in v40 is:

pub fn nth_value(args: Vec<Expr>) -> Expr

A better API would be this:

pub fn nth_value(
        expr: Expr,
        n: i64,
        order_by: Option<Vec<SortExpr>>
) -> Expr

Are these changes tested?

Yes. Logical roundtrip tests, both with and without order by expression.

Are there any user-facing changes?

Yes, this is a breaking change of user-facing API.

@github-actions github-actions bot added proto Related to proto crate functions Changes to functions implementation labels Sep 1, 2024
Comment on lines 43 to 59
/// Returns the nth value in a group of values.
pub fn nth_value(
expr: datafusion_expr::Expr,
n: i64,
order_by: Option<Vec<SortExpr>>,
) -> datafusion_expr::Expr {
let args = vec![expr, lit(n)];
if let Some(order_by) = order_by {
nth_value_udaf()
.call(args)
.order_by(order_by)
.build()
.unwrap()
} else {
nth_value_udaf().call(args)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

API changed here.

pub fn nth_value(
expr: datafusion_expr::Expr,
n: i64,
order_by: Option<Vec<SortExpr>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need Option for no ordering case? Can we represent no ordering case with empty vec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right. The option type is extraneous here. I'll make this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jcsherin
Copy link
Contributor Author

jcsherin commented Sep 2, 2024

I lack permission to apply the api-change label to this PR.

Copy link
Contributor

@jayzhan211 jayzhan211 left a comment

Choose a reason for hiding this comment

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

👍

@jayzhan211 jayzhan211 added the api change Changes the API exposed to users of the crate label Sep 2, 2024
@jayzhan211
Copy link
Contributor

Thanks @jcsherin

@jayzhan211 jayzhan211 merged commit 77e0e3b into apache:main Sep 2, 2024
24 checks passed
@jcsherin jcsherin deleted the redo-nth-value-expr-api branch September 2, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate functions Changes to functions implementation proto Related to proto crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NthValue UDAF removed in v41
2 participants