Github user HyukjinKwon commented on a diff in the pull request: https://github.com/apache/spark/pull/16854#discussion_r103895193 --- 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 -- If you are not sure or it looks painful to review, let me take out all the changes and put those into `DataFrameReader.csv` for now.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org