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 ;
@@ -456,6 +460,22 @@ private static Expression toExpression(Object value)
456
460
@ Override
457
461
protected Node visitShowCreate (ShowCreate node , Void context )
458
462
{
463
+ if (node .getType () == SCHEMA ) {
464
+ CatalogSchemaName catalogSchemaName = createCatalogSchemaName (session , node , Optional .of (node .getName ()));
465
+ if (!metadataResolver .schemaExists (catalogSchemaName )) {
466
+ throw new SemanticException (MISSING_SCHEMA , node , "Schema '%s' does not exist" , catalogSchemaName );
467
+ }
468
+
469
+ Map <String , Object > properties = metadata .getSchemaProperties (session , catalogSchemaName );
470
+ Map <String , PropertyMetadata <?>> allSchemaProperties = metadata .getSchemaPropertyManager ().getAllProperties ().get (getConnectorIdOrThrow (session , metadata , catalogSchemaName .getCatalogName ()));
471
+ List <Property > propertyNodes = buildProperties ("schema " + catalogSchemaName , INVALID_SCHEMA_PROPERTY , properties , allSchemaProperties );
472
+ CreateSchema createSchema = new CreateSchema (
473
+ node .getName (),
474
+ false ,
475
+ propertyNodes );
476
+ return singleValueQuery ("Create Schema" , formatSql (createSchema , Optional .of (parameters )).trim ());
477
+ }
478
+
459
479
QualifiedObjectName objectName = createQualifiedObjectName (session , node , node .getName ());
460
480
Optional <ViewDefinition > viewDefinition = metadataResolver .getView (objectName );
461
481
Optional <MaterializedViewDefinition > materializedViewDefinition = metadataResolver .getMaterializedView (objectName );
@@ -495,7 +515,7 @@ protected Node visitShowCreate(ShowCreate node, Void context)
495
515
ConnectorTableMetadata connectorTableMetadata = metadata .getTableMetadata (session , tableHandle .get ()).getMetadata ();
496
516
Map <String , Object > properties = connectorTableMetadata .getProperties ();
497
517
Map <String , PropertyMetadata <?>> allTableProperties = metadata .getTablePropertyManager ().getAllProperties ().get (tableHandle .get ().getConnectorId ());
498
- List <Property > propertyNodes = buildProperties (objectName , Optional . empty () , INVALID_TABLE_PROPERTY , properties , allTableProperties );
518
+ List <Property > propertyNodes = buildProperties ("materialized view " + objectName , INVALID_TABLE_PROPERTY , properties , allTableProperties );
499
519
500
520
CreateMaterializedView createMaterializedView = new CreateMaterializedView (
501
521
Optional .empty (),
@@ -532,7 +552,7 @@ protected Node visitShowCreate(ShowCreate node, Void context)
532
552
List <TableElement > columns = connectorTableMetadata .getColumns ().stream ()
533
553
.filter (column -> !column .isHidden ())
534
554
.map (column -> {
535
- List <Property > propertyNodes = buildProperties (objectName , Optional .of (column .getName ()), INVALID_COLUMN_PROPERTY , column .getProperties (), allColumnProperties );
555
+ List <Property > propertyNodes = buildProperties (toQualifiedName ( objectName , Optional .of (column .getName () )), INVALID_COLUMN_PROPERTY , column .getProperties (), allColumnProperties );
536
556
return new ColumnDefinition (
537
557
QueryUtil .quotedIdentifier (column .getName ()),
538
558
column .getType ().getDisplayName (),
@@ -544,7 +564,7 @@ protected Node visitShowCreate(ShowCreate node, Void context)
544
564
545
565
Map <String , Object > properties = connectorTableMetadata .getProperties ();
546
566
Map <String , PropertyMetadata <?>> allTableProperties = metadata .getTablePropertyManager ().getAllProperties ().get (tableHandle .get ().getConnectorId ());
547
- List <Property > propertyNodes = buildProperties (objectName , Optional . empty () , INVALID_TABLE_PROPERTY , properties , allTableProperties );
567
+ List <Property > propertyNodes = buildProperties ("table " + objectName , INVALID_TABLE_PROPERTY , properties , allTableProperties );
548
568
549
569
columns .addAll (connectorTableMetadata .getTableConstraintsHolder ().getTableConstraints ()
550
570
.stream ()
@@ -646,7 +666,6 @@ protected Node visitShowCreateFunction(ShowCreateFunction node, Void context)
646
666
647
667
private List <Property > buildProperties (
648
668
Object objectName ,
649
- Optional <String > columnName ,
650
669
StandardErrorCode errorCode ,
651
670
Map <String , Object > properties ,
652
671
Map <String , PropertyMetadata <?>> allProperties )
@@ -661,15 +680,15 @@ private List<Property> buildProperties(
661
680
String propertyName = propertyEntry .getKey ();
662
681
Object value = propertyEntry .getValue ();
663
682
if (value == null ) {
664
- throw new PrestoException (errorCode , format ("Property %s for %s cannot have a null value" , propertyName , toQualifiedName ( objectName , columnName ) ));
683
+ throw new PrestoException (errorCode , format ("Property %s for %s cannot have a null value" , propertyName , objectName ));
665
684
}
666
685
667
686
PropertyMetadata <?> property = allProperties .get (propertyName );
668
687
if (!Primitives .wrap (property .getJavaType ()).isInstance (value )) {
669
688
throw new PrestoException (errorCode , format (
670
689
"Property %s for %s should have value of type %s, not %s" ,
671
690
propertyName ,
672
- toQualifiedName ( objectName , columnName ) ,
691
+ objectName ,
673
692
property .getJavaType ().getName (),
674
693
value .getClass ().getName ()));
675
694
}
0 commit comments