use of com.facebook.presto.raptor.metadata.TableColumn in project presto by prestodb.
the class TestShardOrganizerUtil method getShardIndexInfo.
private static List<ShardIndexInfo> getShardIndexInfo(Table tableInfo, List<ShardInfo> shards, TableColumn temporalColumn, Optional<List<TableColumn>> sortColumns) {
long tableId = tableInfo.getTableId();
Type temporalType = temporalColumn.getDataType();
ImmutableList.Builder<ShardIndexInfo> builder = ImmutableList.builder();
for (ShardInfo shard : shards) {
ColumnStats temporalColumnStats = shard.getColumnStats().stream().filter(columnStats -> columnStats.getColumnId() == temporalColumn.getColumnId()).findFirst().get();
if (temporalColumnStats.getMin() == null || temporalColumnStats.getMax() == null) {
continue;
}
Optional<ShardRange> sortRange = Optional.empty();
if (sortColumns.isPresent()) {
Map<Long, ColumnStats> columnIdToStats = Maps.uniqueIndex(shard.getColumnStats(), ColumnStats::getColumnId);
ImmutableList.Builder<Type> typesBuilder = ImmutableList.builder();
ImmutableList.Builder<Object> minBuilder = ImmutableList.builder();
ImmutableList.Builder<Object> maxBuilder = ImmutableList.builder();
boolean isShardEligible = true;
for (TableColumn sortColumn : sortColumns.get()) {
ColumnStats columnStats = columnIdToStats.get(sortColumn.getColumnId());
typesBuilder.add(sortColumn.getDataType());
if (columnStats.getMin() == null || columnStats.getMax() == null) {
isShardEligible = false;
break;
}
minBuilder.add(columnStats.getMin());
maxBuilder.add(columnStats.getMax());
}
if (!isShardEligible) {
continue;
}
List<Type> types = typesBuilder.build();
List<Object> minValues = minBuilder.build();
List<Object> maxValues = maxBuilder.build();
sortRange = Optional.of(ShardRange.of(new Tuple(types, minValues), new Tuple(types, maxValues)));
}
builder.add(new ShardIndexInfo(tableId, OptionalInt.empty(), shard.getShardUuid(), false, Optional.empty(), shard.getRowCount(), shard.getUncompressedSize(), sortRange, Optional.of(ShardRange.of(new Tuple(temporalType, temporalColumnStats.getMin()), new Tuple(temporalType, temporalColumnStats.getMax())))));
}
return builder.build();
}
use of com.facebook.presto.raptor.metadata.TableColumn in project presto by prestodb.
the class TestShardOrganizerUtil method testGetOrganizationEligibleShards.
@Test
public void testGetOrganizationEligibleShards() {
int day1 = 1111;
int day2 = 2222;
SchemaTableName tableName = new SchemaTableName("default", "test");
metadata.createTable(SESSION, tableMetadataBuilder(tableName).column("orderkey", BIGINT).column("orderdate", DATE).column("orderstatus", createVarcharType(3)).property("ordering", ImmutableList.of("orderstatus", "orderkey")).property("temporal_column", "orderdate").property("table_supports_delta_delete", false).build(), false);
Table tableInfo = metadataDao.getTableInformation(tableName.getSchemaName(), tableName.getTableName());
List<TableColumn> tableColumns = metadataDao.listTableColumns(tableInfo.getTableId());
Map<String, TableColumn> tableColumnMap = Maps.uniqueIndex(tableColumns, TableColumn::getColumnName);
long orderDate = tableColumnMap.get("orderdate").getColumnId();
long orderKey = tableColumnMap.get("orderkey").getColumnId();
long orderStatus = tableColumnMap.get("orderstatus").getColumnId();
List<ShardInfo> shards = ImmutableList.<ShardInfo>builder().add(shardInfo(UUID.randomUUID(), "node1", ImmutableList.of(new ColumnStats(orderDate, day1, day1 + 10), new ColumnStats(orderKey, 13L, 14L), new ColumnStats(orderStatus, "aaa", "abc")))).add(shardInfo(UUID.randomUUID(), "node1", ImmutableList.of(new ColumnStats(orderDate, day2, day2 + 100), new ColumnStats(orderKey, 2L, 20L), new ColumnStats(orderStatus, "aaa", "abc")))).add(shardInfo(UUID.randomUUID(), "node1", ImmutableList.of(new ColumnStats(orderDate, day1, day2), new ColumnStats(orderKey, 2L, 11L), new ColumnStats(orderStatus, "aaa", "abc")))).add(shardInfo(UUID.randomUUID(), "node1", ImmutableList.of(new ColumnStats(orderDate, day1, day2), new ColumnStats(orderKey, 2L, null), new ColumnStats(orderStatus, "aaa", "abc")))).add(shardInfo(UUID.randomUUID(), "node1", ImmutableList.of(new ColumnStats(orderDate, day1, null), new ColumnStats(orderKey, 2L, 11L), new ColumnStats(orderStatus, "aaa", "abc")))).build();
long transactionId = shardManager.beginTransaction();
shardManager.commitShards(transactionId, tableInfo.getTableId(), COLUMNS, shards, Optional.empty(), 0);
Set<ShardMetadata> shardMetadatas = shardManager.getNodeShardsAndDeltas("node1");
Long temporalColumnId = metadataDao.getTemporalColumnId(tableInfo.getTableId());
TableColumn temporalColumn = metadataDao.getTableColumn(tableInfo.getTableId(), temporalColumnId);
Set<ShardIndexInfo> actual = ImmutableSet.copyOf(getOrganizationEligibleShards(dbi, metadataDao, tableInfo, shardMetadatas, false));
List<ShardIndexInfo> expected = getShardIndexInfo(tableInfo, shards, temporalColumn, Optional.empty());
assertEquals(actual, expected);
List<TableColumn> sortColumns = metadataDao.listSortColumns(tableInfo.getTableId());
Set<ShardIndexInfo> actualSortRange = ImmutableSet.copyOf(getOrganizationEligibleShards(dbi, metadataDao, tableInfo, shardMetadatas, true));
List<ShardIndexInfo> expectedSortRange = getShardIndexInfo(tableInfo, shards, temporalColumn, Optional.of(sortColumns));
assertEquals(actualSortRange, expectedSortRange);
}
use of com.facebook.presto.raptor.metadata.TableColumn in project presto by prestodb.
the class RaptorMetadata method getTableHandle.
private RaptorTableHandle getTableHandle(SchemaTableName tableName) {
requireNonNull(tableName, "tableName is null");
Table table = dao.getTableInformation(tableName.getSchemaName(), tableName.getTableName());
if (table == null) {
return null;
}
List<TableColumn> tableColumns = dao.listTableColumns(table.getTableId());
checkArgument(!tableColumns.isEmpty(), "Table %s does not have any columns", tableName);
return new RaptorTableHandle(connectorId, tableName.getSchemaName(), tableName.getTableName(), table.getTableId(), table.getDistributionId(), table.getDistributionName(), table.getBucketCount(), table.isOrganized(), OptionalLong.empty(), Optional.empty(), false, table.isTableSupportsDeltaDelete());
}
use of com.facebook.presto.raptor.metadata.TableColumn in project presto by prestodb.
the class RaptorMetadata method beginInsert.
@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle) {
RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
long tableId = handle.getTableId();
ImmutableList.Builder<RaptorColumnHandle> columnHandles = ImmutableList.builder();
ImmutableList.Builder<Type> columnTypes = ImmutableList.builder();
for (TableColumn column : dao.listTableColumns(tableId)) {
columnHandles.add(new RaptorColumnHandle(connectorId, column.getColumnName(), column.getColumnId(), column.getDataType()));
columnTypes.add(column.getDataType());
}
long transactionId = shardManager.beginTransaction();
setTransactionId(transactionId);
Optional<String> externalBatchId = getExternalBatchId(session);
List<RaptorColumnHandle> sortColumnHandles = getSortColumnHandles(tableId);
List<RaptorColumnHandle> bucketColumnHandles = getBucketColumnHandles(tableId);
Optional<RaptorColumnHandle> temporalColumnHandle = Optional.ofNullable(dao.getTemporalColumnId(tableId)).map(temporalColumnId -> getOnlyElement(columnHandles.build().stream().filter(columnHandle -> columnHandle.getColumnId() == temporalColumnId).collect(toList())));
return new RaptorInsertTableHandle(connectorId, transactionId, tableId, columnHandles.build(), columnTypes.build(), externalBatchId, sortColumnHandles, nCopies(sortColumnHandles.size(), ASC_NULLS_FIRST), handle.getBucketCount(), bucketColumnHandles, temporalColumnHandle);
}
use of com.facebook.presto.raptor.metadata.TableColumn in project presto by prestodb.
the class RaptorMetadata method listTableColumns.
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
requireNonNull(prefix, "prefix is null");
ImmutableListMultimap.Builder<SchemaTableName, ColumnMetadata> columns = ImmutableListMultimap.builder();
for (TableColumn tableColumn : dao.listTableColumns(prefix.getSchemaName(), prefix.getTableName())) {
ColumnMetadata columnMetadata = new ColumnMetadata(tableColumn.getColumnName(), tableColumn.getDataType());
columns.put(tableColumn.getTable(), columnMetadata);
}
return Multimaps.asMap(columns.build());
}
Aggregations