-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-36902][SQL] Migrate CreateTableAsSelectStatement to v2 command #34667
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3df03a4
[SPARK-36902][SQL] Migrate CreateTableAsSelectStatement to v2 command
dchvn 8428ce8
remove unused code
dchvn bb72f45
label the arguments of TableSpec
dchvn d9fa8a6
refactor
dchvn 729cc22
fix catalog
dchvn 616ed90
fix scala style
dchvn 9ce81a6
fix namespaces
dchvn cba6519
deduplicate
dchvn 5186f81
discard location and provider from properties
dchvn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import org.apache.spark.sql.catalyst.TableIdentifier | |
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, ReplaceTableAsSelect, TableSpec} | ||
import org.apache.spark.sql.catalyst.plans.logical.{AppendData, CreateTableAsSelect, 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._ | ||
|
@@ -327,14 +327,24 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) { | |
supportsExtract, catalogManager, dsOptions) | ||
|
||
val location = Option(dsOptions.get("path")).map(TableCatalog.PROP_LOCATION -> _) | ||
|
||
val tableSpec = TableSpec( | ||
bucketSpec = None, | ||
properties = Map(TableCatalog.PROP_PROVIDER -> source) ++ location, | ||
provider = Some(source), | ||
options = Map.empty, | ||
location = extraOptions.get("path"), | ||
comment = extraOptions.get(TableCatalog.PROP_COMMENT), | ||
serde = None, | ||
external = false) | ||
runCommand(df.sparkSession) { | ||
CreateTableAsSelect( | ||
catalog, | ||
ident, | ||
UnresolvedDBObjectName( | ||
catalog.name :: ident.name :: Nil, | ||
isNamespace = false | ||
), | ||
partitioningAsV2, | ||
df.queryExecution.analyzed, | ||
Map(TableCatalog.PROP_PROVIDER -> source) ++ location, | ||
tableSpec, | ||
finalOptions, | ||
ignoreIfExists = createMode == SaveMode.Ignore) | ||
} | ||
|
@@ -607,20 +617,23 @@ final class DataFrameWriter[T] private[sql](ds: Dataset[T]) { | |
// We have a potential race condition here in AppendMode, if the table suddenly gets | ||
// created between our existence check and physical execution, but this can't be helped | ||
// in any case. | ||
CreateTableAsSelectStatement( | ||
nameParts, | ||
df.queryExecution.analyzed, | ||
val tableSpec = TableSpec( | ||
bucketSpec = None, | ||
properties = Map.empty, | ||
provider = Some(source), | ||
options = Map.empty, | ||
location = extraOptions.get("path"), | ||
comment = extraOptions.get(TableCatalog.PROP_COMMENT), | ||
serde = None, | ||
external = false) | ||
|
||
CreateTableAsSelect( | ||
UnresolvedDBObjectName(nameParts, isNamespace = false), | ||
partitioningAsV2, | ||
None, | ||
Map.empty, | ||
Some(source), | ||
df.queryExecution.analyzed, | ||
tableSpec, | ||
Map.empty, | ||
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. @huaxingao can you fix this similar bug as well when you open the PR? |
||
extraOptions.get("path"), | ||
extraOptions.get(TableCatalog.PROP_COMMENT), | ||
extraOptions.toMap, | ||
None, | ||
ifNotExists = other == SaveMode.Ignore, | ||
external = false) | ||
other == SaveMode.Ignore) | ||
} | ||
|
||
runCommand(df.sparkSession) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this should not include the location property. We already specify it in
TableSpec.location
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.
Actually, we should put
Map.empty
here. provide is also specified inTableSpec.provider