HeartSaVioR commented on a change in pull request #29767:
URL: https://github.com/apache/spark/pull/29767#discussion_r489137110



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/streaming/test/DataStreamReaderWriterSuite.scala
##########
@@ -815,3 +818,131 @@ class DataStreamReaderWriterSuite extends StreamTest with 
BeforeAndAfter {
     }
   }
 }
+
+class DataStreamWriterWithTableSuite extends StreamTest with BeforeAndAfter {
+  import testImplicits._
+
+  before {
+    spark.conf.set("spark.sql.catalog.testcat", 
classOf[InMemoryTableCatalog].getName)
+  }
+
+  after {
+    spark.sessionState.catalogManager.reset()
+    spark.sessionState.conf.clear()
+    sqlContext.streams.active.foreach(_.stop())
+  }
+
+  test("write to table with custom catalog & no namespace") {
+    val tableIdentifier = "testcat.table_name"
+
+    spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
foo")
+    checkAnswer(spark.table(tableIdentifier), Seq.empty)
+
+    runTestWithStreamAppend(tableIdentifier)
+  }
+
+  test("write to table with custom catalog & namespace") {
+    spark.sql("CREATE NAMESPACE testcat.ns")
+
+    val tableIdentifier = "testcat.ns.table_name"
+
+    spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
foo")
+    checkAnswer(spark.table(tableIdentifier), Seq.empty)
+
+    runTestWithStreamAppend(tableIdentifier)
+  }
+
+  test("write to table with default session catalog") {
+    try {
+      val v2Source = classOf[FakeV2Provider].getName
+      spark.conf.set(V2_SESSION_CATALOG_IMPLEMENTATION.key,
+        classOf[InMemoryTableSessionCatalog].getName)
+
+      spark.sql("CREATE NAMESPACE ns")
+
+      val tableIdentifier = "ns.table_name"
+      spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
$v2Source")
+      checkAnswer(spark.table(tableIdentifier), Seq.empty)
+
+      runTestWithStreamAppend(tableIdentifier)
+    } finally {
+      spark.conf.unset(V2_SESSION_CATALOG_IMPLEMENTATION.key)
+    }
+  }
+
+  test("write to non-exist table with custom catalog") {
+    val tableIdentifier = "testcat.nonexisttable"
+    val existTableIdentifier = "testcat.ns.nonexisttable"
+
+    spark.sql("CREATE NAMESPACE testcat.ns")
+    spark.sql(s"CREATE TABLE $existTableIdentifier (id bigint, data string) 
USING foo")
+
+    withTempDir { checkpointDir =>
+      val exc = intercept[NoSuchTableException] {
+        runStreamQueryAppendMode(tableIdentifier, checkpointDir, Seq.empty, 
Seq.empty)
+      }
+      assert(exc.getMessage.contains("nonexisttable"))
+    }
+  }
+
+  test("write to file provider based table shouldn't be allowed yet") {
+    val tableIdentifier = "table_name"
+
+    spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
parquet")
+    checkAnswer(spark.table(tableIdentifier), Seq.empty)
+
+    withTempDir { checkpointDir =>
+      val exc = intercept[AnalysisException] {

Review comment:
       This is because file provider based table is V1 which doesn't have 
capability of streaming write. I hope this is OK, rather than struggling to 
convert it into Sink and making it work anyway.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to