All Products
Search
Document Center

Tablestore:Split data into shards of a specific size

Last Updated:Nov 14, 2023

You can call the ComputeSplitsBySize operation to split data in a table into logical shards whose sizes are approximately the specified value. The information about the split points among the shards and the hosts in which the shards reside is returned. In most cases, this operation is used to implement plans on compute engines, such as concurrency plans.

Note

For more information, see ComputeSplitPointsBySize.

Prerequisites

  • OTSClient is initialized. For more information, see Initialization.
  • A data table is created, and data is written to the table.

Parameters

Parameter

description

tableName

The name of the table.

splitSize

The specified size of each shard.

Unit: 100 MB.

Example

The following code provides an example on how to split data in a table into logical shards whose sizes are approximately 200 MB:

private static void describeTable(SyncClient client) {
    // Specify the name of the table. Split the data in the table into logical shards and specify that the size ofeach shard is approximately 200 MB. 
    ComputeSplitsBySizeRequest request = new ComputeSplitsBySizeRequest("<TABLE_NAME>", 2);
    ComputeSplitsBySizeResponse response = client.computeSplitsBySize(request);
    System.out.println("ConsumedCapacity=" + response.getConsumedCapacity().jsonize());
    System.out.println("PrimaryKeySchema=" + response.getPrimaryKeySchema());
    System.out.println("RequestId=" + response.getRequestId());
    System.out.println("TraceId=" + response.getTraceId());
    List<Split> splits = response.getSplits();
    System.out.println("splits.size=" + splits.size());
    Iterator<Split> iterator = splits.iterator();
    while (iterator.hasNext()) {
        Split split = iterator.next();
        System.out.println("split.getLocation()=" + split.getLocation());
        // You can inject the split.getLowerBound() and split.getUpperBound() functions into the RangeRowQueryCriteria class, and pass the RangeRowQueryCriteria class to perform the getRange() or createRangeIterator() operation.
        System.out.println("split.getLowerBound()=" + split.getLowerBound().jsonize());
        System.out.println("split.getUpperBound()=" + split.getUpperBound().jsonize());
    }
}