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();
}
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'");
}
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());
}
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();
}
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);
}
Aggregations