Search in sources :

Example 1 with SchemaTablePrefix

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());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) Test(org.testng.annotations.Test)

Example 2 with SchemaTablePrefix

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()));
}
Also used : SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Example 3 with SchemaTablePrefix

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());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) Test(org.testng.annotations.Test)

Example 4 with SchemaTablePrefix

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));
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Example 5 with SchemaTablePrefix

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);
}
Also used : ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) MetadataUtil.toSchemaTableName(com.facebook.presto.metadata.MetadataUtil.toSchemaTableName) SchemaTableName(com.facebook.presto.spi.SchemaTableName) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) LinkedHashMap(java.util.LinkedHashMap) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorId(com.facebook.presto.spi.ConnectorId)

Aggregations

SchemaTablePrefix (com.facebook.presto.spi.SchemaTablePrefix)14 SchemaTableName (com.facebook.presto.spi.SchemaTableName)12 Test (org.testng.annotations.Test)10 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)9 ImmutableList (com.google.common.collect.ImmutableList)8 List (java.util.List)8 ConnectorSession (com.facebook.presto.spi.ConnectorSession)6 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ConnectorId (com.facebook.presto.spi.ConnectorId)4 ConnectorViewDefinition (com.facebook.presto.spi.ConnectorViewDefinition)4 ArrayList (java.util.ArrayList)4 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)3 Collectors.toList (java.util.stream.Collectors.toList)3 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)2 MetadataUtil.toSchemaTableName (com.facebook.presto.metadata.MetadataUtil.toSchemaTableName)2 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)2 LinkedHashMap (java.util.LinkedHashMap)2 SystemColumnHandle.toSystemColumnHandles (com.facebook.presto.connector.system.SystemColumnHandle.toSystemColumnHandles)1