Split data for parallel scans

Updated at:

Use the Tablestore SDK for Go to logically split all data in a table by an approximate size and obtain the primary key range and location hint for each split.

Prerequisites

Install the Tablestore SDK for Go and initialize the client.

Description

Call ComputeSplitPointsBySize to logically split a table by an approximate size. Each split contains a primary key range and location hint. You can pass the ranges to RangeRowQueryCriteria and read the splits in parallel, such as when a compute engine plans concurrent tasks.

func (client TableStoreClient) ComputeSplitPointsBySize(req *ComputeSplitPointsBySizeRequest) (*ComputeSplitPointsBySizeResponse, error)

The following sample splits all data in the example_table table into logical splits of approximately 200 MB and prints the split information.

request := &tablestore.ComputeSplitPointsBySizeRequest{
    TableName: "example_table",
    SplitSize: 2,
}

response, err := client.ComputeSplitPointsBySize(request)
if err != nil {
    log.Fatal(err)
}

for _, split := range response.Splits {
    fmt.Println("Location:", split.Location)
    fmt.Println("Lower bound:", split.LowerBound)
    fmt.Println("Upper bound:", split.UpperBound)
}
Note

SplitSize is measured in units of 100 MB. A value of N specifies an approximate split size of N × 100 MB. The returned splits are logical, and their actual sizes may differ. Location is only a hint and may be an empty string in some scenarios.

Parameters

ComputeSplitPointsBySizeRequest contains the following parameters.

Name

Type

Description

TableName (required)

string

The table name.

SplitSize (required)

int64

The approximate size of each logical split, in units of 100 MB. For example, a value of 2 specifies approximately 200 MB.

Response

ComputeSplitPointsBySizeResponse contains the following business information.

Field

Type

Description

Splits

[]*Split

The logical splits.

Logical split

Each element in Splits is of the Split type and contains the following fields.

Field

Type

Description

LowerBound

*PrimaryKey

The lower bound of the primary key range, which can be used as the start primary key of a range read.

UpperBound

*PrimaryKey

The upper bound of the primary key range, which can be used as the end primary key of a range read.

Location

string

A hint about the machine location of the split. The value may be an empty string in some scenarios.