Java Code Examples for org.apache.kudu.client.CreateTableOptions#setRangePartitionColumns()

The following examples show how to use org.apache.kudu.client.CreateTableOptions#setRangePartitionColumns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KuduTableInfo.java    From flink-learning with Apache License 2.0 6 votes vote down vote up
public CreateTableOptions getCreateTableOptions() {
    CreateTableOptions options = new CreateTableOptions();
    if(replicas!=null){
        options.setNumReplicas(replicas);
    }
    if(hasColummns()) {
        List<String> rangeKeys = new ArrayList<>();
        List<String> hashKeys = new ArrayList<>();
        for(KuduColumnInfo column : columns){
            if(column.isRangeKey()){
                rangeKeys.add(column.name());
            }
            if(column.isHashKey()){
                hashKeys.add(column.name());
            }
        }
        options.setRangePartitionColumns(rangeKeys);
        options.addHashPartitions(hashKeys, replicas*2);
    }

    return options;
}
 
Example 2
Source File: KuduTableInfo.java    From flink-learning with Apache License 2.0 6 votes vote down vote up
public CreateTableOptions getCreateTableOptions() {
    CreateTableOptions options = new CreateTableOptions();
    if(replicas!=null){
        options.setNumReplicas(replicas);
    }
    if(hasColummns()) {
        List<String> rangeKeys = new ArrayList<>();
        List<String> hashKeys = new ArrayList<>();
        for(KuduColumnInfo column : columns){
            if(column.isRangeKey()){
                rangeKeys.add(column.name());
            }
            if(column.isHashKey()){
                hashKeys.add(column.name());
            }
        }
        options.setRangePartitionColumns(rangeKeys);
        options.addHashPartitions(hashKeys, replicas*2);
    }

    return options;
}
 
Example 3
Source File: Tables.java    From kudu-ts with Apache License 2.0 6 votes vote down vote up
/**
 * The {@code tagsets} table is range partitioned on the {@code id} column.
 * Because the table is essentially a linear probe hash table, it must be able
 * to be scanned in PK order, so hash partitioning is not possible. Since the
 * tagset IDs are effectively random, setting split points at even intervals
 * over the ID range gives good protection against hotspotting.
 * @param options the create options
 * @param numTabletServers the number of tablet servers
 * @return the tagset table create options
 */
static CreateTableOptions tagsetsCreateTableOptions(CreateOptions options,
                                                    int numTabletServers) {
  CreateTableOptions create = new CreateTableOptions();
  create.setNumReplicas(options.getNumReplicas());

  create.setRangePartitionColumns(ImmutableList.of("id"));

  int numTablets = options.getNumTagsetsTablets(numTabletServers);
  long interval = (1L << 32) / numTablets;
  for (int i = 1; i < numTablets; i++) {
    PartialRow split = TAGSETS_SCHEMA.newPartialRow();
    split.addInt(TAGSETS_ID_INDEX, (int) (Integer.MIN_VALUE + i * interval));
    create.addSplitRow(split);
  }
  return create;
}
 
Example 4
Source File: KuduClientSession.java    From presto with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: NativeKuduClientSession.java    From presto-kudu with Apache License 2.0 5 votes vote down vote up
private CreateTableOptions buildCreateTableOptions(Schema schema, Map<String, Object> properties) {
    CreateTableOptions options = new CreateTableOptions();

    RangePartitionDefinition rangePartitionDefinition = null;
    Optional<PartitionDesign> optPartitionDesign = KuduTableProperties.getPartitionDesign(properties);
    if (optPartitionDesign.isPresent()) {
        PartitionDesign partitionDesign = optPartitionDesign.get();
        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());
        }
    } else {
        String firstColumn = schema.getColumnByIndex(0).getName();
        options.setRangePartitionColumns(Collections.singletonList(firstColumn));
    }

    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;
}
 
Example 6
Source File: Tables.java    From kudu-ts with Apache License 2.0 5 votes vote down vote up
/**
 * The {@code metrics} table is hash partitioned on the {@code metric} and
 * {@code tagset_id} columns, and range partitioned on the {@code time}
 * column. The hash partitioning allows writes and scans at the current time
 * to be evenly distributed over the cluster. Range partitioning on time
 * allows whole tablets to be pruned based on the time constraint, and allows
 * old data to be dropped if desired.
 * @param options the create options
 * @param numTabletServers the number of tablet servers
 * @return the tags table create options
 */
static CreateTableOptions metricsCreateTableOptions(CreateOptions options,
                                                    int numTabletServers) {
  CreateTableOptions create = new CreateTableOptions();
  create.setNumReplicas(options.getNumReplicas());
  create.addHashPartitions(ImmutableList.of("metric", "tagset_id"),
                           options.getNumMetricsHashBuckets(numTabletServers));
  create.setRangePartitionColumns(ImmutableList.of("time"));
  for (Long time : options.getMetricsSplits()) {
    PartialRow split = METRICS_SCHEMA.newPartialRow();
    split.addLong(METRICS_TIME_INDEX, time);
    create.addSplitRow(split);
  }
  return create;
}
 
Example 7
Source File: Tables.java    From kudu-ts with Apache License 2.0 5 votes vote down vote up
/**
 * The {@code tags} table is hash partitioned on the {@code key} and
 * {@code value} columns, which allows a scan of a ({@code key}, {@code value})
 * pair to be fully satisfied by a single tablet, and gives good protection
 * against hotspotting.
 * @param options the create options
 * @param numTabletServers the number of tablet servers
 * @return the tags table create options
 */
static CreateTableOptions tagsCreateTableOptions(CreateOptions options,
                                                 int numTabletServers) {
  CreateTableOptions create = new CreateTableOptions();
  create.setNumReplicas(options.getNumReplicas());
  create.addHashPartitions(ImmutableList.of("key", "value"),
                           options.getNumTagsTablets(numTabletServers));
  create.setRangePartitionColumns(ImmutableList.<String>of());
  return create;
}