You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/11/27 13:14:28 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #30521: [SPARK-33577][SS] Add support for V1Table in stream writer table API

cloud-fan commented on a change in pull request #30521:
URL: https://github.com/apache/spark/pull/30521#discussion_r531594942



##########
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(
+        originalMultipartIdentifier,
+        df.schema.asNullable,
+        partitioningColumns.getOrElse(Nil).asTransforms.toSeq,
+        None,
+        Map.empty[String, String],
+        Some(source),
+        Map("createBy" -> "DataStreamWriterAPI"),

Review comment:
       This is very skeptical. It seems like we want to break the semantic of  `CreateTableStatement` and do something special if it's issued by `DataStreamWriter`. We shouldn't encourage it.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org