use of com.facebook.presto.raptor.metadata.MetadataDao in project presto by prestodb.
the class RaptorMetadata method finishCreateTable.
@Override
public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession session, ConnectorOutputTableHandle outputTableHandle, Collection<Slice> fragments) {
RaptorOutputTableHandle table = (RaptorOutputTableHandle) outputTableHandle;
long transactionId = table.getTransactionId();
long updateTime = session.getStartTime();
long newTableId = runTransaction(dbi, (dbiHandle, status) -> {
MetadataDao dao = dbiHandle.attach(MetadataDao.class);
Long distributionId = table.getDistributionId().isPresent() ? table.getDistributionId().getAsLong() : null;
// TODO: update default value of organization_enabled to true
long tableId = dao.insertTable(table.getSchemaName(), table.getTableName(), true, table.isOrganized(), distributionId, updateTime);
List<RaptorColumnHandle> sortColumnHandles = table.getSortColumnHandles();
List<RaptorColumnHandle> bucketColumnHandles = table.getBucketColumnHandles();
for (int i = 0; i < table.getColumnTypes().size(); i++) {
RaptorColumnHandle column = table.getColumnHandles().get(i);
int columnId = i + 1;
String type = table.getColumnTypes().get(i).getTypeSignature().toString();
Integer sortPosition = sortColumnHandles.contains(column) ? sortColumnHandles.indexOf(column) : null;
Integer bucketPosition = bucketColumnHandles.contains(column) ? bucketColumnHandles.indexOf(column) : null;
dao.insertColumn(tableId, columnId, column.getColumnName(), i, type, sortPosition, bucketPosition);
if (table.getTemporalColumnHandle().isPresent() && table.getTemporalColumnHandle().get().equals(column)) {
dao.updateTemporalColumnId(tableId, columnId);
}
}
return tableId;
});
List<ColumnInfo> columns = table.getColumnHandles().stream().map(ColumnInfo::fromHandle).collect(toList());
OptionalLong temporalColumnId = table.getTemporalColumnHandle().map(RaptorColumnHandle::getColumnId).map(OptionalLong::of).orElse(OptionalLong.empty());
// TODO: refactor this to avoid creating an empty table on failure
shardManager.createTable(newTableId, columns, table.getBucketCount().isPresent(), temporalColumnId);
shardManager.commitShards(transactionId, newTableId, columns, parseFragments(fragments), Optional.empty(), updateTime);
clearRollback();
return Optional.empty();
}
use of com.facebook.presto.raptor.metadata.MetadataDao in project presto by prestodb.
the class ShardCompactionManager method filterAndCreateCompactionSets.
private Collection<OrganizationSet> filterAndCreateCompactionSets(long tableId, Collection<ShardMetadata> tableShards) {
Table tableInfo = metadataDao.getTableInformation(tableId);
OptionalLong temporalColumnId = tableInfo.getTemporalColumnId();
if (temporalColumnId.isPresent()) {
TableColumn tableColumn = metadataDao.getTableColumn(tableId, temporalColumnId.getAsLong());
if (!isValidTemporalColumn(tableId, tableColumn.getDataType())) {
return ImmutableSet.of();
}
}
Set<ShardMetadata> filteredShards = tableShards.stream().filter(this::needsCompaction).filter(shard -> !organizer.inProgress(shard.getShardUuid())).collect(toSet());
Collection<ShardIndexInfo> shardIndexInfos = getOrganizationEligibleShards(dbi, metadataDao, tableInfo, filteredShards, false);
if (tableInfo.getTemporalColumnId().isPresent()) {
Set<ShardIndexInfo> temporalShards = shardIndexInfos.stream().filter(shard -> shard.getTemporalRange().isPresent()).collect(toSet());
return compactionSetCreator.createCompactionSets(tableInfo, temporalShards);
}
return compactionSetCreator.createCompactionSets(tableInfo, shardIndexInfos);
}
use of com.facebook.presto.raptor.metadata.MetadataDao in project presto by prestodb.
the class TestShardOrganizerUtil method setup.
@BeforeMethod
public void setup() {
dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime());
dbi.registerMapper(new TableColumn.Mapper(new TypeRegistry()));
dummyHandle = dbi.open();
createTablesWithRetry(dbi);
dataDir = Files.createTempDir();
metadata = new RaptorMetadata("raptor", dbi, createShardManager(dbi));
metadataDao = dbi.onDemand(MetadataDao.class);
shardManager = createShardManager(dbi);
}
use of com.facebook.presto.raptor.metadata.MetadataDao in project presto by prestodb.
the class TestBucketBalancer method createDistribution.
private long createDistribution(String distributionName, int bucketCount) {
MetadataDao dao = dbi.onDemand(MetadataDao.class);
long distributionId = dao.insertDistribution(distributionName, serializeColumnTypes(ImmutableList.of(BIGINT)), bucketCount);
shardManager.createBuckets(distributionId, bucketCount);
return distributionId;
}
use of com.facebook.presto.raptor.metadata.MetadataDao in project presto by prestodb.
the class TestShardMetadataRecordCursor method testNoSchemaFilter.
@Test
public void testNoSchemaFilter() throws Exception {
// Create "orders" table in a different schema
metadata.createTable(SESSION, tableMetadataBuilder(new SchemaTableName("other", "orders")).column("orderkey", BIGINT).build());
// Create another table that should not be selected
metadata.createTable(SESSION, tableMetadataBuilder(new SchemaTableName("schema1", "foo")).column("orderkey", BIGINT).build());
TupleDomain<Integer> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.<Integer, Domain>builder().put(1, Domain.singleValue(createVarcharType(10), utf8Slice("orders"))).build());
MetadataDao metadataDao = dummyHandle.attach(MetadataDao.class);
Set<Long> actual = ImmutableSet.copyOf(ShardMetadataRecordCursor.getTableIds(dbi, tupleDomain));
Set<Long> expected = ImmutableSet.of(metadataDao.getTableInformation("other", "orders").getTableId(), metadataDao.getTableInformation("test", "orders").getTableId());
assertEquals(actual, expected);
}
Aggregations