Skip to content
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-31257][SPARK-33561][SQL] Unify create table syntax #28026

Closed
wants to merge 11 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,17 @@ statement
(RESTRICT | CASCADE)? #dropNamespace
| SHOW (DATABASES | NAMESPACES) ((FROM | IN) multipartIdentifier)?
(LIKE? pattern=STRING)? #showNamespaces
| createTableHeader ('(' colTypeList ')')? tableProvider
| createTableHeader ('(' colTypeList ')')? tableProvider?
rdblue marked this conversation as resolved.
Show resolved Hide resolved
createTableClauses
(AS? query)? #createTable
| createTableHeader ('(' columns=colTypeList ')')?
(commentSpec |
(PARTITIONED BY '(' partitionColumns=colTypeList ')' |
PARTITIONED BY partitionColumnNames=identifierList) |
bucketSpec |
skewSpec |
rowFormat |
createFileFormat |
locationSpec |
(TBLPROPERTIES tableProps=tablePropertyList))*
(AS? query)? #createHiveTable
| CREATE TABLE (IF NOT EXISTS)? target=tableIdentifier
LIKE source=tableIdentifier
(tableProvider |
rowFormat |
createFileFormat |
locationSpec |
(TBLPROPERTIES tableProps=tablePropertyList))* #createTableLike
| replaceTableHeader ('(' colTypeList ')')? tableProvider
| replaceTableHeader ('(' colTypeList ')')? tableProvider?
createTableClauses
(AS? query)? #replaceTable
| ANALYZE TABLE multipartIdentifier partitionSpec? COMPUTE STATISTICS
Expand Down Expand Up @@ -393,8 +382,11 @@ tableProvider

createTableClauses
:((OPTIONS options=tablePropertyList) |
(PARTITIONED BY partitioning=transformList) |
(PARTITIONED BY partitioning=partitionFieldList) |
cloud-fan marked this conversation as resolved.
Show resolved Hide resolved
skewSpec |
bucketSpec |
rowFormat |
createFileFormat |
locationSpec |
commentSpec |
(TBLPROPERTIES tableProps=tablePropertyList))*
Expand Down Expand Up @@ -741,8 +733,13 @@ namedExpressionSeq
: namedExpression (',' namedExpression)*
;

transformList
: '(' transforms+=transform (',' transforms+=transform)* ')'
partitionFieldList
: '(' fields+=partitionField (',' fields+=partitionField)* ')'
;

partitionField
rdblue marked this conversation as resolved.
Show resolved Hide resolved
: transform #partitionTransform
| colType #partitionColumn
;

transform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public interface TableCatalog extends CatalogPlugin {
*/
String PROP_LOCATION = "location";

/**
* A reserved property to specify a table was created with EXTERNAL.
*/
String PROP_EXTERNAL = "external";
rdblue marked this conversation as resolved.
Show resolved Hide resolved

/**
* A reserved property to specify the description of the table.
*/
Expand All @@ -61,6 +66,11 @@ public interface TableCatalog extends CatalogPlugin {
*/
String PROP_OWNER = "owner";

/**
* A prefix used to pass OPTIONS in table properties
*/
String OPTION_PREFIX = "option.";

/**
* List the tables in a namespace from the catalog.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
RenameTable(catalog.asTableCatalog, oldName.asIdentifier, newNameParts.asIdentifier)

case c @ CreateTableStatement(
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _) =>
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _, _, _) =>
assertNoNullTypeInSchema(c.tableSchema)
assertNoCharTypeInSchema(c.tableSchema)
CreateV2Table(
Expand All @@ -152,11 +152,11 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
c.tableSchema,
// convert the bucket spec and add it as a transform
c.partitioning ++ c.bucketSpec.map(_.asTransform),
convertTableProperties(c.properties, c.options, c.location, c.comment, c.provider),
convertTableProperties(c),
ignoreIfExists = c.ifNotExists)

case c @ CreateTableAsSelectStatement(
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _, _) =>
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _, _, _, _) =>
if (c.asSelect.resolved) {
assertNoNullTypeInSchema(c.asSelect.schema)
}
Expand All @@ -166,12 +166,12 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
// convert the bucket spec and add it as a transform
c.partitioning ++ c.bucketSpec.map(_.asTransform),
c.asSelect,
convertTableProperties(c.properties, c.options, c.location, c.comment, c.provider),
convertTableProperties(c),
writeOptions = c.writeOptions,
ignoreIfExists = c.ifNotExists)

case c @ ReplaceTableStatement(
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _) =>
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _, _) =>
assertNoNullTypeInSchema(c.tableSchema)
assertNoCharTypeInSchema(c.tableSchema)
ReplaceTable(
Expand All @@ -180,11 +180,11 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
c.tableSchema,
// convert the bucket spec and add it as a transform
c.partitioning ++ c.bucketSpec.map(_.asTransform),
convertTableProperties(c.properties, c.options, c.location, c.comment, c.provider),
convertTableProperties(c),
orCreate = c.orCreate)

case c @ ReplaceTableAsSelectStatement(
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _, _) =>
NonSessionCatalogAndTable(catalog, tbl), _, _, _, _, _, _, _, _, _, _, _) =>
if (c.asSelect.resolved) {
assertNoNullTypeInSchema(c.asSelect.schema)
}
Expand All @@ -194,7 +194,7 @@ class ResolveCatalogs(val catalogManager: CatalogManager)
// convert the bucket spec and add it as a transform
c.partitioning ++ c.bucketSpec.map(_.asTransform),
c.asSelect,
convertTableProperties(c.properties, c.options, c.location, c.comment, c.provider),
convertTableProperties(c),
writeOptions = c.writeOptions,
orCreate = c.orCreate)

Expand Down
Loading