The Tablestore SDK for Java logically divides all data in a table into splits of a specified size and returns the primary key range and location hint of each split.
Prerequisites
Install the Tablestore SDK for Java and initialize the client.
Description
Tablestore logically divides a table into splits of the specified approximate size on the server. Each split includes its primary key range (lowerBound / upperBound) and a location hint for the machine that hosts the split (location). Pass these primary key ranges to RangeRowQueryCriteria, then process the splits in parallel by reading data by range or reading data with an iterator.
public ComputeSplitsBySizeResponse computeSplitsBySize(ComputeSplitsBySizeRequest request) throws TableStoreException, ClientException
The following example divides the split_demo table into splits of approximately 200 MB and prints the location and primary key range of each split.
String tableName = "split_demo";
// Divide the full data of the table into splits of approximately 200 MB (2 * 100 MB).
ComputeSplitsBySizeRequest request =
new ComputeSplitsBySizeRequest(tableName, 2);
ComputeSplitsBySizeResponse response = client.computeSplitsBySize(request);
System.out.println("PrimaryKeySchema: " + response.getPrimaryKeySchema());
List<Split> splits = response.getSplits();
System.out.println("Splits size: " + splits.size());
Iterator<Split> iterator = splits.iterator();
while (iterator.hasNext()) {
Split split = iterator.next();
// The primary key ranges returned by getLowerBound() and getUpperBound() can be passed directly
// to RangeRowQueryCriteria for parallel reads with getRange or createRangeIterator.
System.out.println("Location: " + split.getLocation());
System.out.println("LowerBound: " + split.getLowerBound().jsonize());
System.out.println("UpperBound: " + split.getUpperBound().jsonize());
}
Parameters
|
Name |
Type |
Description |
|
tableName (required) |
String |
The name of the table. |
|
splitSize (required) |
long |
The approximate size of each split, in units of 100 MB. For example, passing |
Response
Split result
ComputeSplitsBySizeResponse contains the following operation-specific fields.
|
Name |
Type |
Description |
|
splits |
List<Split> |
The logical splits. Call |
|
primaryKeySchema |
List<PrimaryKeySchema> |
The primary key schema of the table. Call |
Split information
Each element in ComputeSplitsBySizeResponse.splits[] is of the Split type.
|
Name |
Type |
Description |
|
lowerBound |
PrimaryKey |
The lower bound of the primary key range of the split. |
|
upperBound |
PrimaryKey |
The upper bound of the primary key range of the split. |
|
location |
String |
A location hint for the machine that stores the split. The value may be an empty string. |