Mister-Meeseeks commented on a change in pull request #23830: 
[SPARK-26935][SQL]Skip DataFrameReader's CSV first line scan when not used
URL: https://github.com/apache/spark/pull/23830#discussion_r259209415
 
 

 ##########
 File path: sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
 ##########
 @@ -508,7 +508,17 @@ 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
+
+    // For performance, short-circuit the collection of the first line when it 
won't be used:
+    //   - TextInputCSVDataSource - Only uses firstLine to infer an 
unspecified schema
+    //   - CSVHeaderChecker       - Only uses firstLine to check header, when 
headerFlag is true
+    //   - CSVUtils               - Only uses firstLine to filter headers, 
when headerFlag is true
 
 Review comment:
   Yes, good idea. Just expanded the inline comment to cover this. Hope it 
adequately conveys the point. Let me know if you have any suggestions or prefer 
different phrasing. 

----------------------------------------------------------------
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]

Reply via email to