Search in sources :

Example 11 with MetadataDao

use of io.trino.plugin.raptor.legacy.metadata.MetadataDao in project trino by trinodb.

the class RaptorMetadata method finishCreateTable.

@Override
public Optional<ConnectorOutputMetadata> finishCreateTable(ConnectorSession session, ConnectorOutputTableHandle outputTableHandle, Collection<Slice> fragments, Collection<ComputedStatistics> computedStatistics) {
    RaptorOutputTableHandle table = (RaptorOutputTableHandle) outputTableHandle;
    long transactionId = table.getTransactionId();
    long updateTime = session.getStart().toEpochMilli();
    long newTableId = runTransaction(dbi, dbiHandle -> {
        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).getTypeId().getId();
            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(io.trino.plugin.raptor.legacy.metadata.ColumnInfo) OptionalLong(java.util.OptionalLong) Constraint(io.trino.spi.connector.Constraint) MetadataDao(io.trino.plugin.raptor.legacy.metadata.MetadataDao)

Aggregations

MetadataDao (io.trino.plugin.raptor.legacy.metadata.MetadataDao)11 Duration (io.airlift.units.Duration)3 ShardManager (io.trino.plugin.raptor.legacy.metadata.ShardManager)3 StorageManagerConfig (io.trino.plugin.raptor.legacy.storage.StorageManagerConfig)3 NodeManager (io.trino.spi.NodeManager)3 Jdbi (org.jdbi.v3.core.Jdbi)3 BeforeMethod (org.testng.annotations.BeforeMethod)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Threads.daemonThreadsNamed (io.airlift.concurrent.Threads.daemonThreadsNamed)2 Logger (io.airlift.log.Logger)2 ColumnInfo (io.trino.plugin.raptor.legacy.metadata.ColumnInfo)2 ForMetadata (io.trino.plugin.raptor.legacy.metadata.ForMetadata)2 ShardMetadata (io.trino.plugin.raptor.legacy.metadata.ShardMetadata)2 Table (io.trino.plugin.raptor.legacy.metadata.Table)2 ShardOrganizerUtil.getOrganizationEligibleShards (io.trino.plugin.raptor.legacy.storage.organization.ShardOrganizerUtil.getOrganizationEligibleShards)2 DatabaseUtil.onDemandDao (io.trino.plugin.raptor.legacy.util.DatabaseUtil.onDemandDao)2 SchemaTableName (io.trino.spi.connector.SchemaTableName)2 TestingNodeManager (io.trino.testing.TestingNodeManager)2 Collection (java.util.Collection)2 List (java.util.List)2