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



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/streaming/DataStreamWriter.scala
##########
@@ -304,46 +308,68 @@ final class DataStreamWriter[T] private[sql](ds: 
Dataset[T]) {
    * @since 3.1.0
    */
   @throws[TimeoutException]
-  def saveAsTable(tableName: String): StreamingQuery = {
-    this.source = SOURCE_NAME_TABLE
+  def table(tableName: String): StreamingQuery = {
     this.tableName = tableName
-    startInternal(None)
-  }
 
-  private def startInternal(path: Option[String]): StreamingQuery = {
-    if (source.toLowerCase(Locale.ROOT) == DDLUtils.HIVE_PROVIDER) {
-      throw new AnalysisException("Hive data source can only be used with 
tables, you can not " +
-        "write files of Hive data source directly.")
-    }
+    import df.sparkSession.sessionState.analyzer.CatalogAndIdentifier
 
-    if (source == SOURCE_NAME_TABLE) {
-      assertNotPartitioned(SOURCE_NAME_TABLE)
+    import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
+    val originalMultipartIdentifier = df.sparkSession.sessionState.sqlParser
+      .parseMultipartIdentifier(tableName)
+    val CatalogAndIdentifier(catalog, identifier) = originalMultipartIdentifier
 
-      import df.sparkSession.sessionState.analyzer.CatalogAndIdentifier
+    // Currently we don't create a logical streaming writer node in logical 
plan, so cannot rely
+    // on analyzer to resolve it. Directly lookup only for temp view to 
provide clearer message.
+    // TODO (SPARK-27484): we should add the writing node before the plan is 
analyzed.
+    if 
(df.sparkSession.sessionState.catalog.isTempView(originalMultipartIdentifier)) {
+      throw new AnalysisException(s"Temporary view $tableName doesn't support 
streaming write")
+    }
 
+    if (!catalog.asTableCatalog.tableExists(identifier)) {
       import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
-      val originalMultipartIdentifier = df.sparkSession.sessionState.sqlParser
-        .parseMultipartIdentifier(tableName)
-      val CatalogAndIdentifier(catalog, identifier) = 
originalMultipartIdentifier
-
-      // Currently we don't create a logical streaming writer node in logical 
plan, so cannot rely
-      // on analyzer to resolve it. Directly lookup only for temp view to 
provide clearer message.
-      // TODO (SPARK-27484): we should add the writing node before the plan is 
analyzed.
-      if 
(df.sparkSession.sessionState.catalog.isTempView(originalMultipartIdentifier)) {
-        throw new AnalysisException(s"Temporary view $tableName doesn't 
support streaming write")
-      }
+      val cmd = CreateTableStatement(

Review comment:
       I think leveraging the old (probably DSv1) options is not sufficient - 
this doesn't have full coverage on DSv2 table - no `Transform` on partitioning, 
no properties, no options. 
   
   Using `source` (via `format(...)`) as `USE <provider>` is also not intuitive 
- it is only effective when table creation is taking place, and it occurs 
implicitly.
   
   Please compare the usage with creating table on DataFrameWriterV2. I still 
think this worths having V2 writer for streaming.




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