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 @@ -48,7 +48,11 @@ private[sql] object JsonRDD extends Logging {
require(samplingRatio > 0, s"samplingRatio ($samplingRatio) should be greater than 0")
val schemaData = if (samplingRatio > 0.99) json else json.sample(false, samplingRatio, 1)
val allKeys =
parseJson(schemaData, columnNameOfCorruptRecords).map(allKeysWithValueTypes).reduce(_ ++ _)
if (schemaData.isEmpty()) {
Set.empty[(String,DataType)]
} else {
parseJson(schemaData, columnNameOfCorruptRecords).map(allKeysWithValueTypes).reduce(_ ++ _)
}
createSchema(allKeys)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,4 +1033,11 @@ class JsonSuite extends QueryTest {
assert(!logicalRelation2.sameResult(logicalRelation3),
s"$logicalRelation2 and $logicalRelation3 should be considered not having the same result.")
}

test("SPARK-6245 JsonRDD.inferSchema on empty RDD") {
// This is really a test that it doesn't throw an exception
val emptySchema = JsonRDD.inferSchema(empty, 1.0, "")
assert(StructType(Seq()) === emptySchema)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,7 @@ object TestJsonData {
"""{"a":{, b:3}""" ::
"""{"b":"str_b_4", "a":"str_a_4", "c":"str_c_4"}""" ::
"""]""" :: Nil)

val empty =
TestSQLContext.sparkContext.parallelize(Seq[String]())
}