-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-31826][SQL] Support composed type of case class for typed Scala UDF #28645
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 9 commits
25c881b
4546f35
c1a2d1c
d13f1c7
bb26320
5e0f445
8576d28
1afbdf5
86035fa
21e8aaf
2527c69
26fc42b
9e986f0
7568e8c
6b384b4
1c82558
21ae72b
bdbd45b
4db6401
3e97fa5
e6bb55d
f29a62a
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 |
|---|---|---|
|
|
@@ -256,7 +256,8 @@ class Analyzer( | |
| Batch("Nondeterministic", Once, | ||
| PullOutNondeterministic), | ||
| Batch("UDF", Once, | ||
| HandleNullInputsForUDF), | ||
| HandleNullInputsForUDF, | ||
| ResolveEncodersInUDF), | ||
| Batch("UpdateNullability", Once, | ||
| UpdateAttributeNullability), | ||
| Batch("Subquery", Once, | ||
|
|
@@ -2847,6 +2848,36 @@ class Analyzer( | |
| } | ||
| } | ||
|
|
||
| object ResolveEncodersInUDF extends Rule[LogicalPlan] { | ||
| override def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperatorsUp { | ||
| case p if !p.resolved => p // Skip unresolved nodes. | ||
|
|
||
| case p => p transformExpressionsUp { | ||
|
|
||
| case udf @ ScalaUDF(_, _, inputs, encoders, _, _, _) if encoders.nonEmpty => | ||
|
Member
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. Shall we avoid argument matching? It's actually an anti-pattern - https://github.com/databricks/scala-style-guide#pattern-matching
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. I see, thanks! |
||
| val resolvedEncoders = encoders.zipWithIndex.map { case (encOpt, i) => | ||
|
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. maybe to call it |
||
| val dataType = inputs(i).dataType | ||
| if (dataType.isInstanceOf[UserDefinedType[_]]) { | ||
|
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. what about struct/array/map of UDT? |
||
| // for UDT, we use `CatalystTypeConverters` | ||
|
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. encoder does support UDT. We can figure it out later.
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. It does, but just doesn't support upcast from the subclass to the parent class. So, when the input data type from the child is the subclass of the input parameter data type of the udf, I think this may need a separate fix. |
||
| None | ||
| } else { | ||
| encOpt.map { enc => | ||
| val attrs = if (enc.isSerializedAsStructForTopLevel) { | ||
| dataType.asInstanceOf[StructType].toAttributes | ||
| } else { | ||
| // the field name doesn't matter here, so we use | ||
| // a simple literal to avoid any overhead | ||
| new StructType().add("input", dataType).toAttributes | ||
| } | ||
|
cloud-fan marked this conversation as resolved.
|
||
| enc.resolveAndBind(attrs) | ||
| } | ||
| } | ||
| } | ||
| udf.copy(inputEncoders = resolvedEncoders) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Check and add proper window frames for all window functions. | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.