Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ object ScalaReflection extends ScalaReflection {
serializerFor(unwrapped, optType, newPath))
}

// Since List[_] also belongs to localTypeOf[Product], we put this case before
// "case t if definedByConstructorParams(t)" to make sure it will match to the
// case "localTypeOf[Seq[_]]"
case t if t <:< localTypeOf[Seq[_]] =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some comment to the definedByConstructorParams case to explain it is sensitive to ordering, and why?

val TypeRef(_, _, Seq(elementType)) = t
toCatalystArray(inputObject, elementType)

case t if definedByConstructorParams(t) =>
val params = getConstructorParameters(t)
val nonNullOutput = CreateNamedStruct(params.flatMap { case (fieldName, fieldType) =>
Expand All @@ -524,10 +531,6 @@ object ScalaReflection extends ScalaReflection {
val TypeRef(_, _, Seq(elementType)) = t
toCatalystArray(inputObject, elementType)

case t if t <:< localTypeOf[Seq[_]] =>
val TypeRef(_, _, Seq(elementType)) = t
toCatalystArray(inputObject, elementType)

case t if t <:< localTypeOf[Map[_, _]] =>
val TypeRef(_, _, Seq(keyType, valueType)) = t

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import java.sql.{Date, Timestamp}
import scala.reflect.runtime.universe.typeOf

import org.apache.spark.SparkFunSuite
import org.apache.spark.sql.catalyst.expressions.{BoundReference, SpecificMutableRow}
import org.apache.spark.sql.catalyst.expressions.{BoundReference, Literal, NewInstance, SpecificMutableRow}
import org.apache.spark.sql.types._
import org.apache.spark.unsafe.types.UTF8String
import org.apache.spark.util.Utils

case class PrimitiveData(
Expand Down Expand Up @@ -277,6 +278,18 @@ class ScalaReflectionSuite extends SparkFunSuite {
assert(anyTypes === Seq(classOf[java.lang.Object], classOf[java.lang.Object]))
}

test("SPARK-15062: Get correct serializer for List[_]") {
val list = List(1, 2, 3)
val serializer = serializerFor[List[Int]](BoundReference(
0, ObjectType(list.getClass), nullable = false))
assert(serializer.children.size == 2)
assert(serializer.children.head.isInstanceOf[Literal])
assert(serializer.children.head.asInstanceOf[Literal].value === UTF8String.fromString("value"))
assert(serializer.children.last.isInstanceOf[NewInstance])
assert(serializer.children.last.asInstanceOf[NewInstance]
.cls.isInstanceOf[Class[org.apache.spark.sql.catalyst.util.GenericArrayData]])
}

private val dataTypeForComplexData = dataTypeFor[ComplexData]
private val typeOfComplexData = typeOf[ComplexData]

Expand Down