Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/17068#discussion_r104356921
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVDataSource.scala
---
@@ -190,28 +194,28 @@ object WholeFileCSVDataSource extends CSVDataSource {
sparkSession: SparkSession,
inputPaths: Seq[FileStatus],
parsedOptions: CSVOptions): Option[StructType] = {
- val csv: RDD[PortableDataStream] = createBaseRdd(sparkSession,
inputPaths, parsedOptions)
- val maybeFirstRow: Option[Array[String]] = csv.flatMap { lines =>
+ val csv = createBaseRdd(sparkSession, inputPaths, parsedOptions)
+ csv.flatMap { lines =>
UnivocityParser.tokenizeStream(
CodecStreams.createInputStreamWithCloseResource(lines.getConfiguration,
lines.getPath()),
- false,
+ shouldDropHeader = false,
new CsvParser(parsedOptions.asParserSettings))
- }.take(1).headOption
-
- if (maybeFirstRow.isDefined) {
- val firstRow = maybeFirstRow.get
- val caseSensitive =
sparkSession.sessionState.conf.caseSensitiveAnalysis
- val header = makeSafeHeader(firstRow, caseSensitive, parsedOptions)
- val tokenRDD = csv.flatMap { lines =>
- UnivocityParser.tokenizeStream(
-
CodecStreams.createInputStreamWithCloseResource(lines.getConfiguration,
lines.getPath()),
- parsedOptions.headerFlag,
- new CsvParser(parsedOptions.asParserSettings))
- }
- Some(CSVInferSchema.infer(tokenRDD, header, parsedOptions))
- } else {
- // If the first row could not be read, just return the empty schema.
- Some(StructType(Nil))
+ }.take(1).headOption match {
--- End diff --
All three patterns I mentioned are being used across the code base. There
is no style guide for this both in
https://github.com/databricks/scala-style-guide and
http://spark.apache.org/contributing.html
In this case, matching new one to other similar ones is a better choice to
reduce changed lines, rather than doing the opposite. Personal taste might be
secondary.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]