Search in sources :

Example 1 with MetadataDao

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();
}
Also used : OptionalLong(java.util.OptionalLong) ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) OptionalLong(java.util.OptionalLong) Constraint(com.facebook.presto.spi.Constraint) MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao)

Example 2 with MetadataDao

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);
}
Also used : IDBI(org.skife.jdbi.v2.IDBI) ListMultimap(com.google.common.collect.ListMultimap) Logger(io.airlift.log.Logger) ForMetadata(com.facebook.presto.raptor.metadata.ForMetadata) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Multimaps(com.google.common.collect.Multimaps) Duration(io.airlift.units.Duration) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) OptionalLong(java.util.OptionalLong) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Type(com.facebook.presto.spi.type.Type) Threads.daemonThreadsNamed(io.airlift.concurrent.Threads.daemonThreadsNamed) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Objects.requireNonNull(java.util.Objects.requireNonNull) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ShardManager(com.facebook.presto.raptor.metadata.ShardManager) DatabaseUtil.onDemandDao(com.facebook.presto.raptor.util.DatabaseUtil.onDemandDao) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) Collectors.toSet(java.util.stream.Collectors.toSet) Table(com.facebook.presto.raptor.metadata.Table) ImmutableSet(com.google.common.collect.ImmutableSet) NodeManager(com.facebook.presto.spi.NodeManager) Collection(java.util.Collection) Set(java.util.Set) StorageManagerConfig(com.facebook.presto.raptor.storage.StorageManagerConfig) MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao) ShardMetadata(com.facebook.presto.raptor.metadata.ShardMetadata) TimeUnit(java.util.concurrent.TimeUnit) DataSize(io.airlift.units.DataSize) List(java.util.List) ShardOrganizerUtil.getOrganizationEligibleShards(com.facebook.presto.raptor.storage.organization.ShardOrganizerUtil.getOrganizationEligibleShards) DATE(com.facebook.presto.spi.type.DateType.DATE) PostConstruct(javax.annotation.PostConstruct) Entry(java.util.Map.Entry) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Table(com.facebook.presto.raptor.metadata.Table) ShardMetadata(com.facebook.presto.raptor.metadata.ShardMetadata) OptionalLong(java.util.OptionalLong) TableColumn(com.facebook.presto.raptor.metadata.TableColumn)

Example 3 with MetadataDao

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);
}
Also used : RaptorMetadata(com.facebook.presto.raptor.RaptorMetadata) DBI(org.skife.jdbi.v2.DBI) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) TypeRegistry(com.facebook.presto.type.TypeRegistry) MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with MetadataDao

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;
}
Also used : MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao)

Example 5 with MetadataDao

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);
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao) Test(org.testng.annotations.Test)

Aggregations

MetadataDao (com.facebook.presto.raptor.metadata.MetadataDao)12 ShardManager (com.facebook.presto.raptor.metadata.ShardManager)3 TableColumn (com.facebook.presto.raptor.metadata.TableColumn)3 StorageManagerConfig (com.facebook.presto.raptor.storage.StorageManagerConfig)3 NodeManager (com.facebook.presto.spi.NodeManager)3 TypeRegistry (com.facebook.presto.type.TypeRegistry)3 Duration (io.airlift.units.Duration)3 DBI (org.skife.jdbi.v2.DBI)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 ColumnInfo (com.facebook.presto.raptor.metadata.ColumnInfo)2 ForMetadata (com.facebook.presto.raptor.metadata.ForMetadata)2 ShardMetadata (com.facebook.presto.raptor.metadata.ShardMetadata)2 Table (com.facebook.presto.raptor.metadata.Table)2 ShardOrganizerUtil.getOrganizationEligibleShards (com.facebook.presto.raptor.storage.organization.ShardOrganizerUtil.getOrganizationEligibleShards)2 DatabaseUtil.onDemandDao (com.facebook.presto.raptor.util.DatabaseUtil.onDemandDao)2 SchemaTableName (com.facebook.presto.spi.SchemaTableName)2 TestingNodeManager (com.facebook.presto.testing.TestingNodeManager)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)2 Logger (io.airlift.log.Logger)2