You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/06/22 20:33:51 UTC

[GitHub] [spark] planga82 opened a new pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

planga82 opened a new pull request #28896:
URL: https://github.com/apache/spark/pull/28896


   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
     2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
     4. Be sure to keep the PR description updated to reflect all changes.
     5. Please write your PR title to summarize what this PR proposes.
     6. If possible, provide a concise example to reproduce the issue for a faster review.
     7. If you want to add a new configuration, please read the guideline first for naming configurations in
        'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
   -->
   
   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   This pull request fixes a bug present in the csv type inference.
   We have problems when we have different types in the same column.
   
   **Previously:** 
   ```
   $ cat /example/f1.csv
   col1
   43200000
   true
   
   spark.read.csv(path="file:///example/*.csv", header=True, inferSchema=True).show()
   +----+
   |col1|
   +----+
   |null|
   |true|
   +----+
   
   root
    |-- col1: boolean (nullable = true)
   ```
   **Now**
   ```
   spark.read.csv(path="file:///example/*.csv", header=True, inferSchema=True).show()
   +-------------+
   |col1          |
   +-------------+
   |43200000 |
   |true           |
   +-------------+
   
   root                                                                            
    |-- col1: string (nullable = true)
   ```
   
   
   Now the hierarchy of type inference is the following:
   
   > IntegerType
   > > LongType
   > > > DecimalType
   > > > > DoubleType
   > > > > > TimestampType
   > > > > > > BooleanType
   > > > > > > > StringType
   
   
   So, when, for example, we have integers in one column, and the last element is a boolean, all the column is inferred as a boolean column incorrectly and all the number are shown as null when you see the data
   
   We need the following hierarchy. When we have different numeric types in the column it will be resolved correctly. And when we have other different types it will be resolved as a String type column
   > IntegerType
   > > LongType
   > > > DecimalType
   > > > >DoubleType
   
   > TimestampType
   > BooleanType
   > StringType
   
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Fix the bug explained
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   -->
   Unit test and manual tests


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649286405






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649593530






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444670381



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/csv/CSVSuite.scala
##########
@@ -2341,6 +2342,17 @@ abstract class CSVSuite extends QueryTest with SharedSparkSession with TestCsvDa
       checkAnswer(csv, Row(null))
     }
   }
