srowen commented on a change in pull request #23830: Decrease processing
overhead on DataFrameReader CSV calls with specif…
URL: https://github.com/apache/spark/pull/23830#discussion_r258163361
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
##########
@@ -508,7 +508,14 @@ class DataFrameReader private[sql](sparkSession:
SparkSession) extends Logging {
sparkSession.sessionState.conf.sessionLocalTimeZone)
val filteredLines: Dataset[String] =
CSVUtils.filterCommentAndEmpty(csvDataset, parsedOptions)
- val maybeFirstLine: Option[String] = filteredLines.take(1).headOption
+ val needsFirstLine: Boolean =
+ userSpecifiedSchema.isEmpty || parsedOptions.headerFlag
+ val maybeFirstLine: Option[String] =
+ if (needsFirstLine) {
+ filteredLines.take(1).headOption
Review comment:
The indentation of this is still off. The title on the PR still needs to be
updated, with a JIRA. Please see my other comment. You can probably inline
`needsFirstLine` too to keep it simpler.
Otherwise I think this is pretty OK, AFAIK, the first line is never needed
unless it's a header or needed for schema inference.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]