Github user wojtek-szymanski commented on a diff in the pull request:
https://github.com/apache/spark/pull/17068#discussion_r104317488
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/CSVDataSource.scala
---
@@ -133,8 +133,19 @@ object TextInputCSVDataSource extends CSVDataSource {
sparkSession: SparkSession,
inputPaths: Seq[FileStatus],
parsedOptions: CSVOptions): Option[StructType] = {
- val csv: Dataset[String] = createBaseDataset(sparkSession, inputPaths,
parsedOptions)
- val firstLine: String = CSVUtils.filterCommentAndEmpty(csv,
parsedOptions).first()
+ val csv = createBaseDataset(sparkSession, inputPaths, parsedOptions)
+ CSVUtils.filterCommentAndEmpty(csv, parsedOptions)
+ .take(1)
+ .headOption
+ .map(firstLine => infer(sparkSession, parsedOptions, csv, firstLine))
+ .orElse(Some(StructType(Seq())))
--- End diff --
I would suggest that we use pattern matching in order to make it more
verbose and avoid code like this:
if (maybeFirstRow.isDefined) {
val firstRow = maybeFirstRow.get
I also touched `WholeFileCSVDataSource` to unify both implementations.
What's your opinion?
Regarding code de-duplication, I fully agree, that it should be done in
separate PR.
---
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]