Skip to content

Commit

Permalink
[SPARK-5504] [sql] convertToCatalyst should support nested arrays
Browse files Browse the repository at this point in the history
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 <[email protected]>

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.
  • Loading branch information
jkbradley authored and marmbrus committed Jan 30, 2015
1 parent 9869773 commit e643de4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit e643de4

Please sign in to comment.