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 @@ -266,11 +266,7 @@ object JacksonParser {
} else {
array.toArray[InternalRow](schema)
}
case _ =>
sys.error(
s"Failed to parse record $record. Please make sure that each line of " +
"the file (or each string in the RDD) is a valid JSON object or " +
"an array of JSON objects.")
case _ => failedRecord(record)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that place, we can still throw. But, then, we catch the exception at https://github.com/apache/spark/pull/10043/files#diff-8affe5ec7d691943a88e43eb30af656eR272.

}
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1427,4 +1427,31 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData {
}
}
}

test("SPARK-12057 additional corrupt records do not throw exceptions") {
// Test if we can query corrupt records.
withSQLConf(SQLConf.COLUMN_NAME_OF_CORRUPT_RECORD.key -> "_unparsed") {
withTempTable("jsonTable") {
val schema = StructType(
StructField("_unparsed", StringType, true) ::
StructField("dummy", StringType, true) :: Nil)
val jsonDF = sqlContext.read.schema(schema).json(additionalCorruptRecords)
jsonDF.registerTempTable("jsonTable")

// In HiveContext, backticks should be used to access columns starting with a underscore.
checkAnswer(
sql(
"""
|SELECT dummy, _unparsed
|FROM jsonTable
""".stripMargin),
Row("test", null) ::
Row(null, """42""") ::
Row(null, """ ","ian":"test"}""") :: Nil
)

}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ private[json] trait TestJsonData {
"""{"b":"str_b_4", "a":"str_a_4", "c":"str_c_4"}""" ::
"""]""" :: Nil)

def additionalCorruptRecords: RDD[String] =
sqlContext.sparkContext.parallelize(
"""{"dummy":"test"}""" ::
"""42""" ::
""" ","ian":"test"}""" :: Nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a record like """[1,, 2, 3]""" (a top level JSON array having and its elements are not JSON objects)?


def emptyRecords: RDD[String] =
sqlContext.sparkContext.parallelize(
"""{""" ::
Expand Down