-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-41412][CONNECT] Implement Column.cast
#38970
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,11 @@ message Expression { | |
| Expression expr = 1; | ||
|
|
||
| // (Required) the data type that the expr to be casted to. | ||
| DataType cast_to_type = 2; | ||
| oneof cast_to_type { | ||
| DataType type = 2; | ||
| // If this is set, Server will use Catalyst parser to parse this string to DataType. | ||
| string type_str = 3; | ||
|
Contributor
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. I add this to follow the design principle so far that we should move repeated clients implementation to the server side to reduce client side redundant work. Otherwise client side will need to implement
Contributor
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 comes back to the discussion that I had in my draft PR if the second argument to the |
||
| } | ||
| } | ||
|
|
||
| message Literal { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -518,9 +518,16 @@ class SparkConnectPlanner(session: SparkSession) { | |
| } | ||
|
|
||
| private def transformCast(cast: proto.Expression.Cast): Expression = { | ||
| Cast( | ||
| transformExpression(cast.getExpr), | ||
| DataTypeProtoConverter.toCatalystType(cast.getCastToType)) | ||
| cast.getCastToTypeCase match { | ||
| case proto.Expression.Cast.CastToTypeCase.TYPE => | ||
| Cast( | ||
| transformExpression(cast.getExpr), | ||
| DataTypeProtoConverter.toCatalystType(cast.getType)) | ||
| case _ => | ||
| Cast( | ||
| transformExpression(cast.getExpr), | ||
| session.sessionState.sqlParser.parseDataType(cast.getTypeStr)) | ||
|
Comment on lines
+527
to
+529
Contributor
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. Wouldn't it be nice if we could just add a second string argument to the
Contributor
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. I am not following this? Can you give some example proto/sample code? Are you saying we do not use
Contributor
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. When I looked at cast as a unicorn in the context of expressions, it's one of the few where not all argument types resolve to expressions. I was wondering if we could simplify the approach to make the type argument of cast an expression that can resolve as a string then we can do the matching of the expression in the analyzer. This is very similar to why you added the oneof to the proto message. |
||
| } | ||
| } | ||
|
|
||
| private def transformSetOperation(u: proto.SetOperation): LogicalPlan = { | ||
|
|
||
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.
FYI: this is a breaking change in the proto message. Ideally, we would use
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.
Ah thanks. I didn't know this way to evolve the proto.
Given Spark Connect is still alpha component though for now we don't need to be enforced to maintain the backwards compatibility.
But when we are ready to leave from the alpha component then we should follow this way.
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 it's fine since this message has not been actually used?
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 we are ok now. But later there is indeed a need to build a process/good practice etc. for how to evolve proto without breaking older versions (if possible)
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're ok now. We can use Buf to check for breaking changes.