Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciferYang committed Nov 27, 2020
1 parent 1770c56 commit ca79a48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ abstract class CSVSuite
private val valueMalformedFile = "test-data/value-malformed.csv"
private val badAfterGoodFile = "test-data/bad_after_good.csv"
private val malformedRowFile = "test-data/malformedRow.csv"
private val unescapedQuotesAndUnescapedDelimiterFile =
"test-data/unescaped-quotes-unescaped-delimiter.csv"

/** Verifies data and schema. */
private def verifyCars(
Expand Down Expand Up @@ -2432,16 +2430,27 @@ abstract class CSVSuite
}

test("SPARK-33566: configure UnescapedQuoteHandling to parse " +
"unescapedQuotesAndUnescapedDelimiterFile correctly") {
// Without configure UnescapedQuoteHandling to STOP_AT_CLOSING_QUOTE,
// the result will be Row(""""a,""b""", """c""""), Row("""a,b,c""", """"x""yz"""")
val result = spark.read
.option("inferSchema", "true")
.option("header", "true")
.option("unescapedQuoteHandling", "STOP_AT_CLOSING_QUOTE")
.csv(testFile(unescapedQuotesAndUnescapedDelimiterFile)).collect()
val exceptResults = Array(Row("""a,""b,c""", "xyz"), Row("""a,b,c""", """x""yz"""))
assert(result.sameElements(exceptResults))
"unescaped quotes and unescaped delimiter data correctly") {
withTempPath { path =>
val dataPath = path.getCanonicalPath
val row1 = Row("""a,""b,c""", "xyz")
val row2 = Row("""a,b,c""", """x""yz""")
// Generate the test data, use `,` as delimiter and `"` as quotes, but they didn't escape.
Seq(
"""c1,c2""",
s""""${row1.getString(0)}","${row1.getString(1)}"""",
s""""${row2.getString(0)}","${row2.getString(1)}"""")
.toDF().repartition(1).write.text(dataPath)
// Without configure UnescapedQuoteHandling to STOP_AT_CLOSING_QUOTE,
// the result will be Row(""""a,""b""", """c""""), Row("""a,b,c""", """"x""yz"""")
val result = spark.read
.option("inferSchema", "true")
.option("header", "true")
.option("unescapedQuoteHandling", "STOP_AT_CLOSING_QUOTE")
.csv(dataPath).collect()
val exceptResults = Array(row1, row2)
assert(result.sameElements(exceptResults))
}
}
}

Expand Down

0 comments on commit ca79a48

Please sign in to comment.