Skip to content

Commit

Permalink
Revert test for invalid encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Aug 17, 2018
1 parent 3240405 commit 2d8e754
Showing 1 changed file with 11 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2224,30 +2224,19 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData {
}

test("SPARK-23723: specified encoding is not matched to actual encoding") {
def doCount(bypassParser: Boolean, multiLine: Boolean): Long = {
var result: Long = -1
withSQLConf(SQLConf.BYPASS_PARSER_FOR_EMPTY_SCHEMA.key -> bypassParser.toString) {
val fileName = "test-data/utf16LE.json"
val schema = new StructType().add("firstName", StringType).add("lastName", StringType)
result = spark.read.schema(schema)
.option("mode", "FAILFAST")
.option("multiline", multiLine)
.options(Map("encoding" -> "UTF-16BE", "lineSep" -> "\n"))
.json(testFile(fileName))
.count()
}
result
}

Seq((true, true), (false, true), (false, false)).foreach { case (bypassParser, multiLine) =>
val exception = intercept[SparkException] {
doCount(bypassParser, multiLine)
}
val errMsg = exception.getMessage
assert(errMsg.contains("Malformed records are detected in record parsing"))
val fileName = "test-data/utf16LE.json"
val schema = new StructType().add("firstName", StringType).add("lastName", StringType)
val exception = intercept[SparkException] {
spark.read.schema(schema)
.option("mode", "FAILFAST")
.option("multiline", "true")
.options(Map("encoding" -> "UTF-16BE"))
.json(testFile(fileName))
.count()
}
val errMsg = exception.getMessage

assert(doCount(bypassParser = true, multiLine = false) == 5)
assert(errMsg.contains("Malformed records are detected in record parsing"))
}

def checkEncoding(expectedEncoding: String, pathToJsonFiles: String,
Expand Down

0 comments on commit 2d8e754

Please sign in to comment.