{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/53448453","id":53448453,"diff_hunk":"@@ -130,7 +141,49 @@ object ResolvedDataSource extends Logging {\n       bucketSpec: Option[BucketSpec],\n       provider: String,\n       options: Map[String, String]): ResolvedDataSource = {\n-    val clazz: Class[_] = lookupDataSource(provider)\n+    // Here, it tries to find out data source by file extensions if the `format()` is not called.\n+    // The auto-detection is based on given paths and it recognizes glob pattern as well but\n+    // it does not recursively check the sub-paths even if the given paths are directories.\n+    // This source detection goes the following steps\n+    //\n+    //   1. Check `provider` and use this if this is not `null`.\n+    //   2. If `provider` is not given, then it tries to detect the source types by extension.\n+    //      at this point, if detects only if all the given paths have the same extension.\n+    //   3. if it fails to detect, use the datasource given to `spark.sql.sources.default`.\n+    //\n+    val paths = {\n+      val caseInsensitiveOptions = new CaseInsensitiveMap(options)\n+      if (caseInsensitiveOptions.contains(\"paths\") &&\n+        caseInsensitiveOptions.contains(\"path\")) {\n+        throw new AnalysisException(s\"Both path and paths options are present.\")\n+      }\n+      caseInsensitiveOptions.get(\"paths\")\n+        .map(_.split(\"(?<!\\\\\\\\),\").map(StringUtils.unEscapeString(_, '\\\\', ',')))\n+        .getOrElse(Array(caseInsensitiveOptions(\"path\")))\n+        .flatMap{ pathString =>\n+        val hdfsPath = new Path(pathString)\n+        val fs = hdfsPath.getFileSystem(sqlContext.sparkContext.hadoopConfiguration)\n+        val qualified = hdfsPath.makeQualified(fs.getUri, fs.getWorkingDirectory)\n+        SparkHadoopUtil.get.globPathIfNecessary(qualified).map(_.toString)\n+      }\n+    }\n+    val safeProvider = Option(provider).getOrElse {\n+      val safePaths = paths.filterNot { path =>\n+        FilenameUtils.getBaseName(path)\n+        path.startsWith(\"_\") || path.startsWith(\".\")\n+      }\n+      val extensions = safePaths.map { path =>\n+        FilenameUtils.getExtension(path).toLowerCase\n+      }\n+      val defaultDataSourceName = sqlContext.conf.defaultDataSourceName\n+      if (extensions.exists(extensions.head != _)) {\n+        defaultDataSourceName","path":"sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/ResolvedDataSource.scala","position":83,"original_position":83,"commit_id":"23ba7266358a3de4800bb65da316c20f60bbf7a8","original_commit_id":"23ba7266358a3de4800bb65da316c20f60bbf7a8","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":"Then original call `read().load()` for files having no extensions would throw an exception which breaks backword compatibility.\r\n\r\nIf we drops this for Spark 2.0, I think that is a good idea.","created_at":"2016-02-19T11:09:05Z","updated_at":"2016-02-19T11:09:05Z","html_url":"https://github.com/apache/spark/pull/11270#discussion_r53448453","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/11270","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/53448453"},"html":{"href":"https://github.com/apache/spark/pull/11270#discussion_r53448453"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/11270"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11270","id":59929781,"html_url":"https://github.com/apache/spark/pull/11270","diff_url":"https://github.com/apache/spark/pull/11270.diff","patch_url":"https://github.com/apache/spark/pull/11270.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/11270","number":11270,"state":"open","locked":false,"title":"[SPARK-8000][SQL] Support for auto-detecting data sources.","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://issues.apache.org/jira/browse/SPARK-8000\r\n\r\nThis PR adds the support for detecting data source by extension.\r\n\r\nAs I described in comments, detection follows the steps below:\r\n\r\n > Here, it tries to find out data source by file extensions if the `format()` is not called.\r\n > The auto-detection is based on given paths and it recognizes glob pattern as well but\r\n > it does not recursively check the sub-paths even if the given paths are directories.\r\n > This source detection goes the following steps\r\n >\r\n >   1. Check `provider` and use this if this is not `null`.\r\n >   2. If `provider` is not given, then it tries to detect the source types by extension.\r\n >      at this point, if detects only if all the given paths have the same extension.\r\n >   3. if it fails to detect, use the datasource given to `spark.sql.sources.default`.\r\n\r\n\r\nEach tests has been added for each datasource.\r\n","created_at":"2016-02-19T10:21:07Z","updated_at":"2016-02-19T11:09:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1cdd83071fb4297ded6d4aafbbb4a71190c34d58","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/11270/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/11270/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/11270/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/23ba7266358a3de4800bb65da316c20f60bbf7a8","head":{"label":"HyukjinKwon:SPARK-8000","ref":"SPARK-8000","sha":"23ba7266358a3de4800bb65da316c20f60bbf7a8","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":42300713,"name":"spark","full_name":"HyukjinKwon/spark","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","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/HyukjinKwon/spark","forks_url":"https://api.github.com/repos/HyukjinKwon/spark/forks","keys_url":"https://api.github.com/repos/HyukjinKwon/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HyukjinKwon/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HyukjinKwon/spark/teams","hooks_url":"https://api.github.com/repos/HyukjinKwon/spark/hooks","issue_events_url":"https://api.github.com/repos/HyukjinKwon/spark/issues/events{/number}","events_url":"https://api.github.com/repos/HyukjinKwon/spark/events","assignees_url":"https://api.github.com/repos/HyukjinKwon/spark/assignees{/user}","branches_url":"https://api.github.com/repos/HyukjinKwon/spark/branches{/branch}","tags_url":"https://api.github.com/repos/HyukjinKwon/spark/tags","blobs_url":"https://api.github.com/repos/HyukjinKwon/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HyukjinKwon/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HyukjinKwon/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/HyukjinKwon/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HyukjinKwon/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/HyukjinKwon/spark/languages","stargazers_url":"https://api.github.com/repos/HyukjinKwon/spark/stargazers","contributors_url":"https://api.github.com/repos/HyukjinKwon/spark/contributors","subscribers_url":"https://api.github.com/repos/HyukjinKwon/spark/subscribers","subscription_url":"https://api.github.com/repos/HyukjinKwon/spark/subscription","commits_url":"https://api.github.com/repos/HyukjinKwon/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/HyukjinKwon/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/HyukjinKwon/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/HyukjinKwon/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/HyukjinKwon/spark/contents/{+path}","compare_url":"https://api.github.com/repos/HyukjinKwon/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HyukjinKwon/spark/merges","archive_url":"https://api.github.com/repos/HyukjinKwon/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HyukjinKwon/spark/downloads","issues_url":"https://api.github.com/repos/HyukjinKwon/spark/issues{/number}","pulls_url":"https://api.github.com/repos/HyukjinKwon/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/HyukjinKwon/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/HyukjinKwon/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HyukjinKwon/spark/labels{/name}","releases_url":"https://api.github.com/repos/HyukjinKwon/spark/releases{/id}","deployments_url":"https://api.github.com/repos/HyukjinKwon/spark/deployments","created_at":"2015-09-11T09:47:43Z","updated_at":"2015-09-11T09:48:06Z","pushed_at":"2016-02-19T10:16:35Z","git_url":"git://github.com/HyukjinKwon/spark.git","ssh_url":"git@github.com:HyukjinKwon/spark.git","clone_url":"https://github.com/HyukjinKwon/spark.git","svn_url":"https://github.com/HyukjinKwon/spark","homepage":null,"size":146244,"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":"apache:master","ref":"master","sha":"c776fce99b496a789ffcf2cfab78cf51eeea032b","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","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://avatars.githubusercontent.com/u/47359?v=3","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":"2016-02-19T09:24:00Z","pushed_at":"2016-02-19T10:43:44Z","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":415317,"stargazers_count":7490,"watchers_count":7490,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6815,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":396,"forks":6815,"open_issues":396,"watchers":7490,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/11270"},"html":{"href":"https://github.com/apache/spark/pull/11270"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/11270"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/11270/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/11270/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/11270/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/23ba7266358a3de4800bb65da316c20f60bbf7a8"}}}}