-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14592][SQL] Native support for CREATE TABLE LIKE DDL command #12362
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2a0a474
init import.
viirya 6525695
Make it work.
viirya 82a3ee8
Reset storage location.
viirya a23559d
Modify comment.
viirya 3c43c16
Merge remote-tracking branch 'upstream/master' into create-table-like
viirya def9039
Fix it.
viirya 0bcafcd
Fix scala style.
viirya ec589b8
Disable create_like_tbl_props.
viirya 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ import org.apache.spark.sql.catalyst.parser._ | |
| import org.apache.spark.sql.catalyst.parser.SqlBaseParser._ | ||
| import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan | ||
| import org.apache.spark.sql.execution.SparkSqlAstBuilder | ||
| import org.apache.spark.sql.execution.command.CreateTable | ||
| import org.apache.spark.sql.execution.command.{CreateTable, CreateTableLike} | ||
| import org.apache.spark.sql.hive.{CreateTableAsSelect => CTAS, CreateViewAsSelect => CreateView} | ||
| import org.apache.spark.sql.hive.{HiveGenericUDTF, HiveMetastoreTypes, HiveSerDe} | ||
| import org.apache.spark.sql.hive.HiveShim.HiveFunctionWrapper | ||
|
|
@@ -236,6 +236,15 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a [[CreateTableLike]] command. | ||
| */ | ||
| override def visitCreateTableLike(ctx: CreateTableLikeContext): LogicalPlan = withOrigin(ctx) { | ||
| val targetTable = visitTableIdentifier(ctx.target) | ||
| val sourceTable = visitTableIdentifier(ctx.source) | ||
| CreateTableLike(targetTable, sourceTable, ctx.EXISTS != null) | ||
|
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. much better! |
||
| } | ||
|
|
||
| /** | ||
| * Create or replace a view. This creates a [[CreateViewAsSelect]] command. | ||
| * | ||
|
|
||
This file contains hidden or 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
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.
instead of doing a copy and change some variables that we need to update, how about we create a new
CatalogTableand put the stuff that we need to retain from the source table? Then it's more clear that what we retained for theCREATE TABLE LIKEcommand.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.
Thanks. But I do this to address previous comment. The main concern is that we may add more fields into
CatalogTable. If so, we will need to revisit here to add these fields.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 I am neutral on this.
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.
My concern is that we may add more fields into
CatalogTablewhich we don't want to retain, likelastAccessTime, I'm not sure which way is safer too, cc @andrewor14There 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.
Your concern is correct. But I think most fields in source table should be retained. Only few exceptions like
lastAccessTime.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.
@dilipbiswal and I also hit the same issue when doing the
Describe Table. At the end, we decided to avoid adding more fields intoCatalogTable. Will follow the discussion in this thread. Thanks!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 things like
lastAccessTimeare exceptions. If we don't do copy here then we might forget to copy a new field that we add toCatalogTable.