{"action":"created","comment":{"url":"https://api.github.com/repos/databricks/spark-csv/pulls/comments/42460993","id":42460993,"diff_hunk":"@@ -136,6 +136,58 @@ case class CsvRelation protected[spark] (\n     }\n   }\n \n+  override def buildScan(requiredColumns: Array[String]): RDD[Row] = {\n+    val schemaFields = schema.fields\n+    val isTableScan = requiredColumns.isEmpty || requiredColumns.sameElements(schemaFields)\n+    if (isTableScan) {\n+      buildScan\n+    } else {\n+      val requiredFields = StructType(requiredColumns.map(schema(_))).fields\n+      val requiredIndices = new Array[Int](requiredFields.length)\n+      schemaFields.zipWithIndex.filter(pair => requiredFields.contains(pair._1))\n+        .foreach(pair => requiredIndices.update(requiredFields.indexOf(pair._1), pair._2))\n+\n+      tokenRdd(schemaFields.map(_.name)).flatMap { tokens =>\n+        if (dropMalformed && schemaFields.length != tokens.size) {\n+          logger.warn(s\"Dropping malformed line: ${tokens.mkString(\",\")}\")\n+          None\n+        } else if (failFast && schemaFields.length != tokens.size) {\n+          throw new RuntimeException(s\"Malformed line in FAILFAST mode: ${tokens.mkString(\",\")}\")\n+        } else {\n+          val indexSafeTokens = if (permissive && schemaFields.length != tokens.size) {","path":"src/main/scala/com/databricks/spark/csv/CsvRelation.scala","position":40,"original_position":40,"commit_id":"f4133a4f16917f13318ec114aa083e16a8e63d9d","original_commit_id":"f4133a4f16917f13318ec114aa083e16a8e63d9d","user":{"login":"JoshRosen","id":50748,"avatar_url":"https://avatars.githubusercontent.com/u/50748?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshRosen","html_url":"https://github.com/JoshRosen","followers_url":"https://api.github.com/users/JoshRosen/followers","following_url":"https://api.github.com/users/JoshRosen/following{/other_user}","gists_url":"https://api.github.com/users/JoshRosen/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshRosen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshRosen/subscriptions","organizations_url":"https://api.github.com/users/JoshRosen/orgs","repos_url":"https://api.github.com/users/JoshRosen/repos","events_url":"https://api.github.com/users/JoshRosen/events{/privacy}","received_events_url":"https://api.github.com/users/JoshRosen/received_events","type":"User","site_admin":false},"body":"Oh, nevermind, I see that this is covered by the `if (failFast && schemaFields.length != tokens.size)` case above.","created_at":"2015-10-20T06:48:02Z","updated_at":"2015-10-20T06:48:02Z","html_url":"https://github.com/databricks/spark-csv/pull/169#discussion_r42460993","pull_request_url":"https://api.github.com/repos/databricks/spark-csv/pulls/169","_links":{"self":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/comments/42460993"},"html":{"href":"https://github.com/databricks/spark-csv/pull/169#discussion_r42460993"},"pull_request":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/169"}}},"pull_request":{"url":"https://api.github.com/repos/databricks/spark-csv/pulls/169","id":48160427,"html_url":"https://github.com/databricks/spark-csv/pull/169","diff_url":"https://github.com/databricks/spark-csv/pull/169.diff","patch_url":"https://github.com/databricks/spark-csv/pull/169.patch","issue_url":"https://api.github.com/repos/databricks/spark-csv/issues/169","number":169,"state":"open","locked":false,"title":"Support for pruned scan for required fields.","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"body":"https://github.com/databricks/spark-csv/issues/166\r\n\r\nFirstly,\r\nI tested the pure iteration time of produced RDD from `buildScan()` with `lineitem` table in TPC-H.\r\nOn local machine, I set the number of 100,000 rows and measure the time.\r\n\r\nThe result was below. (The total number of columns was 17)\r\n\r\n|Scan Type|Required Fields|Elapsed Time|\r\n|--------|-------|-------|\r\n|`PrunedScan`|`C0`|0.106|\r\n|`PrunedScan`|`C0, C1, C2, C3, C4, C5, C6`|0.287|\r\n|`PrunedScan`|`* (C0 - C16)`|0.505|\r\n|`TableScan`|`C0`|0.536|\r\n|`TableScan`|`C0, C1, C2, C3, C4, C5, C6`|0.502|\r\n|`TableScan`|`* (C0 - C16)`|0.489|\r\n\r\nSecondly, I didn't add test codes separately since the original test codes cover this.\r\n\r\nCould you review this please?","created_at":"2015-10-20T06:11:59Z","updated_at":"2015-10-20T06:48:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a5c032549655ae5c6e2d504db9e723138e2f49cf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/databricks/spark-csv/pulls/169/commits","review_comments_url":"https://api.github.com/repos/databricks/spark-csv/pulls/169/comments","review_comment_url":"https://api.github.com/repos/databricks/spark-csv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/databricks/spark-csv/issues/169/comments","statuses_url":"https://api.github.com/repos/databricks/spark-csv/statuses/f4133a4f16917f13318ec114aa083e16a8e63d9d","head":{"label":"HyukjinKwon:ISSUE-166","ref":"ISSUE-166","sha":"f4133a4f16917f13318ec114aa083e16a8e63d9d","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"repo":{"id":44584908,"name":"spark-csv","full_name":"HyukjinKwon/spark-csv","owner":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/HyukjinKwon/spark-csv","description":"CSV data source for Spark SQL and DataFrames","fork":true,"url":"https://api.github.com/repos/HyukjinKwon/spark-csv","forks_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/forks","keys_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/teams","hooks_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/hooks","issue_events_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/issues/events{/number}","events_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/events","assignees_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/assignees{/user}","branches_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/branches{/branch}","tags_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/tags","blobs_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/git/refs{/sha}","trees_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/statuses/{sha}","languages_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/languages","stargazers_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/stargazers","contributors_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/contributors","subscribers_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/subscribers","subscription_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/subscription","commits_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/commits{/sha}","git_commits_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/git/commits{/sha}","comments_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/comments{/number}","issue_comment_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/issues/comments{/number}","contents_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/contents/{+path}","compare_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/merges","archive_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/downloads","issues_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/issues{/number}","pulls_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/pulls{/number}","milestones_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/milestones{/number}","notifications_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/labels{/name}","releases_url":"https://api.github.com/repos/HyukjinKwon/spark-csv/releases{/id}","created_at":"2015-10-20T05:48:06Z","updated_at":"2015-10-20T05:48:07Z","pushed_at":"2015-10-20T06:23:11Z","git_url":"git://github.com/HyukjinKwon/spark-csv.git","ssh_url":"git@github.com:HyukjinKwon/spark-csv.git","clone_url":"https://github.com/HyukjinKwon/spark-csv.git","svn_url":"https://github.com/HyukjinKwon/spark-csv","homepage":"http://databricks.com/","size":1060,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"databricks:master","ref":"master","sha":"001aa71d93174d0d0a6c9bc96aa460ce2770d43b","user":{"login":"databricks","id":4998052,"avatar_url":"https://avatars.githubusercontent.com/u/4998052?v=3","gravatar_id":"","url":"https://api.github.com/users/databricks","html_url":"https://github.com/databricks","followers_url":"https://api.github.com/users/databricks/followers","following_url":"https://api.github.com/users/databricks/following{/other_user}","gists_url":"https://api.github.com/users/databricks/gists{/gist_id}","starred_url":"https://api.github.com/users/databricks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/databricks/subscriptions","organizations_url":"https://api.github.com/users/databricks/orgs","repos_url":"https://api.github.com/users/databricks/repos","events_url":"https://api.github.com/users/databricks/events{/privacy}","received_events_url":"https://api.github.com/users/databricks/received_events","type":"Organization","site_admin":false},"repo":{"id":27461793,"name":"spark-csv","full_name":"databricks/spark-csv","owner":{"login":"databricks","id":4998052,"avatar_url":"https://avatars.githubusercontent.com/u/4998052?v=3","gravatar_id":"","url":"https://api.github.com/users/databricks","html_url":"https://github.com/databricks","followers_url":"https://api.github.com/users/databricks/followers","following_url":"https://api.github.com/users/databricks/following{/other_user}","gists_url":"https://api.github.com/users/databricks/gists{/gist_id}","starred_url":"https://api.github.com/users/databricks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/databricks/subscriptions","organizations_url":"https://api.github.com/users/databricks/orgs","repos_url":"https://api.github.com/users/databricks/repos","events_url":"https://api.github.com/users/databricks/events{/privacy}","received_events_url":"https://api.github.com/users/databricks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/databricks/spark-csv","description":"CSV data source for Spark SQL and DataFrames","fork":false,"url":"https://api.github.com/repos/databricks/spark-csv","forks_url":"https://api.github.com/repos/databricks/spark-csv/forks","keys_url":"https://api.github.com/repos/databricks/spark-csv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/databricks/spark-csv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/databricks/spark-csv/teams","hooks_url":"https://api.github.com/repos/databricks/spark-csv/hooks","issue_events_url":"https://api.github.com/repos/databricks/spark-csv/issues/events{/number}","events_url":"https://api.github.com/repos/databricks/spark-csv/events","assignees_url":"https://api.github.com/repos/databricks/spark-csv/assignees{/user}","branches_url":"https://api.github.com/repos/databricks/spark-csv/branches{/branch}","tags_url":"https://api.github.com/repos/databricks/spark-csv/tags","blobs_url":"https://api.github.com/repos/databricks/spark-csv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/databricks/spark-csv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/databricks/spark-csv/git/refs{/sha}","trees_url":"https://api.github.com/repos/databricks/spark-csv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/databricks/spark-csv/statuses/{sha}","languages_url":"https://api.github.com/repos/databricks/spark-csv/languages","stargazers_url":"https://api.github.com/repos/databricks/spark-csv/stargazers","contributors_url":"https://api.github.com/repos/databricks/spark-csv/contributors","subscribers_url":"https://api.github.com/repos/databricks/spark-csv/subscribers","subscription_url":"https://api.github.com/repos/databricks/spark-csv/subscription","commits_url":"https://api.github.com/repos/databricks/spark-csv/commits{/sha}","git_commits_url":"https://api.github.com/repos/databricks/spark-csv/git/commits{/sha}","comments_url":"https://api.github.com/repos/databricks/spark-csv/comments{/number}","issue_comment_url":"https://api.github.com/repos/databricks/spark-csv/issues/comments{/number}","contents_url":"https://api.github.com/repos/databricks/spark-csv/contents/{+path}","compare_url":"https://api.github.com/repos/databricks/spark-csv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/databricks/spark-csv/merges","archive_url":"https://api.github.com/repos/databricks/spark-csv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/databricks/spark-csv/downloads","issues_url":"https://api.github.com/repos/databricks/spark-csv/issues{/number}","pulls_url":"https://api.github.com/repos/databricks/spark-csv/pulls{/number}","milestones_url":"https://api.github.com/repos/databricks/spark-csv/milestones{/number}","notifications_url":"https://api.github.com/repos/databricks/spark-csv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/databricks/spark-csv/labels{/name}","releases_url":"https://api.github.com/repos/databricks/spark-csv/releases{/id}","created_at":"2014-12-03T00:56:21Z","updated_at":"2015-10-19T13:59:45Z","pushed_at":"2015-10-20T06:23:11Z","git_url":"git://github.com/databricks/spark-csv.git","ssh_url":"git@github.com:databricks/spark-csv.git","clone_url":"https://github.com/databricks/spark-csv.git","svn_url":"https://github.com/databricks/spark-csv","homepage":"http://databricks.com/","size":1060,"stargazers_count":234,"watchers_count":234,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":96,"mirror_url":null,"open_issues_count":40,"forks":96,"open_issues":40,"watchers":234,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/169"},"html":{"href":"https://github.com/databricks/spark-csv/pull/169"},"issue":{"href":"https://api.github.com/repos/databricks/spark-csv/issues/169"},"comments":{"href":"https://api.github.com/repos/databricks/spark-csv/issues/169/comments"},"review_comments":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/169/comments"},"review_comment":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/databricks/spark-csv/pulls/169/commits"},"statuses":{"href":"https://api.github.com/repos/databricks/spark-csv/statuses/f4133a4f16917f13318ec114aa083e16a8e63d9d"}}}}