Search in sources :

Example 1 with StorageTypeConverter

use of com.facebook.presto.raptor.storage.StorageTypeConverter in project presto by prestodb.

the class RaptorMetadata method addColumn.

@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) {
    RaptorTableHandle table = (RaptorTableHandle) tableHandle;
    // Always add new columns to the end.
    List<TableColumn> existingColumns = dao.listTableColumns(table.getSchemaName(), table.getTableName());
    TableColumn lastColumn = existingColumns.get(existingColumns.size() - 1);
    long columnId = lastColumn.getColumnId() + 1;
    int ordinalPosition = lastColumn.getOrdinalPosition() + 1;
    StorageTypeConverter storageTypeConverter = new StorageTypeConverter(typeManager);
    checkState(storageTypeConverter.toStorageType(column.getType()) != null, "storage type cannot be null");
    String type = column.getType().getTypeSignature().toString();
    daoTransaction(dbi, MetadataDao.class, dao -> {
        dao.insertColumn(table.getTableId(), columnId, column.getName(), ordinalPosition, type, null, null);
        dao.updateTableVersion(table.getTableId(), session.getStartTime());
    });
    shardManager.addColumn(table.getTableId(), new ColumnInfo(columnId, column.getType()));
}
Also used : ColumnInfo(com.facebook.presto.raptor.metadata.ColumnInfo) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) StorageTypeConverter(com.facebook.presto.raptor.storage.StorageTypeConverter) Constraint(com.facebook.presto.spi.Constraint)

Example 2 with StorageTypeConverter

use of com.facebook.presto.raptor.storage.StorageTypeConverter in project presto by prestodb.

the class RaptorMetadata method getNewTableLayout.

@Override
public Optional<ConnectorNewTableLayout> getNewTableLayout(ConnectorSession session, ConnectorTableMetadata metadata) {
    ImmutableMap.Builder<String, RaptorColumnHandle> map = ImmutableMap.builder();
    long columnId = 1;
    StorageTypeConverter storageTypeConverter = new StorageTypeConverter(typeManager);
    for (ColumnMetadata column : metadata.getColumns()) {
        checkState(storageTypeConverter.toStorageType(column.getType()) != null, "storage type cannot be null");
        map.put(column.getName(), new RaptorColumnHandle(connectorId, column.getName(), columnId, column.getType()));
        columnId++;
    }
    Optional<DistributionInfo> distribution = getOrCreateDistribution(map.build(), metadata.getProperties());
    if (!distribution.isPresent()) {
        return Optional.empty();
    }
    List<String> partitionColumns = distribution.get().getBucketColumns().stream().map(RaptorColumnHandle::getColumnName).collect(toList());
    ConnectorPartitioningHandle partitioning = getPartitioningHandle(distribution.get().getDistributionId());
    return Optional.of(new ConnectorNewTableLayout(partitioning, partitionColumns));
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorPartitioningHandle(com.facebook.presto.spi.connector.ConnectorPartitioningHandle) StorageTypeConverter(com.facebook.presto.raptor.storage.StorageTypeConverter) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

StorageTypeConverter (com.facebook.presto.raptor.storage.StorageTypeConverter)2 ColumnInfo (com.facebook.presto.raptor.metadata.ColumnInfo)1 TableColumn (com.facebook.presto.raptor.metadata.TableColumn)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 ConnectorNewTableLayout (com.facebook.presto.spi.ConnectorNewTableLayout)1 Constraint (com.facebook.presto.spi.Constraint)1 ConnectorPartitioningHandle (com.facebook.presto.spi.connector.ConnectorPartitioningHandle)1 ImmutableMap (com.google.common.collect.ImmutableMap)1