Skip to content

Commit

Permalink
nullTypeToStringType should check columns with the type of array of s…
Browse files Browse the repository at this point in the history
…tructs.
  • Loading branch information
yhuai committed Aug 7, 2014
1 parent b9e9e53 commit cb11759
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ private[sql] object JsonRDD extends Logging {
val newType = dataType match {
case NullType => StringType
case ArrayType(NullType, containsNull) => ArrayType(StringType, containsNull)
case struct: StructType => nullTypeToStringType(struct)
case ArrayType(struct: StructType, containsNull) =>
ArrayType(nullTypeToStringType(struct), containsNull)
case struct: StructType =>nullTypeToStringType(struct)
case other: DataType => other
}
StructField(fieldName, newType, nullable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ class JsonSuite extends QueryTest {
StructField("arrayOfStruct", ArrayType(
StructType(
StructField("field1", BooleanType, true) ::
StructField("field2", StringType, true) :: Nil)), true) ::
StructField("field2", StringType, true) ::
StructField("field3", StringType, true) :: Nil)), true) ::
StructField("struct", StructType(
StructField("field1", BooleanType, true) ::
StructField("field2", DecimalType, true) :: Nil), true) ::
Expand Down Expand Up @@ -264,7 +265,9 @@ class JsonSuite extends QueryTest {
// Access elements of an array of structs.
checkAnswer(
sql("select arrayOfStruct[0], arrayOfStruct[1], arrayOfStruct[2] from jsonTable"),
(true :: "str1" :: Nil, false :: null :: Nil, null) :: Nil
(true :: "str1" :: null :: Nil,
false :: null :: null :: Nil,
null :: null :: null :: Nil) :: Nil
)

// Access a struct and fields inside of it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object TestJsonData {
"arrayOfDouble":[1.2, 1.7976931348623157E308, 4.9E-324, 2.2250738585072014E-308],
"arrayOfBoolean":[true, false, true],
"arrayOfNull":[null, null, null, null],
"arrayOfStruct":[{"field1": true, "field2": "str1"}, {"field1": false}],
"arrayOfStruct":[{"field1": true, "field2": "str1"}, {"field1": false}, {"field3": null}],
"arrayOfArray1":[[1, 2, 3], ["str1", "str2"]],
"arrayOfArray2":[[1, 2, 3], [1.1, 2.1, 3.1]]
}""" :: Nil)
Expand Down

0 comments on commit cb11759

Please sign in to comment.