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
[SPARK-32459][SQL] Support WrappedArray as customCollectionCls in MapObjects #29261
Conversation
@cloud-fan @viirya @maropu Please take a look, thanks! |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
Outdated
Show resolved
Hide resolved
Test build #126647 has finished for PR 29261 at commit
|
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
Outdated
Show resolved
Hide resolved
I checked it and the fix looks okay except for the existing comments. |
Thanks all! I've addressed your comments. Please take another look! |
""", | ||
(genValue: String) => s"$builder.$$plus$$eq($genValue);", | ||
s"(${cls.getName}) ${classOf[WrappedArray[_]].getName}$$." + | ||
s"MODULE$$.make(((${classOf[ArrayBuffer[_]].getName})$builder" + |
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.
$builder.result()
is a ArrayBuffer
?
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.
Isn't WrappedArray
HasNewBuilder[T, WrappedArray[T]]
, so result
should return a WrappedArray
?
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.
$builder.result() is a ArrayBuffer?
Yes.
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.
What do you mean by HasNewBuilder
? I can't find it.
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.
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 see. I believe it's the difference between the WrappedArray
instance and the WrappedArray
object. The instance one is inherited from HasNewBuilder[T, WrappedArray[T]]
but the object is not.
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. Object WrappedArray
's newBuilder
is def newBuilder[A]: Builder[A, IndexedSeq[A]]
.
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.
Then I think IndexedSeq
is safer?
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.
Sounds reasonable.
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.
updated, thanks!
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.
It looks good to me. Just one suggestion about the builder's result type.
Test build #126692 has finished for PR 29261 at commit
|
(genValue: String) => s"$builder.$$plus$$eq($genValue);", | ||
s"(${cls.getName}) ${classOf[WrappedArray[_]].getName}$$." + | ||
s"MODULE$$.make(((${classOf[ArrayBuffer[_]].getName})$builder" + | ||
s".result()).toArray(scala.reflect.ClassTag$$.MODULE$$.Object()));" |
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.
nit: remove s
in the head.
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.
it's required by the escape char $
.
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, I see.
@@ -755,6 +755,9 @@ case class MapObjects private( | |||
} | |||
|
|||
private lazy val mapElements: Seq[_] => Any = customCollectionCls match { | |||
case Some(cls) if classOf[WrappedArray[_]].isAssignableFrom(cls) => |
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.
does it really work with any sub-class of WrappedArray
?
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. We use WrappedArray.make()
below to generate the sub-calss of WrappedArray
and make()
supports all the sub-calsses.
Test build #126704 has finished for PR 29261 at commit
|
thanks, merging to master! |
thanks all! |
What changes were proposed in this pull request?
This PR supports
WrappedArray
ascustomCollectionCls
inMapObjects
.Why are the changes needed?
This helps fix the regression caused by SPARK-31826. For the following test, it can pass in branch-3.0 but fail in master branch:
In SPARK-31826, we've changed the catalyst-to-scala converter from
CatalystTypeConverters
toExpressionEncoder.deserializer
. However,CatalystTypeConverters
supportsWrappedArray
whileExpressionEncoder.deserializer
doesn't.Does this PR introduce any user-facing change?
No, SPARK-31826 is merged into master and branch-3.1, which haven't been released.
How was this patch tested?
Added a new test for
WrappedArray
inUDFSuite
; Also updatedObjectExpressionsSuite
forMapObjects
.