-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14507] [SQL] EXTERNAL keyword in a CTAS statement is not allowed #13395
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 all commits
f613d9e
1e22d53
2615f67
c5cb32c
220a6e0
fa89081
27332df
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 |
|---|---|---|
|
|
@@ -936,7 +936,47 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { | |
| comment = comment) | ||
|
|
||
| selectQuery match { | ||
| case Some(q) => CreateTableAsSelectLogicalPlan(tableDesc, q, ifNotExists) | ||
| case Some(q) => | ||
| // Hive does not allow to use a CTAS statement to create a partitioned table. | ||
| if (tableDesc.partitionColumnNames.nonEmpty) { | ||
| val errorMessage = "A Create Table As Select (CTAS) statement is not allowed to " + | ||
| "create a partitioned table using Hive's file formats. " + | ||
|
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. Does dataSource support creating tables with Hive file formats (parquet, orc etc..) ? I think it does. Then
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. oh, at here, |
||
| "Please use the syntax of \"CREATE TABLE tableName USING dataSource " + | ||
| "OPTIONS (...) PARTITIONED BY ...\" to create a partitioned table through a " + | ||
| "CTAS statement." | ||
| throw operationNotAllowed(errorMessage, ctx) | ||
| } | ||
|
|
||
| // CTAS statement does not allow the EXTERNAL keyword. | ||
| if (external) { | ||
| val errorMessage = "CREATE EXTERNAL TABLE ... AS SELECT. " + | ||
| "Please remove the EXTERNAL keyword. As long as a user-specified location is " + | ||
| "provided, the data of the table will not be deleted when dropping the table." | ||
| throw operationNotAllowed(errorMessage, ctx) | ||
| } | ||
|
|
||
| val hasStorageProperties = (ctx.createFileFormat != null) || (ctx.rowFormat != null) | ||
| if (conf.convertCTAS && !hasStorageProperties) { | ||
| val mode = if (ifNotExists) SaveMode.Ignore else SaveMode.ErrorIfExists | ||
| val options = rowStorage.serdeProperties ++ fileStorage.serdeProperties | ||
| val optionsWithPath = if (location.isDefined) { | ||
| options + ("path" -> location.get) | ||
| } else { | ||
| options | ||
| } | ||
| CreateTableUsingAsSelect( | ||
| tableIdent = tableDesc.identifier, | ||
| provider = conf.defaultDataSourceName, | ||
| temporary = false, | ||
| partitionColumns = tableDesc.partitionColumnNames.toArray, | ||
| bucketSpec = None, | ||
| mode = mode, | ||
| options = optionsWithPath, | ||
| q | ||
| ) | ||
| } else { | ||
| CreateTableAsSelectLogicalPlan(tableDesc, q, ifNotExists) | ||
| } | ||
| case None => CreateTableCommand(tableDesc, ifNotExists) | ||
| } | ||
| } | ||
|
|
||
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.
nit:
CREATE TABLE ... AS SELECTto be consistent with other places.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 it's OK to just leave this; CTAS is a pretty common term