{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/190146438","pull_request_review_id":122460825,"id":190146438,"diff_hunk":"@@ -248,28 +248,32 @@ private[csv] object UnivocityParser {\n    */\n   def parseStream(\n       inputStream: InputStream,\n-      shouldDropHeader: Boolean,\n+      dropFirstRecord: Boolean,\n       parser: UnivocityParser,\n-      schema: StructType): Iterator[InternalRow] = {\n+      schema: StructType,\n+      checkFirstRecord: Array[String] => Unit): Iterator[InternalRow] = {\n     val tokenizer = parser.tokenizer\n     val safeParser = new FailureSafeParser[Array[String]](\n       input => Seq(parser.convert(input)),\n       parser.options.parseMode,\n       schema,\n       parser.options.columnNameOfCorruptRecord)\n-    convertStream(inputStream, shouldDropHeader, tokenizer) { tokens =>\n+    convertStream(inputStream, dropFirstRecord, tokenizer, checkFirstRecord) { tokens =>\n       safeParser.parse(tokens)\n     }.flatten\n   }\n \n   private def convertStream[T](\n       inputStream: InputStream,\n-      shouldDropHeader: Boolean,","path":"sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/csv/UnivocityParser.scala","position":33,"original_position":33,"commit_id":"7dce1e72f080044ba471fa08bb572452d4b0c907","original_commit_id":"7dce1e72f080044ba471fa08bb572452d4b0c907","user":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"body":"To show what exactly the parameter controls - dropping the first record in the stream. Responsibility for header manipulation belongs to higher level - `CSVDataSource`, `UnivocityParser` doesn't know about `header` at least for now. Do you believe it should be renamed back?","created_at":"2018-05-23T07:27:56Z","updated_at":"2018-05-23T07:27:57Z","html_url":"https://github.com/apache/spark/pull/20894#discussion_r190146438","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/20894","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/190146438"},"html":{"href":"https://github.com/apache/spark/pull/20894#discussion_r190146438"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/20894"}},"in_reply_to_id":190137382},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/20894","id":177185830,"html_url":"https://github.com/apache/spark/pull/20894","diff_url":"https://github.com/apache/spark/pull/20894.diff","patch_url":"https://github.com/apache/spark/pull/20894.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/20894","number":20894,"state":"open","locked":false,"title":"[SPARK-23786][SQL] Checking column names of csv headers","user":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nCurrently column names of headers in CSV files are not checked against provided schema of CSV data. It could cause errors like showed in the [SPARK-23786](https://issues.apache.org/jira/browse/SPARK-23786) and https://github.com/apache/spark/pull/20894#issuecomment-375957777. I introduced new CSV option - `enforceSchema`. If it is enabled (by default `true`), Spark forcibly applies provided or inferred schema to CSV files. In that case, CSV headers are ignored and not checked against the schema. If `enforceSchema` is set to `false`, additional checks can be performed. For example, if column in CSV header and in the schema have different ordering, the following exception is thrown:\r\n\r\n```\r\njava.lang.IllegalArgumentException: CSV file header does not contain the expected fields\r\n Header: depth, temperature\r\n Schema: temperature, depth\r\nCSV file: marina.csv\r\n``` \r\n\r\n## How was this patch tested?\r\n\r\nThe changes were tested by existing tests of CSVSuite and by 2 new tests.\r\n","created_at":"2018-03-23T21:14:56Z","updated_at":"2018-05-23T07:27:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f3b3dd54270d6a2da0ac871e5e263d776ed91f95","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/20894/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/20894/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/20894/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/7dce1e72f080044ba471fa08bb572452d4b0c907","head":{"label":"MaxGekk:check-column-names","ref":"check-column-names","sha":"7dce1e72f080044ba471fa08bb572452d4b0c907","user":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"repo":{"id":123690489,"name":"spark-1","full_name":"MaxGekk/spark-1","owner":{"login":"MaxGekk","id":1580697,"avatar_url":"https://avatars1.githubusercontent.com/u/1580697?v=4","gravatar_id":"","url":"https://api.github.com/users/MaxGekk","html_url":"https://github.com/MaxGekk","followers_url":"https://api.github.com/users/MaxGekk/followers","following_url":"https://api.github.com/users/MaxGekk/following{/other_user}","gists_url":"https://api.github.com/users/MaxGekk/gists{/gist_id}","starred_url":"https://api.github.com/users/MaxGekk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaxGekk/subscriptions","organizations_url":"https://api.github.com/users/MaxGekk/orgs","repos_url":"https://api.github.com/users/MaxGekk/repos","events_url":"https://api.github.com/users/MaxGekk/events{/privacy}","received_events_url":"https://api.github.com/users/MaxGekk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MaxGekk/spark-1","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/MaxGekk/spark-1","forks_url":"https://api.github.com/repos/MaxGekk/spark-1/forks","keys_url":"https://api.github.com/repos/MaxGekk/spark-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MaxGekk/spark-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MaxGekk/spark-1/teams","hooks_url":"https://api.github.com/repos/MaxGekk/spark-1/hooks","issue_events_url":"https://api.github.com/repos/MaxGekk/spark-1/issues/events{/number}","events_url":"https://api.github.com/repos/MaxGekk/spark-1/events","assignees_url":"https://api.github.com/repos/MaxGekk/spark-1/assignees{/user}","branches_url":"https://api.github.com/repos/MaxGekk/spark-1/branches{/branch}","tags_url":"https://api.github.com/repos/MaxGekk/spark-1/tags","blobs_url":"https://api.github.com/repos/MaxGekk/spark-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MaxGekk/spark-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MaxGekk/spark-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/MaxGekk/spark-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MaxGekk/spark-1/statuses/{sha}","languages_url":"https://api.github.com/repos/MaxGekk/spark-1/languages","stargazers_url":"https://api.github.com/repos/MaxGekk/spark-1/stargazers","contributors_url":"https://api.github.com/repos/MaxGekk/spark-1/contributors","subscribers_url":"https://api.github.com/repos/MaxGekk/spark-1/subscribers","subscription_url":"https://api.github.com/repos/MaxGekk/spark-1/subscription","commits_url":"https://api.github.com/repos/MaxGekk/spark-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/MaxGekk/spark-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/MaxGekk/spark-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/MaxGekk/spark-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/MaxGekk/spark-1/contents/{+path}","compare_url":"https://api.github.com/repos/MaxGekk/spark-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MaxGekk/spark-1/merges","archive_url":"https://api.github.com/repos/MaxGekk/spark-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MaxGekk/spark-1/downloads","issues_url":"https://api.github.com/repos/MaxGekk/spark-1/issues{/number}","pulls_url":"https://api.github.com/repos/MaxGekk/spark-1/pulls{/number}","milestones_url":"https://api.github.com/repos/MaxGekk/spark-1/milestones{/number}","notifications_url":"https://api.github.com/repos/MaxGekk/spark-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MaxGekk/spark-1/labels{/name}","releases_url":"https://api.github.com/repos/MaxGekk/spark-1/releases{/id}","deployments_url":"https://api.github.com/repos/MaxGekk/spark-1/deployments","created_at":"2018-03-03T12:37:00Z","updated_at":"2018-05-21T15:05:00Z","pushed_at":"2018-05-22T19:56:57Z","git_url":"git://github.com/MaxGekk/spark-1.git","ssh_url":"git@github.com:MaxGekk/spark-1.git","clone_url":"https://github.com/MaxGekk/spark-1.git","svn_url":"https://github.com/MaxGekk/spark-1","homepage":null,"size":271500,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"f9f055afa47412eec8228c843b34a90decb9be43","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2018-05-23T05:32:04Z","pushed_at":"2018-05-23T03:26:37Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":270979,"stargazers_count":17361,"watchers_count":17361,"language":"Scala","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15879,"mirror_url":null,"archived":false,"open_issues_count":542,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":15879,"open_issues":542,"watchers":17361,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/20894"},"html":{"href":"https://github.com/apache/spark/pull/20894"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/20894"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/20894/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/20894/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/20894/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/7dce1e72f080044ba471fa08bb572452d4b0c907"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"MaxGekk"}}