Skip to content
Snippets Groups Projects
Commit e643de42 authored by Joseph K. Bradley's avatar Joseph K. Bradley Committed by Michael Armbrust
Browse files

[SPARK-5504] [sql] convertToCatalyst should support nested arrays

After the recent refactoring, convertToCatalyst in ScalaReflection does not recurse on Arrays. It should.

The test suite modification made the test fail before the fix in ScalaReflection.  The fix makes the test suite succeed.

CC: marmbrus

Author: Joseph K. Bradley <joseph@databricks.com>

Closes #4295 from jkbradley/SPARK-5504 and squashes the following commits:

6b7276d [Joseph K. Bradley] Fixed issue in ScalaReflection.convertToCatalyst with Arrays with non-primitive types. Modified test suite so it failed before the fix and works after the fix.
parent 98697734
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,11 @@ trait ScalaReflection {
case (obj, udt: UserDefinedType[_]) => udt.serialize(obj)
case (o: Option[_], _) => o.map(convertToCatalyst(_, dataType)).orNull
case (s: Seq[_], arrayType: ArrayType) => s.map(convertToCatalyst(_, arrayType.elementType))
case (s: Array[_], arrayType: ArrayType) => s.toSeq
case (s: Array[_], arrayType: ArrayType) => if (arrayType.elementType.isPrimitive) {
s.toSeq
} else {
s.toSeq.map(convertToCatalyst(_, arrayType.elementType))
}
case (m: Map[_, _], mapType: MapType) => m.map { case (k, v) =>
convertToCatalyst(k, mapType.keyType) -> convertToCatalyst(v, mapType.valueType)
}
......
......@@ -64,7 +64,8 @@ case class ComplexData(
arrayFieldContainsNull: Seq[java.lang.Integer],
mapField: Map[Int, Long],
mapFieldValueContainsNull: Map[Int, java.lang.Long],
structField: PrimitiveData)
structField: PrimitiveData,
nestedArrayField: Array[Array[Int]])
case class GenericData[A](
genericField: A)
......@@ -158,7 +159,10 @@ class ScalaReflectionSuite extends FunSuite {
StructField("shortField", ShortType, nullable = false),
StructField("byteField", ByteType, nullable = false),
StructField("booleanField", BooleanType, nullable = false))),
nullable = true))),
nullable = true),
StructField(
"nestedArrayField",
ArrayType(ArrayType(IntegerType, containsNull = false), containsNull = true)))),
nullable = true))
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment