Uh oh!
There was an error while loading. Please reload this page.
[SPARK-16101][SQL] Refactoring CSV data source to be consistent with JSON data source - #13988
[SPARK-16101][SQL] Refactoring CSV data source to be consistent with JSON data source#13988HyukjinKwon wants to merge 6 commits into
Conversation
I still need to correct some nits and check the consistency with JSON data source but I opened this just to check if it breaks anything. I will submit some more commits soon. (and will also update the PR description to be in more details maybe). |
SparkQA
commented
Jun 30, 2016
Test build #61523 has finished for PR 13988 at commit
|
Hi @rxin, I think the change in this PR might be still pretty big. Should I maybe make this separate into two PRs for both reading and writing parts? |
SparkQA
commented
Jul 1, 2016
Test build #61587 has finished for PR 13988 at commit
|
SparkQA
commented
Jul 1, 2016
Test build #61588 has finished for PR 13988 at commit
|
HyukjinKwon
commented
Jul 7, 2016
(@rxin gentle ping..) |
SparkQA
commented
Jul 9, 2016
Test build #62011 has finished for PR 13988 at commit
|
SparkQA
commented
Jul 9, 2016
Test build #62014 has finished for PR 13988 at commit
|
HyukjinKwon
commented
Jul 9, 2016
retest this please |
HyukjinKwon
commented
Jul 9, 2016
I updated the PR description. I hope this is helpful for reviewing. |
SparkQA
commented
Jul 9, 2016
Test build #62015 has finished for PR 13988 at commit
|
SparkQA
commented
Jul 9, 2016
Test build #62016 has finished for PR 13988 at commit
|
There was a problem hiding this comment.
@HyukjinKwon we ran in to this issue where csv writes ints for DateType instead of date string. (https://issues.apache.org/jira/browse/SPARK-16597)
There was a problem hiding this comment.
Actually, I opened another PR here, #13912. Maybe it is about that PR.
There was a problem hiding this comment.
ah thanks, commented on that PR. Glad to see someone showing some love to Spark's csv datasource!
HyukjinKwon
commented
Jul 27, 2016
@rxin Could you take a look please? |
SparkQA
commented
Aug 9, 2016
Test build #63425 has finished for PR 13988 at commit
|
SparkQA
commented
Aug 10, 2016
Test build #63482 has finished for PR 13988 at commit
|
SparkQA
commented
Aug 23, 2016
Test build #64254 has finished for PR 13988 at commit
|
SparkQA
commented
Aug 30, 2016
Test build #64635 has finished for PR 13988 at commit
|
HyukjinKwon
commented
Sep 10, 2016
cc @hvanhovell Do you mind if I ask to review this please? I remember the initial proposal was reviewed by you. If this seems too big to review, I can split this into reading path and writing path. |
HyukjinKwon
commented
Sep 10, 2016
This is also loosely related with https://issues.apache.org/jira/browse/SPARK-15463. After this one is merged, we could resemble the implementation of JSON one easily rather then introducing another refactoring. |
SparkQA
commented
Sep 21, 2016
Test build #65716 has finished for PR 13988 at commit
|
a6d85b6 to
ac94e67CompareSparkQA
commented
Sep 28, 2016
Test build #66037 has finished for PR 13988 at commit
|
SparkQA
commented
Sep 28, 2016
Test build #66035 has finished for PR 13988 at commit
|
SparkQA
commented
Sep 28, 2016
Test build #66038 has finished for PR 13988 at commit
|
HyukjinKwon
commented
Oct 8, 2016
@hvanhovell If this change looks too big, I will split this into reading path and writing path if you confirm please. |
SparkQA
commented
Oct 14, 2016
Test build #66939 has finished for PR 13988 at commit
|
SparkQA
commented
Oct 14, 2016
Test build #66936 has finished for PR 13988 at commit
|
SparkQA
commented
Oct 22, 2016
Test build #67391 has finished for PR 13988 at commit
|
HyukjinKwon
commented
Nov 28, 2016
I will try to split this into two PRs for read path and write path. Would that sound okay to you both @rxin and @hvanhovell? |
| schema.foreach(field => verifyType(field.dataType)) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
These below just came from CSVRelation.
| @@ -39,22 +38,43 @@ private[csv] object CSVInferSchema { | |||
| * 3. Replace any null types with string type | |||
| */ | |||
| def infer( | |||
There was a problem hiding this comment.
This argument change is kind of a important change to introduce similar functionalities with JSON. (e,g., creating a dataframe from RDD[String] or Dataset[String]).
| case datum => | ||
| Try(datum.toDouble) | ||
| .getOrElse(NumberFormat.getInstance(Locale.US).parse(datum).doubleValue()) | ||
| private def makeSafeHeader( |
There was a problem hiding this comment.
This just came from CSVFileFormat.
| val isCommentSet = this.comment != '\u0000' | ||
| def asWriterSettings: CsvWriterSettings = { |
There was a problem hiding this comment.
These just came from CSVParser.
| writerSettings.setHeaders(schema.fieldNames: _*) | ||
| private val gen = new CsvWriter(writer, writerSettings) | ||
| // A `ValueConverter` is responsible for converting a value of an `InternalRow` to `String`. |
There was a problem hiding this comment.
These below just mostly came from CSVRelation.
| private type ValueConverter = String => Any | ||
| var numMalformedRecords = 0 | ||
| val row = new GenericInternalRow(requiredSchema.length) |
There was a problem hiding this comment.
Now, we reuse the single row.
There was a problem hiding this comment.
Also, it separates numMalformedRecords when it calls parse (...) which looked weird before.
| * each element represents a column) and turns it into either one resulting row or no row (if the | ||
| * the record is malformed). | ||
| */ | ||
| def parse(input: String): Option[InternalRow] = { |
There was a problem hiding this comment.
Here, I separate the parsing mode logics (withParseMode) and actual converting logics (parse).
There was a problem hiding this comment.
Also, the argument change (matching it up to JacksonParser) is also important. We could avoid additional refactoring when introducing the same funtionalities with JacksonParser, (e.g., loading it from RDD[String] or Dataset[String], from_json and to_json functions).
There was a problem hiding this comment.
For example, PR - 13300 introduces such refactoring.
SparkQA
commented
Jan 5, 2017
Test build #70917 has finished for PR 13988 at commit
|
SparkQA
commented
Jan 5, 2017
Test build #70919 has finished for PR 13988 at commit
|
SparkQA
commented
Jan 5, 2017
Test build #70920 has finished for PR 13988 at commit
|
SparkQA
commented
Jan 5, 2017
Test build #70923 has finished for PR 13988 at commit
|
HyukjinKwon
commented
Jan 6, 2017
Hi @cloud-fan, do you mind if I ask to check whether it looks making sense? |
| options: CSVOptions) extends Logging { | ||
| def this(schema: StructType, options: CSVOptions) = this(schema, schema, options) | ||
| val valueConverters = makeConverters(schema, options) |
There was a problem hiding this comment.
Some changes about converting here came from CSVTypeCast.
cloud-fan
commented
Jan 6, 2017
can you split this into smaller PRs? it's really painful to review such a big refactor-only PR. |
HyukjinKwon
commented
Jan 6, 2017
Sure! Let me split this into reading and writing ones. Thank you for yout comments. Let me close this for now. |
What changes were proposed in this pull request?
This PR refactors CSV data source to be consistent with JSON data source.
This PR removes classes
CSVParserand introduces new classesUnivocityParserandUnivocityGeneratorto be consistent with JSON data source (JacksonParser,JacksonGenerator). Also,CSVRelationis merged withCSVFileFormatjust likeJsonFileFormat.This is a rough look of this change:
CSVOptions- reading/writing settings that can be created from options fromCsvParser.UnivocityGenerator- writing logics fromCSVRelationandCsvParserUnivocityParser- parsing logics inCSVTypeCast,CsvParserandCSVRelationCSVFileFormat-CSVOutputWriterFactoryandCsvOutputWriterinCSVRelationThis PR makes the methods in classes have consistent arguments with JSON ones.
UnivocityGeneratorandJacksonGeneratorUnivocityParserresemblesJacksonParser.csv.CSVInferSchemaandjson.InferSchemaThis PR also makes the classes put in together in a consistent manner with JSON.
CsvFileFormatJsonFileFormatAlso, this re-write existing CSV parsing logics to re-use the row, separate parsing mode logic/convering logics and etc.
How was this patch tested?
Existing tests should cover this.