Skip to content

Commit 918d163

Browse files
committed
Restrict lineSep by 1 character only
1 parent 1f5399f commit 918d163

File tree

2 files changed

+10
-15
lines changed
  • sql
    • catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv
    • core/src/test/scala/org/apache/spark/sql/execution/datasources/csv

2 files changed

+10
-15
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVOptions.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class CSVOptions(
197197
*/
198198
val lineSeparator: Option[String] = parameters.get("lineSep").map { sep =>
199199
require(sep.nonEmpty, "'lineSep' cannot be an empty string.")
200-
require(sep.length <= 2, "'lineSep' can contain 1 or 2 characters.")
200+
require(sep.length == 1, "'lineSep' can contain only 1 character.")
201201
sep
202202
}
203203

@@ -232,10 +232,7 @@ class CSVOptions(
232232
format.setDelimiter(delimiter)
233233
format.setQuote(quote)
234234
format.setQuoteEscape(escape)
235-
lineSeparator.foreach {sep =>
236-
format.setLineSeparator(sep)
237-
format.setNormalizedNewline(0x00.toChar)
238-
}
235+
lineSeparator.foreach(format.setLineSeparator)
239236
charToEscapeQuoteEscaping.foreach(format.setCharToEscapeQuoteEscaping)
240237
format.setComment(comment)
241238

sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,17 +1961,15 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils with Te
19611961
List(
19621962
(0, "|", "UTF-8", false),
19631963
(1, "^", "UTF-16BE", true),
1964-
(2, "::", "ISO-8859-1", true),
1965-
(3, "!!", "UTF-32LE", false),
1964+
(2, ":", "ISO-8859-1", true),
1965+
(3, "!", "UTF-32LE", false),
19661966
(4, 0x1E.toChar.toString, "UTF-8", true),
19671967
(5, "", "UTF-32BE", false),
1968-
(6, "ку", "CP1251", true),
1969-
(8, "\r\n", "UTF-16LE", true),
1970-
(9, "\r\n", "utf-16be", false),
1971-
(10, "\u000d\u000a", "UTF-32BE", false),
1972-
(11, "\u000a\u000d", "UTF-8", true),
1973-
(12, "==", "US-ASCII", false),
1974-
(13, "$^", "utf-32le", true)
1968+
(6, "у", "CP1251", true),
1969+
(8, "\r", "UTF-16LE", true),
1970+
(9, "\u000d", "UTF-32BE", false),
1971+
(10, "=", "US-ASCII", false),
1972+
(11, "$", "utf-32le", true)
19751973
).foreach { case (testNum, sep, encoding, inferSchema) =>
19761974
testLineSeparator(sep, encoding, inferSchema, testNum)
19771975
}
@@ -1986,6 +1984,6 @@ class CSVSuite extends QueryTest with SharedSQLContext with SQLTestUtils with Te
19861984
val errMsg2 = intercept[IllegalArgumentException] {
19871985
spark.read.option("lineSep", "123").csv(testFile(carsFile)).collect
19881986
}.getMessage
1989-
assert(errMsg2.contains("'lineSep' can contain 1 or 2 characters"))
1987+
assert(errMsg2.contains("'lineSep' can contain only 1 character"))
19901988
}
19911989
}

0 commit comments

Comments
 (0)