Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16854#discussion_r103894945
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/UnivocityParser.scala
 ---
    @@ -344,4 +346,36 @@ private[csv] object UnivocityParser {
           CSVUtils.filterCommentAndEmpty(linesWithoutHeader, options)
         filteredLines.flatMap(line => parser.parse(line))
       }
    +
    +  /**
    +   * Parses a `Dataset` that contains CSV strings and turns it into an 
`RDD` of rows.
    +   */
    +  def tokenizeDataset(
    +      csvDataset: Dataset[String],
    +      maybeFirstLine: Option[String],
    +      options: CSVOptions): RDD[Array[String]] = {
    +    val filtered = CSVUtils.filterCommentAndEmpty(csvDataset, options)
    +    val linesWithoutHeader = maybeFirstLine.map { firstLine =>
    +      filtered.rdd.mapPartitions(CSVUtils.filterHeaderLine(_, firstLine, 
options))
    +    }.getOrElse(filtered.rdd)
    +
    +    linesWithoutHeader.mapPartitions { iter =>
    +      val parser = new CsvParser(options.asParserSettings)
    +      iter.map(line => parser.parseLine(line))
    +    }
    +  }
    +
    +  /**
    +   * Parses a `Dataset` that contains CSV strings and turns it into an 
`RDD` of rows.
    +   */
    +  def parseDataset(
    +      csvDataset: Dataset[String],
    +      schema: StructType,
    +      maybeFirstLine: Option[String],
    +      options: CSVOptions): RDD[InternalRow] = {
    +    tokenizeDataset(csvDataset, maybeFirstLine, options).mapPartitions { 
iter =>
    +      val parser = new UnivocityParser(schema, options)
    +      iter.flatMap(line => parser.convert(line))
    +    }
    +  }
    --- End diff --
    
    cc @cloud-fan, this is still a wip but I am trying to put the different 
execution paths into here in CSV parsing.
    
    For example,
    
      - `spark.read.csv(file)`
        - data: `parseIterator` (note that this one is read from partitioned 
file).
        - schema: `tokenizeDataset `
    
    
      - `spark.read.csv(file)` with `wholeFile`
        - data: `parseStream`
        - schema: `tokenizeStream `
    
      - `spark.read.csv(dataset)`
        - data: `parseDataset `
        - schema: `tokenizeDataset `
    
    
    However, it seems ending up with a bit weird arguments here.. do you think 
it is okay? 


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

Reply via email to