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



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/streaming/DataStreamWriter.scala
##########
@@ -300,54 +301,44 @@ final class DataStreamWriter[T] private[sql](ds: 
Dataset[T]) {
         "write files of Hive data source directly.")
     }
 
-    if (source == "memory") {
+    if (source == SOURCE_NAME_TABLE) {
+      assertNotPartitioned("table")
+
+      import df.sparkSession.sessionState.analyzer.CatalogAndIdentifier
+
+      import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+      val CatalogAndIdentifier(catalog, identifier) = 
df.sparkSession.sessionState.sqlParser

Review comment:
       @cloud-fan 
   Does the functionality (DataFrameWriter.insertInto with (temp) view) being 
covered by tests?
   
   ```
     test("insertInto to view against file-based table") {
       val tableIdentifier = "table_name"
       val viewIdentifier = "table_view"
   
       spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
parquet")
       checkAnswer(spark.table(tableIdentifier), Seq.empty)
   
       spark.sql(s"CREATE VIEW $viewIdentifier AS SELECT id, data FROM 
$tableIdentifier")
   
       spark.range(10).write.insertInto(viewIdentifier)
   
       /*
       Inserting into a view is not allowed. View: `default`.`table_view`.;
       org.apache.spark.sql.AnalysisException: Inserting into a view is not 
allowed. View: `default`.`table_view`.;
        */
     }
   
     test("insertInto to temp view against file-based table") {
       val tableIdentifier = "table_name"
       val tempViewIdentifier = "temp_view"
   
       spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
parquet")
       checkAnswer(spark.table(tableIdentifier), Seq.empty)
   
       spark.sql(s"SELECT id, data FROM 
$tableIdentifier").createOrReplaceTempView(tempViewIdentifier)
   
       spark.range(10).write.insertInto(tempViewIdentifier)
   
       /*
       Inserting into an RDD-based table is not allowed.;;
       'InsertIntoStatement Project [id#0L, data#1], false, false
       +- Range (0, 10, step=1, splits=Some(2))
   
       org.apache.spark.sql.AnalysisException: Inserting into an RDD-based 
table is not allowed.;;
       'InsertIntoStatement Project [id#0L, data#1], false, false
       +- Range (0, 10, step=1, splits=Some(2))
   
       --> Actually the relation is under the projection
       Project [id#0L, data#1]
       +- Relation[id#0L,data#1] parquet
        */
     }
   
     test("insertInto to view against V2 table") {
       val tableIdentifier = "testcat.table_name"
       val viewIdentifier = "table_view"
   
       spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
foo")
       checkAnswer(spark.table(tableIdentifier), Seq.empty)
   
       spark.sql(s"CREATE VIEW $viewIdentifier AS SELECT id, data FROM 
$tableIdentifier")
   
       spark.range(10).write.insertInto(viewIdentifier)
   
       /*
       Inserting into a view is not allowed. View: `default`.`table_view`.;
       org.apache.spark.sql.AnalysisException: Inserting into a view is not 
allowed. View: `default`.`table_view`.;
        */
     }
   
     test("insertInto to temp view against V2 table") {
       val tableIdentifier = "testcat.table_name"
       val tempViewIdentifier = "temp_view"
   
       spark.sql(s"CREATE TABLE $tableIdentifier (id bigint, data string) USING 
foo")
       checkAnswer(spark.table(tableIdentifier), Seq.empty)
   
       spark.sql(s"SELECT id, data FROM 
$tableIdentifier").createOrReplaceTempView(tempViewIdentifier)
   
       spark.range(10).write.insertInto(tempViewIdentifier)
   
       /*
       Inserting into an RDD-based table is not allowed.;;
       'InsertIntoStatement Project [id#8L, data#9], false, false
       +- Range (0, 10, step=1, splits=Some(2))
   
       org.apache.spark.sql.AnalysisException: Inserting into an RDD-based 
table is not allowed.;;
       'InsertIntoStatement Project [id#8L, data#9], false, false
       +- Range (0, 10, step=1, splits=Some(2))
   
       --> Actually the relation is under the projection
       Project [id#8L, data#9]
       +- RelationV2[id#8L, data#9] testcat.table_name
        */
     }
   ```
   
   All tests failed.




----------------------------------------------------------------
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