Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/16541#discussion_r95923248
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
---
@@ -307,54 +307,11 @@ object ScalaReflection extends ScalaReflection {
}
}
- val array = Invoke(
- MapObjects(mapFunction, getPath, dataType),
- "array",
- ObjectType(classOf[Array[Any]]))
-
- val wrappedArray = StaticInvoke(
- scala.collection.mutable.WrappedArray.getClass,
- ObjectType(classOf[Seq[_]]),
- "make",
- array :: Nil)
-
- if (localTypeOf[scala.collection.mutable.WrappedArray[_]] <:<
t.erasure) {
- wrappedArray
- } else {
- // Convert to another type using `to`
- val cls = mirror.runtimeClass(t.typeSymbol.asClass)
- import scala.collection.generic.CanBuildFrom
- import scala.reflect.ClassTag
-
- // Some canBuildFrom methods take an implicit ClassTag parameter
- val cbfParams = try {
- cls.getDeclaredMethod("canBuildFrom", classOf[ClassTag[_]])
- StaticInvoke(
- ClassTag.getClass,
- ObjectType(classOf[ClassTag[_]]),
- "apply",
- StaticInvoke(
- cls,
- ObjectType(classOf[Class[_]]),
- "getClass"
- ) :: Nil
- ) :: Nil
- } catch {
- case _: NoSuchMethodException => Nil
- }
-
- Invoke(
- wrappedArray,
- "to",
- ObjectType(cls),
- StaticInvoke(
- cls,
- ObjectType(classOf[CanBuildFrom[_, _, _]]),
- "canBuildFrom",
- cbfParams
- ) :: Nil
- )
+ val cls = t.companion.decl(TermName("newBuilder")) match {
+ case NoSymbol => classOf[Seq[_]]
--- End diff --
I checked that the builder for `Seq[_]` is a `mutable.ListBuffer` and its
build result will be `immutable.List`. But the original deserialized type of
`Seq[_]` is a `WrappedArray`.
Can we keep the original expression if we can't find `newBuilder` here,
i.e., returning the `WrappedArray`?
Or use `WrappedArray` as the `collClass` instead of `Seq`?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]