-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Remove parse_vec_expr
helper
#12178
Remove parse_vec_expr
helper
#12178
Conversation
Behavior of `parse_vec_expr` and `parse_exprs` is almost similar -- both take a collection of expressions to parse. The only difference is that `parse_vec_expr` returns `Option::None` when collections is empty, but this difference in behavior does not correspond to difference in function names. Since the function is used once only, remove it instead of coming up with a fancy name.
4661698
to
e09f43d
Compare
match pb.order_by.len() { | ||
0 => None, | ||
_ => Some(parse_exprs(&pb.order_by, registry, codec)?), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this pattern is already used here
datafusion/datafusion/proto/src/logical_plan/mod.rs
Lines 817 to 819 in 117ab1b
let sort_expr = match distinct_on.sort_expr.len() { | |
0 => None, | |
_ => Some( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if in both places, we could use another new helper like
fn optimize_empty_vec<T>(v: Vec<T>) -> Option<Vec<T>> {
(!v.empty()).then_some(v)
}
so the combination would look like this:
optimize_empty_vec(parse_exprs(&pb.order_by, registry, codec)?)
However, that's a personal preference, mostly based on the fact that naming the input (pb.order_by
) twice, which can easily introduce copy&paste errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty_vec_to_none
? vec_if_non_empty
?
in this case, however, my preference would be to remove Option
and keep just Vec
.
Empty collection perfectly describes lack of sorting, so no need to wrap if with optional value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty collection perfectly describes lack of sorting, so no need to wrap if with optional value.
Let's try to do that then. I agree that having an Option<Vec<_>>
in new_udf
doesn't make much sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea. i would rather have this as a follow-up though.
this work would conflict with #12177 considerably.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filed #12195 issue for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is a reasonable change to me and we are tracking futher improvements. Let's keep the code flowing
Thank you @findepi and @crepererum for the review
Behavior of
parse_vec_expr
andparse_exprs
is almost similar -- both take a collection of expressions to parse. The only difference is thatparse_vec_expr
returnsOption::None
when collections is empty, but this difference in behavior does not correspond to difference in function names. Since the function is used once only, remove it instead of coming up with a fancy name.Prep for #12177