+
+  test("Test mixed types") {

Review comment:
       nit: `SPARK-32025: infer the schema from mixed-type values`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649442951


   **[Test build #124512 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/124512/testReport)** for PR 28896 at commit [`4629bb5`](https://github.com/apache/spark/commit/4629bb5556564b2ebcedca88157f45aa95982f00).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444833442



##########
File path: sql/core/src/test/resources/test-data/mixed-types1.csv
##########
@@ -0,0 +1,4 @@
+col_mixed_types
+2012
+1997
+True

Review comment:
       Let's don't bother to create new data file here. You write the test codes as below instead.
   
   ```scala
   withTempPath { path =>
     Seq("col_mixed_types", "2012", "1997", "True").toDS.write.text(path.getCanonicalPath)
     val df = spark.read.format("csv")
       .option("header", "true")
       .option("inferSchema", "true")
       .load(path.getCanonicalPath)
   
     assert(data.schema.last == StructField("col_mixed_types", StringType, true))
   }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647758404


   Can one of the admins verify this patch?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649286424


   Test FAILed.
   Refer to this link for build results (access rights to CI server needed): 
   https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/124510/
   Test FAILed.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-648408488


   I have done some performance tests in my local machine
   - File: 999999999 lines integers / 10 GB 
   - Resources: 4 Cores
   
   Result without changes:
   - 21m10,114s
   - 20m18,626s
   - 19m46,158s
   
   Results after changes
   - 19m46,388s
   - 22m10,784s
   - 21m15,937s
   
   It seems that we don't have a very significant impact but the tests in local are not the best way to be sure
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647757877


   Can one of the admins verify this patch?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649302913


   retest this please


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649215558


   **[Test build #124510 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/124510/testReport)** for PR 28896 at commit [`4629bb5`](https://github.com/apache/spark/commit/4629bb5556564b2ebcedca88157f45aa95982f00).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649442539


   retest this please


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647905243


   Does JSON source have the same problem?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647758404


   Can one of the admins verify this patch?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r443900894



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVInferSchema.scala
##########
@@ -103,7 +103,16 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
       typeSoFar
     } else {
       typeSoFar match {
-        case NullType => tryParseInteger(field)
+        case NullType =>
+          tryParseInteger(field) match {

Review comment:
       But the problem is that that's going to degrade the performance, and single partition case is arguably rare. Let's make sure we don't have the performance penalty in general cases.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649285517


   **[Test build #124510 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/124510/testReport)** for PR 28896 at commit [`4629bb5`](https://github.com/apache/spark/commit/4629bb5556564b2ebcedca88157f45aa95982f00).
    * This patch **fails due to an unknown error code, -9**.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon closed pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #28896:
URL: https://github.com/apache/spark/pull/28896


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] huaxingao commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
huaxingao commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-655580604


   @gatorsmile I will take a look. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-655595401


   Thanks @huaxingao  If you can't do it for any reason tell me.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647775764


   @MaxGekk Yes, the last type in inference is StringType in all inference chains. I have change the description to show it better.
   The principal difference is than now we have different chains instead of one


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649215908






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 edited a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 edited a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647775764


   @MaxGekk Yes, the last type in inference is StringType in all inference chains. I have changed the description to show it better.
   The principal difference is than now we have different chains instead of one


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649901085


   Merged to master.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] gatorsmile commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
gatorsmile commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-655310637


   Is that possible we can document the type inference rule? something like the traditional database like https://www.ibm.com/support/knowledgecenter/SSEPGG_10.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0008477.html
   
   cc @huaxingao @planga82 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444715867



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVInferSchema.scala
##########
@@ -82,7 +82,8 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
   def inferRowType(rowSoFar: Array[DataType], next: Array[String]): Array[DataType] = {
     var i = 0
     while (i < math.min(rowSoFar.length, next.length)) {  // May have columns on right missing.
-      rowSoFar(i) = inferField(rowSoFar(i), next(i))
+      val typeElemInfer = inferField(rowSoFar(i), next(i))
+      rowSoFar(i) = compatibleType(rowSoFar(i), typeElemInfer).getOrElse(StringType)

Review comment:
       Ok it's more intuitive and inferField is only used here and in the tests




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] SparkQA removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649442951


   **[Test build #124512 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/124512/testReport)** for PR 28896 at commit [`4629bb5`](https://github.com/apache/spark/commit/4629bb5556564b2ebcedca88157f45aa95982f00).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647759812


   CC @HyukjinKwon @cloud-fan @MaxGekk 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] SparkQA commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
SparkQA commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649592156


   **[Test build #124512 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/124512/testReport)** for PR 28896 at commit [`4629bb5`](https://github.com/apache/spark/commit/4629bb5556564b2ebcedca88157f45aa95982f00).
    * This patch passes all tests.
    * This patch merges cleanly.
    * This patch adds no public classes.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] SparkQA removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
SparkQA removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649215558


   **[Test build #124510 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/124510/testReport)** for PR 28896 at commit [`4629bb5`](https://github.com/apache/spark/commit/4629bb5556564b2ebcedca88157f45aa95982f00).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444950936



##########
File path: sql/core/src/test/resources/test-data/mixed-types1.csv
##########
@@ -0,0 +1,4 @@
+col_mixed_types
+2012
+1997
+True

Review comment:
       Ok, It's more clear to see the data in the test.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 edited a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 edited a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647775764


   @MaxGekk Yes, the last type in inference is StringType in all inference chains. I have changed the description to show it better.
   The principal difference is that now we have different chains instead of one


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649286405


   Merged build finished. Test FAILed.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649214971


   retest this please


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r443900676



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVInferSchema.scala
##########
@@ -103,7 +103,16 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
       typeSoFar
     } else {
       typeSoFar match {
-        case NullType => tryParseInteger(field)
+        case NullType =>
+          tryParseInteger(field) match {

Review comment:
       Let's don't have a separate rule alone here. The problem here seems like when the type is inferred from single partition alone, and the compatible types are not respected. You might have to call `compatibleType` from my cursory look.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] planga82 commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
planga82 commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-648255662


   @HyukjinKwon It's exactly what you say, it only happens when the incompatibility is inside one partition. I will change the PR to use compatibleType, and I will make some performance test. Thanks for your help!
   
   @cloud-fan I tested the same situation with json and it works fine, we don't have problems there


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649443555






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649214971


   retest this please


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-647757877


   Can one of the admins verify this patch?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649215908






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649593530






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649215341


   ok to test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444830652



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVInferSchema.scala
##########
@@ -102,7 +102,7 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
     if (field == null || field.isEmpty || field == options.nullValue) {
       typeSoFar
     } else {
-      typeSoFar match {
+      val typeElemInfer = typeSoFar match {
         case NullType => tryParseInteger(field)
         case IntegerType => tryParseInteger(field)
         case LongType => tryParseLong(field)

Review comment:
       Seems like now you can just do `tryParseDecimal(field)` alone at decimal case below.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] cloud-fan commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
cloud-fan commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444670101



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/csv/CSVInferSchema.scala
##########
@@ -82,7 +82,8 @@ class CSVInferSchema(val options: CSVOptions) extends Serializable {
   def inferRowType(rowSoFar: Array[DataType], next: Array[String]): Array[DataType] = {
     var i = 0
     while (i < math.min(rowSoFar.length, next.length)) {  // May have columns on right missing.
-      rowSoFar(i) = inferField(rowSoFar(i), next(i))
+      val typeElemInfer = inferField(rowSoFar(i), next(i))
+      rowSoFar(i) = compatibleType(rowSoFar(i), typeElemInfer).getOrElse(StringType)

Review comment:
       shall we do this inside `inferField`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] HyukjinKwon commented on a change in pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on a change in pull request #28896:
URL: https://github.com/apache/spark/pull/28896#discussion_r444833442



##########
File path: sql/core/src/test/resources/test-data/mixed-types1.csv
##########
@@ -0,0 +1,4 @@
+col_mixed_types
+2012
+1997
+True

Review comment:
       Let's don't bother to create new data file here. You can write the test codes as below instead.
   
   ```scala
   withTempPath { path =>
     Seq("col_mixed_types", "2012", "1997", "True").toDS.write.text(path.getCanonicalPath)
     val df = spark.read.format("csv")
       .option("header", "true")
       .option("inferSchema", "true")
       .load(path.getCanonicalPath)
   
     assert(data.schema.last == StructField("col_mixed_types", StringType, true))
   }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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


[GitHub] [spark] AmplabJenkins removed a comment on pull request #28896: [SPARK-32025][SQL] Csv schema inference problems with different types in the same column

Posted by GitBox <gi...@apache.org>.
AmplabJenkins removed a comment on pull request #28896:
URL: https://github.com/apache/spark/pull/28896#issuecomment-649443555






----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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