Skip to content

Commit

Permalink
Fix SHOW CREATE SCHEMA for connectors
Browse files Browse the repository at this point in the history
Before the change, SHOW CREATE SCHEMA did not work for almost all
connectors (except maybe for Hive, Iceberg, Blackhole and Memory).
  • Loading branch information
findepi committed Jul 20, 2021
1 parent 47163b8 commit b63e636
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -662,15 +662,15 @@ default Optional<ConnectorViewDefinition> getView(ConnectorSession session, Sche
*/
default Map<String, Object> getSchemaProperties(ConnectorSession session, CatalogSchemaName schemaName)
{
throw new TrinoException(NOT_SUPPORTED, "This connector does not support schema properties");
return Map.of();
}

/**
* Get the schema properties for the specified schema.
*/
default Optional<TrinoPrincipal> getSchemaOwner(ConnectorSession session, CatalogSchemaName schemaName)
{
throw new TrinoException(NOT_SUPPORTED, "This connector does not support schema ownership");
return Optional.empty();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ public Optional<TrinoPrincipal> getSchemaOwner(ConnectorSession session, Catalog
return Optional.empty();
}

@Override
public Map<String, Object> getSchemaProperties(ConnectorSession session, CatalogSchemaName schemaName)
{
return ImmutableMap.of();
}

@Override
public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ public void testViewAuthorizationForRole()
}

@Test
@Override
public void testShowCreateSchema()
{
Session admin = Session.builder(getSession())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public void testRenameTable()
}

@Test
@Override
public void testShowCreateSchema()
{
assertThat(computeActual("SHOW CREATE SCHEMA tpch").getOnlyValue().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ public Optional<TrinoPrincipal> getSchemaOwner(ConnectorSession session, Catalog
return Optional.empty();
}

@Override
public Map<String, Object> getSchemaProperties(ConnectorSession session, CatalogSchemaName schemaName)
{
return ImmutableMap.of();
}

@Override
public synchronized ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName schemaTableName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,14 @@ public void testWrittenStats()
assertUpdate("DROP TABLE " + tableName);
}

@Test
public void testShowCreateSchema()
{
String schemaName = getSession().getSchema().orElseThrow();
assertThat((String) computeScalar("SHOW CREATE SCHEMA " + schemaName))
.isEqualTo(format("CREATE SCHEMA %s.%s", getSession().getCatalog().orElseThrow(), schemaName));
}

@Test
public void testCreateSchema()
{
Expand All @@ -1101,6 +1109,8 @@ public void testCreateSchema()
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).doesNotContain(schemaName);
assertUpdate("CREATE SCHEMA " + schemaName);
assertThat(computeActual("SHOW SCHEMAS").getOnlyColumnAsSet()).contains(schemaName);
assertThat((String) computeScalar("SHOW CREATE SCHEMA " + schemaName))
.startsWith(format("CREATE SCHEMA %s.%s", getSession().getCatalog().orElseThrow(), schemaName));
assertQueryFails("CREATE SCHEMA " + schemaName, format("line 1:1: Schema '.*\\.%s' already exists", schemaName));
assertUpdate("DROP SCHEMA " + schemaName);
assertQueryFails("DROP SCHEMA " + schemaName, format("line 1:1: Schema '.*\\.%s' does not exist", schemaName));
Expand Down

0 comments on commit b63e636

Please sign in to comment.