|
53 | 53 | import com.facebook.presto.sql.tree.ConstraintSpecification;
|
54 | 54 | import com.facebook.presto.sql.tree.CreateFunction;
|
55 | 55 | import com.facebook.presto.sql.tree.CreateMaterializedView;
|
| 56 | +import com.facebook.presto.sql.tree.CreateSchema; |
56 | 57 | import com.facebook.presto.sql.tree.CreateTable;
|
57 | 58 | import com.facebook.presto.sql.tree.CreateView;
|
58 | 59 | import com.facebook.presto.sql.tree.DoubleLiteral;
|
|
113 | 114 | import static com.facebook.presto.metadata.MetadataUtil.createCatalogSchemaName;
|
114 | 115 | import static com.facebook.presto.metadata.MetadataUtil.createQualifiedName;
|
115 | 116 | import static com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName;
|
| 117 | +import static com.facebook.presto.metadata.MetadataUtil.getConnectorIdOrThrow; |
116 | 118 | import static com.facebook.presto.metadata.SessionFunctionHandle.SESSION_NAMESPACE;
|
117 | 119 | import static com.facebook.presto.spi.StandardErrorCode.FUNCTION_NOT_FOUND;
|
118 | 120 | import static com.facebook.presto.spi.StandardErrorCode.GENERIC_USER_ERROR;
|
119 | 121 | import static com.facebook.presto.spi.StandardErrorCode.INVALID_COLUMN_PROPERTY;
|
| 122 | +import static com.facebook.presto.spi.StandardErrorCode.INVALID_SCHEMA_PROPERTY; |
120 | 123 | import static com.facebook.presto.spi.StandardErrorCode.INVALID_TABLE_PROPERTY;
|
121 | 124 | import static com.facebook.presto.sql.ExpressionUtils.combineConjuncts;
|
122 | 125 | import static com.facebook.presto.sql.QueryUtil.aliased;
|
|
151 | 154 | import static com.facebook.presto.sql.tree.RoutineCharacteristics.Language;
|
152 | 155 | import static com.facebook.presto.sql.tree.RoutineCharacteristics.NullCallClause;
|
153 | 156 | import static com.facebook.presto.sql.tree.ShowCreate.Type.MATERIALIZED_VIEW;
|
| 157 | +import static com.facebook.presto.sql.tree.ShowCreate.Type.SCHEMA; |
154 | 158 | import static com.facebook.presto.sql.tree.ShowCreate.Type.TABLE;
|
155 | 159 | import static com.facebook.presto.sql.tree.ShowCreate.Type.VIEW;
|
156 | 160 | import static com.facebook.presto.util.AnalyzerUtil.createParsingOptions;
|
@@ -581,6 +585,22 @@ else if (constraint instanceof UniqueConstraint) {
|
581 | 585 | return singleValueQuery("Create Table", formatSql(createTable, Optional.of(parameters)).trim());
|
582 | 586 | }
|
583 | 587 |
|
| 588 | + if (node.getType() == SCHEMA) { |
| 589 | + CatalogSchemaName catalogSchemaName = createCatalogSchemaName(session, node, Optional.of(node.getName())); |
| 590 | + if (!metadataResolver.schemaExists(catalogSchemaName)) { |
| 591 | + throw new SemanticException(MISSING_SCHEMA, node, "Schema '%s' does not exist", catalogSchemaName); |
| 592 | + } |
| 593 | + |
| 594 | + Map<String, Object> properties = metadata.getSchemaProperties(session, catalogSchemaName); |
| 595 | + Map<String, PropertyMetadata<?>> allTableProperties = metadata.getSchemaPropertyManager().getAllProperties().get(getConnectorIdOrThrow(session, metadata, catalogSchemaName.getCatalogName())); |
| 596 | + List<Property> propertyNodes = buildProperties(objectName, Optional.empty(), INVALID_SCHEMA_PROPERTY, properties, allTableProperties); |
| 597 | + CreateSchema createSchema = new CreateSchema( |
| 598 | + node.getName(), |
| 599 | + false, |
| 600 | + propertyNodes); |
| 601 | + return singleValueQuery("Create Schema", formatSql(createSchema, Optional.of(parameters)).trim()); |
| 602 | + } |
| 603 | + |
584 | 604 | throw new UnsupportedOperationException("SHOW CREATE only supported for tables and views");
|
585 | 605 | }
|
586 | 606 |
|
|
0 commit comments