-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-37496][SQL] Migrate ReplaceTableAsSelectStatement to v2 command #34754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,10 @@ import scala.collection.JavaConverters._ | |
|
|
||
| import org.apache.spark.annotation.Stable | ||
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, NoSuchTableException, UnresolvedRelation} | ||
| import org.apache.spark.sql.catalyst.analysis.{EliminateSubqueryAliases, NoSuchTableException, UnresolvedDBObjectName, UnresolvedRelation} | ||
| import org.apache.spark.sql.catalyst.catalog._ | ||
| import org.apache.spark.sql.catalyst.expressions.Literal | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AppendData, CreateTableAsSelect, CreateTableAsSelectStatement, InsertIntoStatement, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic, ReplaceTableAsSelectStatement} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AppendData, CreateTableAsSelect, CreateTableAsSelectStatement, InsertIntoStatement, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic, ReplaceTableAsSelect, TableSpec} | ||
| import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap | ||
| import org.apache.spark.sql.connector.catalog.{CatalogPlugin, CatalogV2Implicits, CatalogV2Util, Identifier, SupportsCatalogOptions, Table, TableCatalog, TableProvider, V1Table} | ||
| import org.apache.spark.sql.connector.catalog.TableCapability._ | ||
|
|
@@ -586,19 +586,13 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) { | |
| AppendData.byName(v2Relation, df.logicalPlan, extraOptions.toMap) | ||
|
|
||
| case (SaveMode.Overwrite, _) => | ||
| ReplaceTableAsSelectStatement( | ||
| nameParts, | ||
| df.queryExecution.analyzed, | ||
| partitioningAsV2, | ||
| None, | ||
| Map.empty, | ||
| Some(source), | ||
| Map.empty, | ||
| extraOptions.get("path"), | ||
| extraOptions.get(TableCatalog.PROP_COMMENT), | ||
| extraOptions.toMap, | ||
| None, | ||
| orCreate = true) // Create the table if it doesn't exist | ||
| val tableSpec = TableSpec(None, Map.empty, Some(source), Map.empty, | ||
| extraOptions.get("path"), extraOptions.get(TableCatalog.PROP_COMMENT), | ||
| None, false) | ||
| ReplaceTableAsSelect( | ||
| UnresolvedDBObjectName(nameParts, isNamespace = false), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we prepend
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems no need? I stepped into one of the test, the |
||
| partitioningAsV2, df.queryExecution.analyzed, tableSpec, writeOptions = Map.empty, | ||
| orCreate = true) // Create the table if it doesn't exist | ||
|
|
||
| case (other, _) => | ||
| // We have a potential race condition here in AppendMode, if the table suddenly gets | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,9 @@ import scala.collection.JavaConverters._ | |
| import scala.collection.mutable | ||
|
|
||
| import org.apache.spark.annotation.Experimental | ||
| import org.apache.spark.sql.catalyst.analysis.{CannotReplaceMissingTableException, NoSuchTableException, TableAlreadyExistsException, UnresolvedRelation} | ||
| import org.apache.spark.sql.catalyst.analysis.{CannotReplaceMissingTableException, NoSuchTableException, TableAlreadyExistsException, UnresolvedDBObjectName, UnresolvedRelation} | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, Bucket, Days, Hours, Literal, Months, Years} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AppendData, CreateTableAsSelectStatement, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic, ReplaceTableAsSelectStatement} | ||
| import org.apache.spark.sql.catalyst.plans.logical.{AppendData, CreateTableAsSelectStatement, LogicalPlan, OverwriteByExpression, OverwritePartitionsDynamic, ReplaceTableAsSelect, TableSpec} | ||
| import org.apache.spark.sql.connector.expressions.{LogicalExpressions, NamedReference, Transform} | ||
| import org.apache.spark.sql.errors.QueryCompilationErrors | ||
| import org.apache.spark.sql.types.IntegerType | ||
|
|
@@ -195,20 +195,12 @@ final class DataFrameWriterV2[T] private[sql](table: String, ds: Dataset[T]) | |
| } | ||
|
|
||
| private def internalReplace(orCreate: Boolean): Unit = { | ||
| runCommand( | ||
| ReplaceTableAsSelectStatement( | ||
| tableName, | ||
| logicalPlan, | ||
| partitioning.getOrElse(Seq.empty), | ||
| None, | ||
| properties.toMap, | ||
| provider, | ||
| Map.empty, | ||
| None, | ||
| None, | ||
| options.toMap, | ||
| None, | ||
| orCreate = orCreate)) | ||
| val tableSpec = TableSpec(None, properties.toMap, provider, Map.empty, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| None, None, None, false) | ||
| runCommand(ReplaceTableAsSelect( | ||
| UnresolvedDBObjectName(tableName, isNamespace = false), | ||
| partitioning.getOrElse(Seq.empty), logicalPlan, tableSpec, writeOptions = options.toMap, | ||
| orCreate = orCreate)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's use named parameter here:
TableSpec(bucketSpec = None, ...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed