-
Notifications
You must be signed in to change notification settings - Fork 164
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
minor: Refactor binary expr serde to reduce code duplication #1053
Conversation
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 is a beautiful refactor!
I will follow up with similar PRs for UnaryExpr and MathExpr |
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.
LGTM.
@@ -2388,7 +2388,7 @@ mod tests { | |||
}; | |||
|
|||
let expr = spark_expression::Expr { | |||
expr_struct: Some(Eq(Box::new(spark_expression::Equal { | |||
expr_struct: Some(Eq(Box::new(spark_expression::BinaryExpr { |
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'm guessing this is the only place where the expression needed to be updated explicitly?
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.
Yes
ExprOuterClass.Expr | ||
.newBuilder() | ||
.setEq(builder) | ||
.build() |
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 feel these lines can be a part of createBinaryExpr
so that we do not have to map()
?
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 block of code is specifically for creating BinaryExpr eq = 9
(note the call to setEq
that uses the result of createBinaryExpr
). Each of these 20 similar blocks of code is for setting a specific top-level expr_struct
. It is only the contained BinaryExpr
struct that is common to each one. Does that make 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.
Hmm .. perhaps I could refactor farther so that the map
receives an ExprOuterClass.Expr.Builder
and then only has to call setEq
in the map block. That would be more concise. I will try that as a follow on PR after #1056 is merged
Thanks for the reviews @kazuyukitanimura @parthchandra @parthchandra |
Which issue does this PR close?
N/A
Rationale for this change
We currently have 20 duplicate structs defined in protobuf for binary expressions, such as:
As a result, we have a lot of duplicate code in QueryPlanSerde for serializing binary expressions that cannot easily be refactored because each code block references a different (but identical) generated class.
What changes are included in this PR?
How are these changes tested?
Existing tests