use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.
the class TestMemoryMetadata method testViews.
@Test
public void testViews() {
SchemaTableName test1 = new SchemaTableName("test", "test_view1");
ConnectorTableMetadata viewMetadata1 = new ConnectorTableMetadata(test1, ImmutableList.of(new ColumnMetadata("a", BIGINT)));
SchemaTableName test2 = new SchemaTableName("test", "test_view2");
ConnectorTableMetadata viewMetadata2 = new ConnectorTableMetadata(test2, ImmutableList.of(new ColumnMetadata("a", BIGINT)));
// create schema
metadata.createSchema(SESSION, "test", ImmutableMap.of());
// create views
metadata.createView(SESSION, viewMetadata1, "test1", false);
metadata.createView(SESSION, viewMetadata2, "test2", false);
// verify listing
List<SchemaTableName> list = metadata.listViews(SESSION, "test");
assertEqualsIgnoreOrder(list, ImmutableList.of(test1, test2));
// verify getting data
Map<SchemaTableName, ConnectorViewDefinition> views = metadata.getViews(SESSION, new SchemaTablePrefix("test"));
assertEquals(views.keySet(), ImmutableSet.of(test1, test2));
assertEquals(views.get(test1).getViewData(), "test1");
assertEquals(views.get(test2).getViewData(), "test2");
// all schemas
Map<SchemaTableName, ConnectorViewDefinition> allViews = metadata.getViews(SESSION, new SchemaTablePrefix());
assertEquals(allViews.keySet(), ImmutableSet.of(test1, test2));
// exact match on one schema and table
Map<SchemaTableName, ConnectorViewDefinition> exactMatchView = metadata.getViews(SESSION, new SchemaTablePrefix("test", "test_view1"));
assertEquals(exactMatchView.keySet(), ImmutableSet.of(test1));
// non-existent table
Map<SchemaTableName, ConnectorViewDefinition> nonexistentTableView = metadata.getViews(SESSION, new SchemaTablePrefix("test", "nonexistenttable"));
assertTrue(nonexistentTableView.isEmpty());
// non-existent schema
Map<SchemaTableName, ConnectorViewDefinition> nonexistentSchemaView = metadata.getViews(SESSION, new SchemaTablePrefix("nonexistentschema"));
assertTrue(nonexistentSchemaView.isEmpty());
// drop first view
metadata.dropView(SESSION, test1);
views = metadata.getViews(SESSION, new SchemaTablePrefix("test"));
assertEquals(views.keySet(), ImmutableSet.of(test2));
// drop second view
metadata.dropView(SESSION, test2);
views = metadata.getViews(SESSION, new SchemaTablePrefix("test"));
assertTrue(views.isEmpty());
// verify listing everything
views = metadata.getViews(SESSION, new SchemaTablePrefix());
assertTrue(views.isEmpty());
}
use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.
the class TestRaptorMetadata method testListTableColumns.
@Test
public void testListTableColumns() {
metadata.createTable(SESSION, getOrdersTable(), false);
Map<SchemaTableName, List<ColumnMetadata>> columns = metadata.listTableColumns(SESSION, new SchemaTablePrefix());
assertEquals(columns, ImmutableMap.of(DEFAULT_TEST_ORDERS, getOrdersTable().getColumns()));
}
use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.
the class TestRaptorMetadata method testViews.
@Test
public void testViews() {
ConnectorTableMetadata viewMetadata1 = new ConnectorTableMetadata(new SchemaTableName("test", "test_view1"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
ConnectorTableMetadata viewMetadata2 = new ConnectorTableMetadata(new SchemaTableName("test", "test_view2"), ImmutableList.of(new ColumnMetadata("a", BIGINT)));
SchemaTableName test1 = viewMetadata1.getTable();
SchemaTableName test2 = viewMetadata2.getTable();
// create views
metadata.createView(SESSION, viewMetadata1, "test1", false);
metadata.createView(SESSION, viewMetadata2, "test2", false);
// verify listing
List<SchemaTableName> list = metadata.listViews(SESSION, "test");
assertEqualsIgnoreOrder(list, ImmutableList.of(test1, test2));
// verify getting data
Map<SchemaTableName, ConnectorViewDefinition> views = metadata.getViews(SESSION, new SchemaTablePrefix("test"));
assertEquals(views.keySet(), ImmutableSet.of(test1, test2));
assertEquals(views.get(test1).getViewData(), "test1");
assertEquals(views.get(test2).getViewData(), "test2");
// drop first view
metadata.dropView(SESSION, test1);
views = metadata.getViews(SESSION, new SchemaTablePrefix("test"));
assertEquals(views.keySet(), ImmutableSet.of(test2));
// drop second view
metadata.dropView(SESSION, test2);
views = metadata.getViews(SESSION, new SchemaTablePrefix("test"));
assertTrue(views.isEmpty());
// verify listing everything
views = metadata.getViews(SESSION, new SchemaTablePrefix());
assertTrue(views.isEmpty());
}
use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.
the class TestJdbcMetadata method testListTableColumns.
@Test
public void testListTableColumns() {
SchemaTableName tpchOrders = new SchemaTableName("tpch", "orders");
ImmutableList<ColumnMetadata> tpchOrdersColumnMetadata = ImmutableList.of(ColumnMetadata.builder().setName("orderkey").setType(BIGINT).setNullable(false).build(), ColumnMetadata.builder().setName("custkey").setType(BIGINT).setNullable(true).build());
SchemaTableName tpchLineItem = new SchemaTableName("tpch", "lineitem");
ImmutableList<ColumnMetadata> tpchLineItemColumnMetadata = ImmutableList.of(ColumnMetadata.builder().setName("orderkey").setType(BIGINT).setNullable(false).build(), ColumnMetadata.builder().setName("partkey").setType(BIGINT).setNullable(true).build());
// List columns for a given schema and table
Map<SchemaTableName, List<ColumnMetadata>> tpchOrdersColumns = metadata.listTableColumns(SESSION, new SchemaTablePrefix("tpch", "orders"));
assertThat(tpchOrdersColumns).containsOnly(entry(tpchOrders, tpchOrdersColumnMetadata));
// List columns for a given schema
Map<SchemaTableName, List<ColumnMetadata>> tpchColumns = metadata.listTableColumns(SESSION, new SchemaTablePrefix("tpch"));
assertThat(tpchColumns).containsOnly(entry(tpchOrders, tpchOrdersColumnMetadata), entry(tpchLineItem, tpchLineItemColumnMetadata));
}
use of com.facebook.presto.spi.SchemaTablePrefix in project presto by prestodb.
the class MetadataManager method getViews.
@Override
public Map<QualifiedObjectName, ViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
Optional<CatalogMetadata> catalog = getOptionalCatalogMetadata(session, prefix.getCatalogName());
Map<QualifiedObjectName, ViewDefinition> views = new LinkedHashMap<>();
if (catalog.isPresent()) {
CatalogMetadata catalogMetadata = catalog.get();
SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix();
for (ConnectorId connectorId : catalogMetadata.listConnectorIds()) {
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
for (Entry<SchemaTableName, ConnectorViewDefinition> entry : metadata.getViews(connectorSession, tablePrefix).entrySet()) {
QualifiedObjectName viewName = new QualifiedObjectName(prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName());
views.put(viewName, deserializeView(entry.getValue().getViewData()));
}
}
}
return ImmutableMap.copyOf(views);
}
Aggregations