xuanyuanking commented on a change in pull request #30521:
URL: https://github.com/apache/spark/pull/30521#discussion_r533487871
##########
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:
I planed to leave a way for distinguishing the table created by
streaming or batch. But yes, we should not do anything special on the table
side. Removed in 82430ea.
----------------------------------------------------------------
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]