-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SPARK-33902][SQL] Support CREATE TABLE LIKE for V2 #54809
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
base: master
Are you sure you want to change the base?
Changes from all commits
f26c1a6
a13cfbb
ab99578
9f92a9b
36a95d0
1755580
8fdaf69
4788469
7912780
b0a26e4
a71107d
5687e8b
6fefd98
628cc31
3b94076
9fdf2fa
f5d3d25
74a7ff1
f4a1cd3
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 |
|---|---|---|
|
|
@@ -293,6 +293,17 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager) | |
| c | ||
| } | ||
|
|
||
| // For CREATE TABLE LIKE, use the v1 command if both the target and source are in the session | ||
| // catalog (or a V1-compatible catalog extension). If source is in a different catalog, fall | ||
| // through to the V2 execution path (CreateTableLikeExec via DataSourceV2Strategy). | ||
| case CreateTableLike( | ||
|
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. What does this mean for DSv2 connectors that override the session catalog?
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. An example is Iceberg session catalog.
Member
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. yea, agree, we should add a test for sessionCatalog
Member
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. Good catch. When a connector like Iceberg overrides the session catalog, the target resolves through ResolvedV1Identifier (since supportsV1Command returns true for the session catalog), but the source — a native Iceberg Table — does NOT match ResolvedV1TableOrViewIdentifier (which requires V1Table). So ResolveSessionCatalog falls through and CreateTableLikeExec handles it, passing the Iceberg Table directly. The target createTable call goes to V2SessionCatalog, which delegates to the Iceberg catalog extension. This should work, but deserves a test. I can add one if you'd like. |
||
| ResolvedV1Identifier(targetIdent), | ||
| ResolvedV1TableOrViewIdentifier(sourceIdent), | ||
| location, provider, serdeInfo, properties, ifNotExists) => | ||
| val fileFormat = buildStorageFormatFromSerdeInfo(location, serdeInfo) | ||
| CreateTableLikeCommand( | ||
| targetIdent, sourceIdent, fileFormat, provider, properties, ifNotExists) | ||
|
|
||
| case DropTable(ResolvedV1Identifier(ident), ifExists, purge) if conf.useV1Command => | ||
| DropTableCommand(ident, ifExists, isView = false, purge = purge) | ||
|
|
||
|
|
@@ -626,6 +637,15 @@ class ResolveSessionCatalog(val catalogManager: CatalogManager) | |
| CreateTableV1(tableDesc, mode, query) | ||
| } | ||
|
|
||
| private def buildStorageFormatFromSerdeInfo( | ||
| location: Option[String], | ||
| maybeSerdeInfo: Option[SerdeInfo]): CatalogStorageFormat = { | ||
| HiveSerDe.buildStorageFormat( | ||
| location, | ||
| maybeSerdeInfo, | ||
| si => QueryCompilationErrors.invalidFileFormatForStoredAsError(si)) | ||
| } | ||
|
|
||
| private def getStorageFormatAndProvider( | ||
| provider: Option[String], | ||
| options: Map[String, String], | ||
|
|
||
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.
can we have one single command (UnaryRunnableCommand)? I thought that's the preferred way now to reduce plan complexity in the different stages