spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wojtek-szymanski <...@git.apache.org>
Subject [GitHub] spark pull request #17068: [SPARK-19709][SQL] Read empty file with CSV data ...
Date Mon, 06 Mar 2017 21:31:28 GMT
Github user wojtek-szymanski commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17068#discussion_r104527927
  
    --- 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 --
    
    @HyukjinKwon @cloud-fan many thanks for your effort. I really appreciate it and I will
take it into account when working with the codebase.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message