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

The following examples show how to use org.apache.kudu.client.CreateTableOptions#addSplitRow() . 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: 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 2
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 3
Source File: KuduClientTestCommons.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
public static void createTestTable(String tableName, KuduClient client) throws Exception
{
  List<String> rangeKeys = new ArrayList<>();
  rangeKeys.add("introwkey");
  List<String> hashPartitions = new ArrayList<>();
  hashPartitions.add("stringrowkey");
  hashPartitions.add("timestamprowkey");
  CreateTableOptions thisTableOptions = new CreateTableOptions()
      .setNumReplicas(1)
      .addHashPartitions(hashPartitions,HASH_BUCKETS_SIZE_FOR_ALL_HASH_COL)
      .setRangePartitionColumns(rangeKeys);
  int stepsize = Integer.MAX_VALUE / SPLIT_COUNT_FOR_INT_ROW_KEY;
  int splitBoundary = stepsize;
  Schema schema = buildSchemaForUnitTestsTable();
  for ( int i = 0; i < SPLIT_COUNT_FOR_INT_ROW_KEY; i++) {
    PartialRow splitRowBoundary = schema.newPartialRow();
    splitRowBoundary.addInt("introwkey",splitBoundary);
    thisTableOptions = thisTableOptions.addSplitRow(splitRowBoundary);
    splitBoundary += stepsize;
  }
  try {
    client.createTable(tableName, schema,thisTableOptions);
  } catch (KuduException e) {
    LOG.error("Error while creating table for unit tests " + e.getMessage(), e);
    throw e;
  }

}