Search in sources :

Example 1 with RangePartitionDefinition

use of com.facebook.presto.kudu.properties.RangePartitionDefinition in project presto by prestodb.

the class KuduClientSession method buildCreateTableOptions.

private CreateTableOptions buildCreateTableOptions(Schema schema, Map<String, Object> properties) {
    CreateTableOptions options = new CreateTableOptions();
    RangePartitionDefinition rangePartitionDefinition = null;
    PartitionDesign partitionDesign = KuduTableProperties.getPartitionDesign(properties);
    if (partitionDesign.getHash() != null) {
        for (HashPartitionDefinition partition : partitionDesign.getHash()) {
            options.addHashPartitions(partition.getColumns(), partition.getBuckets());
        }
    }
    if (partitionDesign.getRange() != null) {
        rangePartitionDefinition = partitionDesign.getRange();
        options.setRangePartitionColumns(rangePartitionDefinition.getColumns());
    }
    List<RangePartition> rangePartitions = KuduTableProperties.getRangePartitions(properties);
    if (rangePartitionDefinition != null && !rangePartitions.isEmpty()) {
        for (RangePartition rangePartition : rangePartitions) {
            PartialRow lower = KuduTableProperties.toRangeBoundToPartialRow(schema, rangePartitionDefinition, rangePartition.getLower());
            PartialRow upper = KuduTableProperties.toRangeBoundToPartialRow(schema, rangePartitionDefinition, rangePartition.getUpper());
            options.addRangePartition(lower, upper);
        }
    }
    Optional<Integer> numReplicas = KuduTableProperties.getNumReplicas(properties);
    numReplicas.ifPresent(options::setNumReplicas);
    return options;
}
Also used : RangePartition(com.facebook.presto.kudu.properties.RangePartition) HashPartitionDefinition(com.facebook.presto.kudu.properties.HashPartitionDefinition) PartialRow(org.apache.kudu.client.PartialRow) RangePartitionDefinition(com.facebook.presto.kudu.properties.RangePartitionDefinition) CreateTableOptions(org.apache.kudu.client.CreateTableOptions) PartitionDesign(com.facebook.presto.kudu.properties.PartitionDesign)

Example 2 with RangePartitionDefinition

use of com.facebook.presto.kudu.properties.RangePartitionDefinition in project presto by prestodb.

the class KuduClientSession method changeRangePartition.

private void changeRangePartition(SchemaTableName schemaTableName, RangePartition rangePartition, RangePartitionChange change) {
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        KuduTable table = client.openTable(rawName);
        Schema schema = table.getSchema();
        PartitionDesign design = KuduTableProperties.getPartitionDesign(table);
        RangePartitionDefinition definition = design.getRange();
        if (definition == null) {
            throw new PrestoException(QUERY_REJECTED, "Table " + schemaTableName + " has no range partition");
        }
        PartialRow lowerBound = KuduTableProperties.toRangeBoundToPartialRow(schema, definition, rangePartition.getLower());
        PartialRow upperBound = KuduTableProperties.toRangeBoundToPartialRow(schema, definition, rangePartition.getUpper());
        AlterTableOptions alterOptions = new AlterTableOptions();
        switch(change) {
            case ADD:
                alterOptions.addRangePartition(lowerBound, upperBound);
                break;
            case DROP:
                alterOptions.dropRangePartition(lowerBound, upperBound);
                break;
        }
        client.alterTable(rawName, alterOptions);
    } catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
Also used : AlterTableOptions(org.apache.kudu.client.AlterTableOptions) Schema(org.apache.kudu.Schema) ColumnSchema(org.apache.kudu.ColumnSchema) PartialRow(org.apache.kudu.client.PartialRow) KuduTable(org.apache.kudu.client.KuduTable) RangePartitionDefinition(com.facebook.presto.kudu.properties.RangePartitionDefinition) PrestoException(com.facebook.presto.spi.PrestoException) PartitionDesign(com.facebook.presto.kudu.properties.PartitionDesign) KuduException(org.apache.kudu.client.KuduException)

Aggregations

PartitionDesign (com.facebook.presto.kudu.properties.PartitionDesign)2 RangePartitionDefinition (com.facebook.presto.kudu.properties.RangePartitionDefinition)2 PartialRow (org.apache.kudu.client.PartialRow)2 HashPartitionDefinition (com.facebook.presto.kudu.properties.HashPartitionDefinition)1 RangePartition (com.facebook.presto.kudu.properties.RangePartition)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ColumnSchema (org.apache.kudu.ColumnSchema)1 Schema (org.apache.kudu.Schema)1 AlterTableOptions (org.apache.kudu.client.AlterTableOptions)1 CreateTableOptions (org.apache.kudu.client.CreateTableOptions)1 KuduException (org.apache.kudu.client.KuduException)1 KuduTable (org.apache.kudu.client.KuduTable)1