{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/51928412","id":51928412,"diff_hunk":"@@ -0,0 +1,131 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.spark.sql.streaming\n+\n+import java.io.File\n+\n+import org.apache.spark.sql.StreamTest\n+import org.apache.spark.sql.catalyst.util._\n+import org.apache.spark.sql.execution.datasources.ResolvedDataSource\n+import org.apache.spark.sql.execution.streaming.{FileStreamSource, Offset}\n+import org.apache.spark.sql.test.SharedSQLContext\n+import org.apache.spark.util.Utils\n+\n+class FileStreamSourceSuite extends StreamTest with SharedSQLContext {\n+\n+  import testImplicits._\n+\n+  case class AddTextFileData(source: FileStreamSource, content: String, src: File, tmp: File)\n+    extends AddData {\n+\n+    override def addData(): Offset = {\n+      val file = Utils.tempFileWith(new File(tmp, \"text\"))\n+      stringToFile(file, content).renameTo(new File(src, file.getName))\n+      source.currentOffset + 1\n+    }\n+  }\n+\n+  case class AddParquetFileData(\n+      source: FileStreamSource,\n+      content: Seq[String],\n+      src: File,\n+      tmp: File) extends AddData {\n+\n+    override def addData(): Offset = {\n+      val file = Utils.tempFileWith(new File(tmp, \"parquet\"))\n+      content.toDS().toDF().write.parquet(file.getCanonicalPath)\n+      file.renameTo(new File(src, file.getName))\n+      source.currentOffset + 1\n+    }\n+  }\n+\n+  test(\"read from text files\") {\n+    val src = Utils.createTempDir(\"streaming.src\")\n+    val tmp = Utils.createTempDir(\"streaming.tmp\")\n+\n+    val textSource = ResolvedDataSource.createSource(\n+      sqlContext,\n+      userSpecifiedSchema = None,\n+      providerName = \"text\",\n+      options = Map(\"path\" -> src.getCanonicalPath)).asInstanceOf[FileStreamSource]\n+    val df = textSource.toDF().filter($\"value\" contains \"keep\")\n+    val filtered = df\n+\n+    testStream(filtered)(\n+      AddTextFileData(textSource, \"drop1\\nkeep2\\nkeep3\", src, tmp),\n+      CheckAnswer(\"keep2\", \"keep3\"),\n+      AddTextFileData(textSource, \"drop4\\nkeep5\\nkeep6\", src, tmp),\n+      CheckAnswer(\"keep2\", \"keep3\", \"keep5\", \"keep6\"),\n+      AddTextFileData(textSource, \"drop7\\nkeep8\\nkeep9\", src, tmp),\n+      CheckAnswer(\"keep2\", \"keep3\", \"keep5\", \"keep6\", \"keep8\", \"keep9\")\n+    )\n+\n+    Utils.deleteRecursively(src)\n+    Utils.deleteRecursively(tmp)\n+  }\n+\n+  test(\"read from json files\") {\n+    val src = Utils.createTempDir(\"streaming.src\")\n+    val tmp = Utils.createTempDir(\"streaming.tmp\")\n+\n+    val textSource = ResolvedDataSource.createSource(\n+      sqlContext,\n+      userSpecifiedSchema = None,\n+      providerName = \"json\",\n+      options = Map(\"path\" -> src.getCanonicalPath)).asInstanceOf[FileStreamSource]\n+    val df = textSource.toDF().filter($\"value\" contains \"keep\")\n+    val filtered = df\n+\n+    testStream(filtered)(\n+      AddTextFileData(textSource, \"{'c': 'drop1'}\\n{'c': 'keep2'}\\n{'c': 'keep3'}\", src, tmp),","path":"sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala","position":95,"original_position":95,"commit_id":"6a90c55beece97af10af5aa01f004ac85fda02a4","original_commit_id":"6a90c55beece97af10af5aa01f004ac85fda02a4","user":{"login":"marmbrus","id":527,"avatar_url":"https://avatars.githubusercontent.com/u/527?v=3","gravatar_id":"","url":"https://api.github.com/users/marmbrus","html_url":"https://github.com/marmbrus","followers_url":"https://api.github.com/users/marmbrus/followers","following_url":"https://api.github.com/users/marmbrus/following{/other_user}","gists_url":"https://api.github.com/users/marmbrus/gists{/gist_id}","starred_url":"https://api.github.com/users/marmbrus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmbrus/subscriptions","organizations_url":"https://api.github.com/users/marmbrus/orgs","repos_url":"https://api.github.com/users/marmbrus/repos","events_url":"https://api.github.com/users/marmbrus/events{/privacy}","received_events_url":"https://api.github.com/users/marmbrus/received_events","type":"User","site_admin":false},"body":"The column name here is `c` but the query is referencing `value`.","created_at":"2016-02-04T19:54:30Z","updated_at":"2016-02-04T19:54:30Z","html_url":"https://github.com/apache/spark/pull/11034#discussion_r51928412","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/11034","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/51928412"},"html":{"href":"https://github.com/apache/spark/pull/11034#discussion_r51928412"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/11034"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11034","id":58062944,"html_url":"https://github.com/apache/spark/pull/11034","diff_url":"https://github.com/apache/spark/pull/11034.diff","patch_url":"https://github.com/apache/spark/pull/11034.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/11034","number":11034,"state":"open","locked":false,"title":"[SPARK-13149][SQL]Add FileStreamSource","user":{"login":"zsxwing","id":1000778,"avatar_url":"https://avatars.githubusercontent.com/u/1000778?v=3","gravatar_id":"","url":"https://api.github.com/users/zsxwing","html_url":"https://github.com/zsxwing","followers_url":"https://api.github.com/users/zsxwing/followers","following_url":"https://api.github.com/users/zsxwing/following{/other_user}","gists_url":"https://api.github.com/users/zsxwing/gists{/gist_id}","starred_url":"https://api.github.com/users/zsxwing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zsxwing/subscriptions","organizations_url":"https://api.github.com/users/zsxwing/orgs","repos_url":"https://api.github.com/users/zsxwing/repos","events_url":"https://api.github.com/users/zsxwing/events{/privacy}","received_events_url":"https://api.github.com/users/zsxwing/received_events","type":"User","site_admin":false},"body":"`FileStreamSource` is an implementation of `org.apache.spark.sql.execution.streaming.Source`. It takes advantage of the existing `HadoopFsRelationProvider` to support various file formats. It remembers files in each batch and stores it into the metadata files so as to recover them when restarting. The metadata files are stored in the file system. There will be a further PR to clean up the metadata files periodically. \r\n\r\nThis is based on the initial work from @marmbrus.","created_at":"2016-02-02T22:45:36Z","updated_at":"2016-02-04T19:54:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0fc7142342ca7111e420300a043ae9d4c1a18750","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/11034/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/11034/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/11034/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/6a90c55beece97af10af5aa01f004ac85fda02a4","head":{"label":"zsxwing:stream-df-file-source","ref":"stream-df-file-source","sha":"6a90c55beece97af10af5aa01f004ac85fda02a4","user":{"login":"zsxwing","id":1000778,"avatar_url":"https://avatars.githubusercontent.com/u/1000778?v=3","gravatar_id":"","url":"https://api.github.com/users/zsxwing","html_url":"https://github.com/zsxwing","followers_url":"https://api.github.com/users/zsxwing/followers","following_url":"https://api.github.com/users/zsxwing/following{/other_user}","gists_url":"https://api.github.com/users/zsxwing/gists{/gist_id}","starred_url":"https://api.github.com/users/zsxwing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zsxwing/subscriptions","organizations_url":"https://api.github.com/users/zsxwing/orgs","repos_url":"https://api.github.com/users/zsxwing/repos","events_url":"https://api.github.com/users/zsxwing/events{/privacy}","received_events_url":"https://api.github.com/users/zsxwing/received_events","type":"User","site_admin":false},"repo":{"id":17894272,"name":"spark","full_name":"zsxwing/spark","owner":{"login":"zsxwing","id":1000778,"avatar_url":"https://avatars.githubusercontent.com/u/1000778?v=3","gravatar_id":"","url":"https://api.github.com/users/zsxwing","html_url":"https://github.com/zsxwing","followers_url":"https://api.github.com/users/zsxwing/followers","following_url":"https://api.github.com/users/zsxwing/following{/other_user}","gists_url":"https://api.github.com/users/zsxwing/gists{/gist_id}","starred_url":"https://api.github.com/users/zsxwing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zsxwing/subscriptions","organizations_url":"https://api.github.com/users/zsxwing/orgs","repos_url":"https://api.github.com/users/zsxwing/repos","events_url":"https://api.github.com/users/zsxwing/events{/privacy}","received_events_url":"https://api.github.com/users/zsxwing/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zsxwing/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/zsxwing/spark","forks_url":"https://api.github.com/repos/zsxwing/spark/forks","keys_url":"https://api.github.com/repos/zsxwing/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zsxwing/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zsxwing/spark/teams","hooks_url":"https://api.github.com/repos/zsxwing/spark/hooks","issue_events_url":"https://api.github.com/repos/zsxwing/spark/issues/events{/number}","events_url":"https://api.github.com/repos/zsxwing/spark/events","assignees_url":"https://api.github.com/repos/zsxwing/spark/assignees{/user}","branches_url":"https://api.github.com/repos/zsxwing/spark/branches{/branch}","tags_url":"https://api.github.com/repos/zsxwing/spark/tags","blobs_url":"https://api.github.com/repos/zsxwing/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zsxwing/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zsxwing/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/zsxwing/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zsxwing/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/zsxwing/spark/languages","stargazers_url":"https://api.github.com/repos/zsxwing/spark/stargazers","contributors_url":"https://api.github.com/repos/zsxwing/spark/contributors","subscribers_url":"https://api.github.com/repos/zsxwing/spark/subscribers","subscription_url":"https://api.github.com/repos/zsxwing/spark/subscription","commits_url":"https://api.github.com/repos/zsxwing/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/zsxwing/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/zsxwing/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/zsxwing/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/zsxwing/spark/contents/{+path}","compare_url":"https://api.github.com/repos/zsxwing/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zsxwing/spark/merges","archive_url":"https://api.github.com/repos/zsxwing/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zsxwing/spark/downloads","issues_url":"https://api.github.com/repos/zsxwing/spark/issues{/number}","pulls_url":"https://api.github.com/repos/zsxwing/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/zsxwing/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/zsxwing/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zsxwing/spark/labels{/name}","releases_url":"https://api.github.com/repos/zsxwing/spark/releases{/id}","deployments_url":"https://api.github.com/repos/zsxwing/spark/deployments","created_at":"2014-03-19T06:21:04Z","updated_at":"2015-03-09T07:52:42Z","pushed_at":"2016-02-04T19:02:53Z","git_url":"git://github.com/zsxwing/spark.git","ssh_url":"git@github.com:zsxwing/spark.git","clone_url":"https://github.com/zsxwing/spark.git","svn_url":"https://github.com/zsxwing/spark","homepage":null,"size":135870,"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":"9dd2741ebe5f9b5fa0a3b0e9c594d0e94b6226f9","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-04T19:53:22Z","pushed_at":"2016-02-04T19:50:27Z","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":409605,"stargazers_count":7345,"watchers_count":7345,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6679,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":361,"forks":6679,"open_issues":361,"watchers":7345,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/11034"},"html":{"href":"https://github.com/apache/spark/pull/11034"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/11034"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/11034/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/11034/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/11034/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/6a90c55beece97af10af5aa01f004ac85fda02a4"}}}}