Skip to content

Commit

Permalink
[SPARK-2908] [SQL] JsonRDD.nullTypeToStringType does not convert all …
Browse files Browse the repository at this point in the history
…NullType to StringType

JIRA: https://issues.apache.org/jira/browse/SPARK-2908

Author: Yin Huai <huai@cse.ohio-state.edu>

Closes #1840 from yhuai/SPARK-2908 and squashes the following commits:

86e833e [Yin Huai] Update test.
cb11759 [Yin Huai] nullTypeToStringType should check columns with the type of array of structs.
  • Loading branch information
yhuai authored and marmbrus committed Aug 8, 2014
1 parent 9016af3 commit 0489cee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 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 @@ -263,8 +264,12 @@ 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
sql("select arrayOfStruct[0], arrayOfStruct[1], arrayOfStruct[2], arrayOfStruct[3] " +
"from jsonTable"),
(true :: "str1" :: null :: Nil,
false :: null :: null :: Nil,
null :: null :: null :: Nil,
null) :: 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 0489cee

Please sign in to comment.