Skip to content

Commit

Permalink
[SPARK-23094] Revert [] Fix invalid character handling in JsonDataSource
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?
This PR is to revert the PR apache#20302, because it causes a regression.

## How was this patch tested?
N/A

Author: gatorsmile <[email protected]>

Closes apache#20614 from gatorsmile/revertJsonFix.
  • Loading branch information
gatorsmile committed Feb 15, 2018
1 parent a77ebb0 commit 95e4b49
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ private[sql] object CreateJacksonParser extends Serializable {
}

def text(jsonFactory: JsonFactory, record: Text): JsonParser = {
val bain = new ByteArrayInputStream(record.getBytes, 0, record.getLength)
jsonFactory.createParser(new InputStreamReader(bain, "UTF-8"))
jsonFactory.createParser(record.getBytes, 0, record.getLength)
}

def inputStream(jsonFactory: JsonFactory, record: InputStream): JsonParser = {
jsonFactory.createParser(new InputStreamReader(record, "UTF-8"))
jsonFactory.createParser(record)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import org.apache.spark.sql.types._
class JsonHadoopFsRelationSuite extends HadoopFsRelationTest {
override val dataSourceName: String = "json"

private val badJson = "\u0000\u0000\u0000A\u0001AAA"

// JSON does not write data of NullType and does not play well with BinaryType.
override protected def supportsDataType(dataType: DataType): Boolean = dataType match {
case _: NullType => false
Expand Down Expand Up @@ -107,36 +105,4 @@ class JsonHadoopFsRelationSuite extends HadoopFsRelationTest {
)
}
}

test("invalid json with leading nulls - from file (multiLine=true)") {
import testImplicits._
withTempDir { tempDir =>
val path = tempDir.getAbsolutePath
Seq(badJson, """{"a":1}""").toDS().write.mode("overwrite").text(path)
val expected = s"""$badJson\n{"a":1}\n"""
val schema = new StructType().add("a", IntegerType).add("_corrupt_record", StringType)
val df =
spark.read.format(dataSourceName).option("multiLine", true).schema(schema).load(path)
checkAnswer(df, Row(null, expected))
}
}

test("invalid json with leading nulls - from file (multiLine=false)") {
import testImplicits._
withTempDir { tempDir =>
val path = tempDir.getAbsolutePath
Seq(badJson, """{"a":1}""").toDS().write.mode("overwrite").text(path)
val schema = new StructType().add("a", IntegerType).add("_corrupt_record", StringType)
val df =
spark.read.format(dataSourceName).option("multiLine", false).schema(schema).load(path)
checkAnswer(df, Seq(Row(1, null), Row(null, badJson)))
}
}

test("invalid json with leading nulls - from dataset") {
import testImplicits._
checkAnswer(
spark.read.json(Seq(badJson).toDS()),
Row(badJson))
}
}

0 comments on commit 95e4b49

Please sign in to comment.