{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/16320","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/16320/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/16320/comments","events_url":"https://api.github.com/repos/apache/spark/issues/16320/events","html_url":"https://github.com/apache/spark/pull/16320","id":196169352,"number":16320,"title":"[SPARK-18877][SQL] `CSVInferSchema.inferField` on DecimalType should find a common type with `typeSoFar`","user":{"login":"dongjoon-hyun","id":9700541,"avatar_url":"https://avatars.githubusercontent.com/u/9700541?v=3","gravatar_id":"","url":"https://api.github.com/users/dongjoon-hyun","html_url":"https://github.com/dongjoon-hyun","followers_url":"https://api.github.com/users/dongjoon-hyun/followers","following_url":"https://api.github.com/users/dongjoon-hyun/following{/other_user}","gists_url":"https://api.github.com/users/dongjoon-hyun/gists{/gist_id}","starred_url":"https://api.github.com/users/dongjoon-hyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongjoon-hyun/subscriptions","organizations_url":"https://api.github.com/users/dongjoon-hyun/orgs","repos_url":"https://api.github.com/users/dongjoon-hyun/repos","events_url":"https://api.github.com/users/dongjoon-hyun/events{/privacy}","received_events_url":"https://api.github.com/users/dongjoon-hyun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-12-16T22:34:58Z","updated_at":"2016-12-26T02:37:36Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/16320","html_url":"https://github.com/apache/spark/pull/16320","diff_url":"https://github.com/apache/spark/pull/16320.diff","patch_url":"https://github.com/apache/spark/pull/16320.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nCSV type inferencing causes `IllegalArgumentException` on decimal numbers with heterogeneous precisions and scales because the current logic uses the last decimal type in a **partition**. Specifically, `inferRowType`, the **seqOp** of **aggregate**, returns the last decimal type. This PR fixes it to use `findTightestCommonType`.\r\n\r\n**decimal.csv**\r\n```\r\n9.03E+12\r\n1.19E+11\r\n```\r\n\r\n**BEFORE**\r\n```scala\r\nscala> spark.read.format(\"csv\").option(\"inferSchema\", true).load(\"decimal.csv\").printSchema\r\nroot\r\n |-- _c0: decimal(3,-9) (nullable = true)\r\n\r\nscala> spark.read.format(\"csv\").option(\"inferSchema\", true).load(\"decimal.csv\").show\r\n16/12/16 14:32:49 ERROR Executor: Exception in task 0.0 in stage 4.0 (TID 4)\r\njava.lang.IllegalArgumentException: requirement failed: Decimal precision 4 exceeds max precision 3\r\n```\r\n\r\n**AFTER**\r\n```scala\r\nscala> spark.read.format(\"csv\").option(\"inferSchema\", true).load(\"decimal.csv\").printSchema\r\nroot\r\n |-- _c0: decimal(4,-9) (nullable = true)\r\n\r\nscala> spark.read.format(\"csv\").option(\"inferSchema\", true).load(\"decimal.csv\").show\r\n+---------+\r\n|      _c0|\r\n+---------+\r\n|9.030E+12|\r\n| 1.19E+11|\r\n+---------+\r\n```\r\n\r\n\r\n## How was this patch tested?\r\n\r\nPass the newly add test case."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/269150692","html_url":"https://github.com/apache/spark/pull/16320#issuecomment-269150692","issue_url":"https://api.github.com/repos/apache/spark/issues/16320","id":269150692,"user":{"login":"SparkQA","id":8108735,"avatar_url":"https://avatars.githubusercontent.com/u/8108735?v=3","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2016-12-26T02:37:36Z","updated_at":"2016-12-26T02:37:36Z","body":"**[Test build #70576 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/70576/testReport)** for PR 16320 at commit [`308de12`](https://github.com/apache/spark/commit/308de12950599a6900766a76a0ea39ac72aba59f)."}}
{"actor":{"display_login":"SparkQA"}}