API 说明请参见ComputeSplitPointsBySize。
前提条件
已初始化Client。具体操作,请参见初始化Tablestore Client。
已创建数据表并写入数据。具体操作,请参见创建数据表。
接口
/**
* 将全表数据在逻辑上划分成接近指定大小的若干分片,返回分片之间的分割点及分片所在机器的提示。
* 通常用于计算引擎规划并发度等执行计划。
* @api
* @param [] $request 请求参数。
* @return [] 请求返回。
* @throws OTSClientException 参数检查出错或服务端返回校验出错时抛出异常。
* @throws OTSServerException OTS 服务端返回错误时抛出异常。
*/
public function computeSplitPointsBySize(array $request)
参数
请求信息
请求参数
|
参数 |
说明 |
|
table_name |
数据表名称。 |
|
split_size |
每个分片的近似大小。单位为百兆(100 MB)。 |
请求格式
$result = $client->ComputeSplitsBySize([
'table_name' => '<string>', //设置数据表名称,必须设置。
'split_size' => <integer> //设置分片大小,必须设置。
]);
响应信息
响应参数
|
参数 |
说明 |
|
consumed |
本次操作消耗的服务能力单元(CU)值。 capacity_unit 表示消耗的读写 CU:
|
|
primary_key_schema |
数据表的主键定义,与创建数据表时的主键定义相同。 |
|
splits |
分片之间的分割点,每个分片包含以下字段:
|
结果格式
[
'consumed' => [
'capacity_unit' => [
'read' => <integer>,
'write' => <integer>
]
],
'primary_key_schema' => [
['<string>', <PrimaryKeyType>],
['<string>', <PrimaryKeyType>, <PrimaryKeyOption>]
]
'splits' => [
[
'lower_bound' => [
['<string>', <PrimaryKeyValue>, <PrimaryKeyType>],
['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
],
'upper_bound' => [
['<string>', <PrimaryKeyValue>, <PrimaryKeyType>],
['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
],
'location' => '<string>'
],
// ...
]
]
示例
以下示例将全表数据划分成接近 100 MB 的若干分片(split_size 设置为 1),并打印每个分片的位置和主键范围。
$result = $client->ComputeSplitsBySize([
'table_name' => 'MyTable',
'split_size' => 1
]);
foreach($result['splits'] as $split) {
print_r($split['location']);
print_r($split['lower_bound']);
print_r($split['upper_bound']);
}