use of com.facebook.presto.spi.ConnectorNewTableLayout 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"), TABLE_SUPPORTS_DELTA_DELETE, false));
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(), 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, 0, OptionalInt.of(0), OptionalInt.empty(), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, 1, OptionalInt.of(1), OptionalInt.empty(), false)));
assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(32));
assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
metadata.dropTable(SESSION, tableHandle);
}
use of com.facebook.presto.spi.ConnectorNewTableLayout in project presto by prestodb.
the class ConnectorMetadata method getInsertLayout.
/**
* Get the physical layout for a inserting into an existing table.
*/
default Optional<ConnectorNewTableLayout> getInsertLayout(ConnectorSession session, ConnectorTableHandle tableHandle) {
List<ConnectorTableLayout> layouts = getTableLayouts(session, tableHandle, new Constraint<>(TupleDomain.all(), map -> true), Optional.empty()).stream().map(ConnectorTableLayoutResult::getTableLayout).filter(layout -> layout.getTablePartitioning().isPresent()).collect(toList());
if (layouts.isEmpty()) {
return Optional.empty();
}
if (layouts.size() > 1) {
throw new PrestoException(NOT_SUPPORTED, "Tables with multiple layouts can not be written");
}
ConnectorTableLayout layout = layouts.get(0);
ConnectorPartitioningHandle partitioningHandle = layout.getTablePartitioning().get().getPartitioningHandle();
Map<ColumnHandle, String> columnNamesByHandle = getColumnHandles(session, tableHandle).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
List<String> partitionColumns = layout.getTablePartitioning().get().getPartitioningColumns().stream().map(columnNamesByHandle::get).collect(toList());
return Optional.of(new ConnectorNewTableLayout(partitioningHandle, partitionColumns));
}
use of com.facebook.presto.spi.ConnectorNewTableLayout in project presto by prestodb.
the class BlackHoleMetadata method getNewTableLayout.
@Override
public Optional<ConnectorNewTableLayout> getNewTableLayout(ConnectorSession connectorSession, ConnectorTableMetadata tableMetadata) {
List<String> distributeColumns = (List<String>) tableMetadata.getProperties().get(DISTRIBUTED_ON);
if (distributeColumns.isEmpty()) {
return Optional.empty();
}
Set<String> undefinedColumns = Sets.difference(ImmutableSet.copyOf(distributeColumns), tableMetadata.getColumns().stream().map(ColumnMetadata::getName).collect(toSet()));
if (!undefinedColumns.isEmpty()) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Distribute columns not defined on table: " + undefinedColumns);
}
return Optional.of(new ConnectorNewTableLayout(BlackHolePartitioningHandle.INSTANCE, distributeColumns));
}
use of com.facebook.presto.spi.ConnectorNewTableLayout in project presto by prestodb.
the class HiveMetadata method getPreferredShuffleLayoutForInsert.
@Override
public Optional<ConnectorNewTableLayout> getPreferredShuffleLayoutForInsert(ConnectorSession session, ConnectorTableHandle tableHandle) {
HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
SchemaTableName tableName = hiveTableHandle.getSchemaTableName();
MetastoreContext metastoreContext = getMetastoreContext(session);
Table table = metastore.getTable(metastoreContext, tableName.getSchemaName(), tableName.getTableName()).orElseThrow(() -> new TableNotFoundException(tableName));
Optional<HiveBucketHandle> hiveBucketHandle = getHiveBucketHandle(table);
if (hiveBucketHandle.isPresent()) {
// and there is no additional preferred shuffle partitioning
return Optional.empty();
}
if (!isShufflePartitionedColumnsForTableWriteEnabled(session) || table.getPartitionColumns().isEmpty()) {
return Optional.empty();
}
// TODO: the shuffle partitioning could use a better hash function (instead of Hive bucket function)
HivePartitioningHandle partitioningHandle = createHiveCompatiblePartitioningHandle(SHUFFLE_MAX_PARALLELISM_FOR_PARTITIONED_TABLE_WRITE, table.getPartitionColumns().stream().map(Column::getType).collect(toList()), OptionalInt.empty());
List<String> partitionedBy = table.getPartitionColumns().stream().map(Column::getName).collect(toList());
return Optional.of(new ConnectorNewTableLayout(partitioningHandle, partitionedBy));
}
use of com.facebook.presto.spi.ConnectorNewTableLayout in project presto by prestodb.
the class HiveMetadata method getPreferredShuffleLayoutForNewTable.
@Override
public Optional<ConnectorNewTableLayout> getPreferredShuffleLayoutForNewTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
validatePartitionColumns(tableMetadata);
validateBucketColumns(tableMetadata);
Optional<HiveBucketProperty> bucketProperty = getBucketProperty(tableMetadata.getProperties());
if (bucketProperty.isPresent()) {
// and there is no additional preferred shuffle partitioning
return Optional.empty();
}
List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties());
if (!isShufflePartitionedColumnsForTableWriteEnabled(session) || partitionedBy.isEmpty()) {
return Optional.empty();
}
List<HiveColumnHandle> columnHandles = getColumnHandles(tableMetadata, ImmutableSet.copyOf(partitionedBy), typeTranslator);
Map<String, HiveColumnHandle> columnHandlesByName = Maps.uniqueIndex(columnHandles, HiveColumnHandle::getName);
List<Column> partitionColumns = partitionedBy.stream().map(columnHandlesByName::get).map(columnHandle -> columnHandleToColumn(session, columnHandle)).collect(toList());
// TODO: the shuffle partitioning could use a better hash function (instead of Hive bucket function)
HivePartitioningHandle partitioningHandle = createHiveCompatiblePartitioningHandle(SHUFFLE_MAX_PARALLELISM_FOR_PARTITIONED_TABLE_WRITE, partitionColumns.stream().map(Column::getType).collect(toList()), OptionalInt.empty());
return Optional.of(new ConnectorNewTableLayout(partitioningHandle, partitionedBy));
}
Aggregations