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 @@ -485,6 +485,13 @@ object ScalaReflection extends ScalaReflection {
extractorFor(unwrapped, optType, newPath))
}

// Since List[_] also belongs to localTypeOf[Product], we put this case before
// "case t if t <:< localTypeOf[Product]" to make sure it will match to the
// case "localTypeOf[Seq[_]]"
case t if t <:< localTypeOf[Seq[_]] =>
val TypeRef(_, _, Seq(elementType)) = t
toCatalystArray(inputObject, elementType)

case t if t <:< localTypeOf[Product] =>
val params = getConstructorParameters(t)
val nonNullOutput = CreateNamedStruct(params.flatMap { case (fieldName, fieldType) =>
Expand All @@ -500,10 +507,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 @@ -21,7 +21,9 @@ import java.math.BigInteger
import java.sql.{Date, Timestamp}

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

case class PrimitiveData(
intField: Int,
Expand Down Expand Up @@ -229,4 +231,16 @@ class ScalaReflectionSuite extends SparkFunSuite {
assert(anyTypes.forall(!_.isPrimitive))
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 = extractorsFor[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]])
}
}