Search in sources :

Example 6 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class ExampleMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : listTables(session, prefix)) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
Also used : List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 7 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestMemoryMetadata method tableIsCreatedAfterCommits.

@Test
public void tableIsCreatedAfterCommits() {
    assertThatNoTableIsCreated();
    SchemaTableName schemaTableName = new SchemaTableName("default", "temp_table");
    ConnectorOutputTableHandle table = metadata.beginCreateTable(SESSION, new ConnectorTableMetadata(schemaTableName, ImmutableList.of(), ImmutableMap.of()), Optional.empty());
    metadata.finishCreateTable(SESSION, table, ImmutableList.of());
    List<SchemaTableName> tables = metadata.listTables(SESSION, null);
    assertTrue(tables.size() == 1, "Expected only one table.");
    assertTrue(tables.get(0).getTableName().equals("temp_table"), "Expected table with name 'temp_table'");
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 8 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class RaptorMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
    SchemaTableName tableName = new SchemaTableName(handle.getSchemaName(), handle.getTableName());
    List<TableColumn> tableColumns = dao.listTableColumns(handle.getTableId());
    if (tableColumns.isEmpty()) {
        throw new TableNotFoundException(tableName);
    }
    ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
    SortedMap<Integer, String> bucketing = new TreeMap<>();
    SortedMap<Integer, String> ordering = new TreeMap<>();
    for (TableColumn column : tableColumns) {
        if (column.isTemporal()) {
            properties.put(TEMPORAL_COLUMN_PROPERTY, column.getColumnName());
        }
        column.getBucketOrdinal().ifPresent(bucketOrdinal -> bucketing.put(bucketOrdinal, column.getColumnName()));
        column.getSortOrdinal().ifPresent(sortOrdinal -> ordering.put(sortOrdinal, column.getColumnName()));
    }
    if (!bucketing.isEmpty()) {
        properties.put(BUCKETED_ON_PROPERTY, ImmutableList.copyOf(bucketing.values()));
    }
    if (!ordering.isEmpty()) {
        properties.put(ORDERING_PROPERTY, ImmutableList.copyOf(ordering.values()));
    }
    handle.getBucketCount().ifPresent(bucketCount -> properties.put(BUCKET_COUNT_PROPERTY, bucketCount));
    handle.getDistributionName().ifPresent(distributionName -> properties.put(DISTRIBUTION_NAME_PROPERTY, distributionName));
    // Only display organization property if set
    if (handle.isOrganized()) {
        properties.put(ORGANIZED_PROPERTY, true);
    }
    List<ColumnMetadata> columns = tableColumns.stream().map(TableColumn::toColumnMetadata).collect(toCollection(ArrayList::new));
    columns.add(hiddenColumn(SHARD_UUID_COLUMN_NAME, SHARD_UUID_COLUMN_TYPE));
    columns.add(hiddenColumn(BUCKET_NUMBER_COLUMN_NAME, INTEGER));
    return new ConnectorTableMetadata(tableName, columns, properties.build());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TreeMap(java.util.TreeMap) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) ImmutableMap(com.google.common.collect.ImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 9 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestRaptorConnector method createTable.

private long createTable(String name) {
    ConnectorTransactionHandle transaction = connector.beginTransaction(READ_COMMITTED, false);
    connector.getMetadata(transaction).createTable(SESSION, new ConnectorTableMetadata(new SchemaTableName("test", name), ImmutableList.of(new ColumnMetadata("id", BIGINT))));
    connector.commit(transaction);
    transaction = connector.beginTransaction(READ_COMMITTED, false);
    ConnectorTableHandle tableHandle = getTableHandle(connector.getMetadata(transaction), name);
    connector.commit(transaction);
    return ((RaptorTableHandle) tableHandle).getTableId();
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle)

Example 10 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestRaptorMetadata method testCreateBucketedTableAsSelect.

@Test
public void testCreateBucketedTableAsSelect() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 32, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey", "custkey")));
    ConnectorNewTableLayout layout = metadata.getNewTableLayout(SESSION, ordersTable).get();
    assertEquals(layout.getPartitionColumns(), ImmutableList.of("orderkey", "custkey"));
    assertInstanceOf(layout.getPartitioning(), RaptorPartitioningHandle.class);
    RaptorPartitioningHandle partitioning = (RaptorPartitioningHandle) layout.getPartitioning();
    assertEquals(partitioning.getDistributionId(), 1);
    ConnectorOutputTableHandle outputHandle = metadata.beginCreateTable(SESSION, ordersTable, Optional.of(layout));
    metadata.finishCreateTable(SESSION, outputHandle, ImmutableList.of());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderkey", BIGINT, 1, OptionalInt.of(0), OptionalInt.empty(), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, OptionalInt.of(1), OptionalInt.empty(), false)));
    assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(32));
    assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
    metadata.dropTable(SESSION, tableHandle);
}
Also used : ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) RaptorPartitioningHandle(com.facebook.presto.raptor.RaptorPartitioningHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)60 SchemaTableName (com.facebook.presto.spi.SchemaTableName)28 Test (org.testng.annotations.Test)28 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)26 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)23 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)17 ImmutableList (com.google.common.collect.ImmutableList)14 ConnectorSession (com.facebook.presto.spi.ConnectorSession)13 ColumnHandle (com.facebook.presto.spi.ColumnHandle)12 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 List (java.util.List)11 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)10 RaptorTableHandle (com.facebook.presto.raptor.RaptorTableHandle)8 PrestoException (com.facebook.presto.spi.PrestoException)7 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)6 Constraint (com.facebook.presto.spi.Constraint)6 Path (org.apache.hadoop.fs.Path)6 Table (com.facebook.presto.hive.metastore.Table)5 ConnectorPageSink (com.facebook.presto.spi.ConnectorPageSink)5