xuanyuanking commented on a change in pull request #30521:
URL: https://github.com/apache/spark/pull/30521#discussion_r535038435
##########
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.empty[String, String],
+ extraOptions.get("path"),
+ None,
+ None,
+ external = false,
+ ifNotExists = false)
+ Dataset.ofRows(df.sparkSession, cmd)
+ }
- val tableInstance = catalog.asTableCatalog.loadTable(identifier)
+ val tableInstance = catalog.asTableCatalog.loadTable(identifier)
- import
org.apache.spark.sql.execution.datasources.v2.DataSourceV2Implicits._
- val sink = tableInstance match {
- case t: SupportsWrite if t.supports(STREAMING_WRITE) => t
- case t => throw new AnalysisException(s"Table $tableName doesn't
support streaming " +
- s"write - $t")
- }
+ def writeToV1Table(table: CatalogTable): StreamingQuery = {
+ require(table.tableType != CatalogTableType.VIEW, "Streaming into views
is not supported.")
+ format(table.provider.get)
Review comment:
Got the point. So your point focus on how DSv2 addressing the partition
column conflict. My point is want to explain we shouldn't overwrite the user's
input, ~we need to pass both(user-input and table catalog partition info) into
the data source.~ Data source need to know both(user-input and table catalog
partition info). I already added this and further discussion to SPARK-33638's
[comment](https://issues.apache.org/jira/browse/SPARK-33638?focusedCommentId=17243070&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17243070)
since it's part of full support for the V2 table.
----------------------------------------------------------------
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]