-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22000][SQL][FOLLOWUP] Add comment and simple cleanup to DeserializerBuildHelper #23916
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,25 +44,38 @@ object DeserializerBuildHelper { | |
| upCastToExpectedType(newPath, dataType, walkedTypePath) | ||
| } | ||
|
|
||
| /** | ||
| * Returns an expression that can be used to deserialize input expression. | ||
| * | ||
| * @param expr The input expression that can be used to extract serialized value. | ||
| * @param nullable Whether deserialized expression evalutes to null value. | ||
| * @param walkedTypePath The paths from top to bottom to access current field when deserializing. | ||
| * @param funcForCreatingDeserializer Given input expression and typed path, this function | ||
| * returns deserializer expression. | ||
| */ | ||
| def deserializerForWithNullSafety( | ||
| expr: Expression, | ||
| dataType: DataType, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| nullable: Boolean, | ||
| walkedTypePath: Seq[String], | ||
| funcForCreatingNewExpr: (Expression, Seq[String]) => Expression): Expression = { | ||
| val newExpr = funcForCreatingNewExpr(expr, walkedTypePath) | ||
| funcForCreatingDeserializer: (Expression, Seq[String]) => Expression): Expression = { | ||
| val newExpr = funcForCreatingDeserializer(expr, walkedTypePath) | ||
| expressionWithNullSafety(newExpr, nullable, walkedTypePath) | ||
| } | ||
|
|
||
| /** | ||
| * This returns deserializer expression as `deserializerForWithNullSafety` does. The only | ||
| * difference is this method adds `UpCast` to input expression to avoid possible runtime | ||
| * error caused by type mimatch between serialized column data type and deserializing type. | ||
| */ | ||
| def deserializerForWithNullSafetyAndUpcast( | ||
| expr: Expression, | ||
| dataType: DataType, | ||
| nullable: Boolean, | ||
| walkedTypePath: Seq[String], | ||
| funcForCreatingNewExpr: (Expression, Seq[String]) => Expression): Expression = { | ||
| funcForCreatingDeserializer: (Expression, Seq[String]) => Expression): Expression = { | ||
| val casted = upCastToExpectedType(expr, dataType, walkedTypePath) | ||
| deserializerForWithNullSafety(casted, dataType, nullable, walkedTypePath, | ||
| funcForCreatingNewExpr) | ||
| deserializerForWithNullSafety(casted, nullable, walkedTypePath, | ||
| funcForCreatingDeserializer) | ||
| } | ||
|
|
||
| private def expressionWithNullSafety( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -322,13 +322,12 @@ object ScalaReflection extends ScalaReflection { | |
| val newTypePath = (s"""- field (class: "$clsName", """ + | ||
| s"""name: "$fieldName")""") +: walkedTypePath | ||
|
|
||
| // For tuples, we based grab the inner fields by ordinal instead of name. | ||
| deserializerForWithNullSafety( | ||
| path, | ||
| dataType, | ||
| nullable = nullable, | ||
| newTypePath, | ||
| (expr, typePath) => { | ||
| // For tuples, we based grab the inner fields by ordinal instead of name. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This location should be more proper for this comment. |
||
| if (cls.getName startsWith "scala.Tuple") { | ||
| deserializerFor( | ||
| fieldType, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we can remove it, according to #23908 (comment)
Uh oh!
There was an error while loading. Please reload this page.
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.
Remove
deserializerForWithNullSafety? So we calldeserializerForWithNullSafetyAndUpcastfor all cases?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.
have you read the comment? It's the same as
expressionWithNullSafetyThere 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, but looks like to remove
expressionWithNullSafetyand incorporate it intodeserializerForWithNullSafety?Uh oh!
There was an error while loading. Please reload this page.
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.
oh, i see. I don't see the all change around the change to
deserializerForWithNullSafetthere...since it is not shown if not clicking changes tab.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 think
expressionWithNullSafetyis more general naming so might be preferred one, butdeserializerForWithNullSafetyis also a good name cause we have relevant methoddeserializerForWithNullSafetyAndUpcast.So that's a matter of preference and either can be removed. Which method would we prefer to keep?
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.
Moving my comment to #23908 since it will keep updated.