Tablestore SDKs provide multi-row operations such as BatchWriteRow, BatchGetRow, and GetRange.

Prerequisites

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

BatchWriteRow

You can call this operation to write multiple rows of data to one or more tables by sending one request. The BatchWriteRow operation is a set of PutRow, UpdateRow, or DeleteRow operations. When you call the BatchWriteRow operation, the process of constructing the PutRow, UpdateRow, or DeleteRow operations is the same as the process of constructing the PutRow, UpdateRow, or DeleteRow operation when you call the PutRow, UpdateRow, or DeleteRow operation. BatchWriteRow supports conditional update.

If you call the BatchWriteRow operation, each PutRow, UpdateRow, or DeleteRow operation is separately performed and the response to each PutRow, UpdateRow, or DeleteRow operation is separately returned.

  • When you call the BatchWriteRow operation to write multiple rows at a time, some rows may fail to be written. If this happens, Tablestore does not return exceptions, but returns BatchWriteRowResponse in which the indexes and error messages of the failed rows are included. Therefore, when you call the BatchWriteRow operation, you must check the return values to determine whether the operation on each row is successful. If you do not check the return values, failures of operations on some rows are ignored.
  • If the server detects that invalid parameters exist in some operations, the BatchWriteRow operation may return an exception about parameter errors before the first operation in the request is performed.

API operation

/**
 * Write, update, or delete the specified rows of data. 
 * When you call the BatchWriteRow operation to write multiple rows at a time, if some rows fail to be written, the system does not return an exception. However, information about the failed rows is contained in $response. For more information, see the sample response to the BatchWriteRow operation. 
 * @api
 * @param [] $request The request parameters. 
 * @return [] The response. 
 * @throws OTSClientException The exception that is returned when a parameter error occurs or the Tablestore server returns a verification error. 
 * @throws OTSServerException The exception that is returned when the Tablestore server returns an error. 
 */
public function batchWriteRow(array $request);              

Request parameters

BatchWriteRow is a combination of PutRow, UpdateRow, or DeleteRow.
  • Hierarchies are created for tables. Multiple tables can be processed at a time.

    You can configure the tables parameter to specify information about tables and rows on which you want to perform the write, update, or delete operations. For more information, see Single-row operations.

  • The operation_type parameter is added to distinguish between different operation types.
    You can use OperationTypeConst::CONST_PUT to set the operation type to PUT, use OperationTypeConst::CONST_UPDATE to set the operation type to UPDATE, and use OperationTypeConst::CONST_DELETE to set the operation type to DELETE.
    • If the operation type is PUT, primary_key and attribute_columns are valid.
    • If the operation type is UPDATE, primary_key and update_of_attribute_columns are valid.
    • If the operation type is DELETE, primary_key is valid.

Request format

$result = $client->batchWriteRow([
    'tables' => [                                            // Specify the hierarchies of tables. 
        [
            'table_name' => '<string>',                     // Specify the name of the data table. 
            'operation_type' => <OperationType>,
            'condition' => [
                'row_existence' => <RowExistence>,   
                'column_condition' => <ColumnCondition>
            ],
            'primary_key' => [                              // Specify the primary key. 
                ['<string>', <PrimaryKeyValue>], 
                ['<string>', <PrimaryKeyValue>],
                ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
            ], 
            'attribute_columns' => [                        // This parameter is required when the operation type is PUT. 
                    ['<string>', <ColumnValue>], 
                    ['<string>', <ColumnValue>, <ColumnType>],
                    ['<string>', <ColumnValue>, <ColumnType>, <integer>]
            ],
            'update_of_attribute_columns' => [               // This parameter is required when the operation type is UPDATE. 
                'PUT' => [
                    ['<string>', <ColumnValue>], 
                    ['<string>', <ColumnValue>, <ColumnType>],
                    ['<string>', <ColumnValue>, <ColumnType>, <integer>]
                ],
                'DELETE' => [
                    ['<string>', <integer>], 
                    ['<string>', <integer>], 
                    ['<string>', <integer>], 
                    ['<string>', <integer>]
                ],
                'DELETE_ALL' => [
                    '<string>',
                    '<string>',
                    '<string>',
                    '<string>'
                ],
            ],
            'return_content' => [
                'return_type' => <ReturnType>
            ]
        ],
        // Specify other tables. 
    ]
]);        

Response parameters

Each table indicated by the tables parameter in the response corresponds to each table specified in the request. The following table describes the parameters in the response.
Parameter Description
table_name The name of the data table.
is_ok Indicates whether the operation on the row is successful.
  • A value of true indicates that the operation on the row is successful. In this case, the error parameter is invalid.
  • A value of false indicates that the operation on the row fails.
error The error information in the response when the operation fails.
  • code indicates the error code in the response when the operation on the row fails.
  • message indicates the error message in the response when the operation on the row fails.
consumed The number of CUs that are consumed by this operation.
capacity_unit indicates the number of read and write CUs that are consumed.
  • read: the read throughput
  • write: the write throughput
primary_key The value of the primary key, which is consistent with that in the request.

If a value is specified for return_type, the value of this parameter exists. This parameter is used for the auto-increment of primary key column feature.

attribute_columns The values of attribute columns, which are consistent with those in the request. At present, the value of this parameter is empty.

Result format

[
    'tables' => [
        [
            'table_name' => '<string>',
            'rows' => [
                [
                    'is_ok' => true || false,
                    'error' => [
                        'code' => '<string>',
                        'message' => '<string>',
                    ]
                    'consumed' => [
                        'capacity_unit' => [
                            'read' => <integer>,
                            'write' => <integer>
                        ]
                    ],
                    'primary_key' => [ 
                        ['<string>', <PrimaryKeyValue>], 
                        ['<string>', <PrimaryKeyValue>],
                        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
                    ],
                    'attribute_columns' => []
                ],
                // Other rows. 
            ]
        ],
        // Other tables. 
    ]
]           

Examples

The following code provides an example on how to write 30 rows of data to three tables at a time. 10 rows are written to each table.

// Write data to three tables. 10 rows are written to each table. 
$tables = array();
for($i = 0; $i < 3; $i++) {
    $rows = array();
    for($j = 0; $j < 10; $j++) {
        $rows[] = [
            'operation_type' => OperationTypeConst::CONST_PUT, // Set the operation type to PUT. 
            'condition' => RowExistenceExpectationConst::CONST_IGNORE,
            'primary_key' => [
                ['pk0', $i],
                ['pk1', $j]
            ],
            'attribute_columns' => [
                ['Col0', 4],
                ['Col2', 'Beijing']
            ]
        ];
    }
    $tables[] = [
        'table_name' => 'SampleTable' . $i,
        'rows' => $rows
    ];
}
$request = [
    'tables' => $tables
];
$response = $otsClient->batchWriteRow ($request);
// Process each table that is returned. 
foreach ($response['tables'] as $tableData) {
  print "Handling table {$tableData['table_name']} ...\n";

  // Process the result that is returned by the PutRow operation on the table. 
  $putRows = $tableData['rows'];

  foreach ($putRows as $rowData) {

    if ($rowData['is_ok']) {
      // Data is written. 
      print "Capacity Unit Consumed: {$rowData['consumed']['capacity_unit']['write']}\n";
    } else {

      // Handle errors. 
      print "Error: {$rowData['error']['code']} {$rowData['error']['message']}\n";
    }
  }
}           

The following table describes the examples of detailed sample code.

Example Description
BatchWriteRow1.php Shows you how to perform multiple PUT operations in BatchWriteRow.
BatchWriteRow2.php Shows you how to perform multiple UPDATE operations in BatchWriteRow.
BatchWriteRow3.php Shows you how to perform multiple DELETE operations in BatchWriteRow.
BatchWriteRow4.php Shows you how to perform the UPDATE, PUT, and DELETE operations in BatchWriteRow.
BatchWriteRowWithColumnFilter.php Shows you how to use BatchWriteRow together with conditional update.

BatchGetRow

You can call this operation to read multiple rows of data from one or more tables by sending one request. The BatchGetRow operation consists of multiple GetRow operations. The process of constructing a suboperation is the same as the process of calling the GetRow operation. BatchGetRow supports filters.

Note that the BatchGetRow operation uses the same parameter configurations for all rows. For example, if ColumnsToGet is set to [colA], only the value of the colA column is read from all rows.

If you call the BatchGetRow operation, each GetRow operation is separately performed and the response to each GetRow operation is separately returned.

When you call the BatchGetRow operation to read multiple rows at a time, some rows may fail to be read. If this happens, Tablestore does not return exceptions, but returns BatchGetRowResponse in which error messages of the failed rows are included. Therefore, when you call the BatchGetRow operation, you must check the return values to determine whether the status of each row is successful.

API operation

/**
 * Read the specified rows of data. 
 * When you call the BatchGetRow operation to read multiple rows at a time, if some rows fail to be read, the system does not return an exception. However, information about the failed rows is contained in $response. For more information, see the sample response to the BatchGetRow operation. 
 * @api
 * @param [] $request The request parameters. 
 * @return [] The response. 
 * @throws OTSClientException The exception that is returned when a parameter error occurs or the Tablestore server returns a verification error. 
 * @throws OTSServerException The exception that is returned when the Tablestore server returns an error. 
 */
public function batchGetRow(array $request);  
            

Request parameters

BatchGetRow and GetRow have the following differences:
  • Hierarchies are created for tables. Data from multiple tables can be read at a time.

    You can configure the tables parameter to specify information about tables and rows on which you want to perform the read operation. For more information, see Single-row operations.

  • primary_key is changed to primary_keys. You can specify the primary key for multiple rows and read data from multiple rows at a time.

Request format

$result = $client->batchGetRow([
    'tables' => [                                            // Specify the hierarchies of tables. 
        [
            'table_name' => '<string>',                     // Specify the name of the data table. 
            'primary_key' => [                              // Specify the primary key. 
                [
                    ['<string>', <PrimaryKeyValue>], 
                    ['<string>', <PrimaryKeyValue>],
                    ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
                ], 
                // Set other primary keys. 
            ]
            'max_versions' => <integer>,
            'time_range' => [
                'start_time' => <integer>,
                'end_time' => <integer>,
                'specific_time' => <integer>
            ],
            'start_column' => '<string>',
            'end_column' => '<string>',
            'token' => '<string>',
            'columns_to_get' => [
                '<string>',
                '<string>',
                //...   
            ],
            'column_filter' =>  <ColumnCondition>
        ],
        // Specify other tables. 
    ]
]);

            

Response parameters

Each table specified by the tables parameter in the response corresponds to each table specified in the request. The following table describes the parameters in the response.
Parameter Description
table_name The name of the data table.
is_ok Indicates whether the operation on the row is successful.
  • A value of true indicates that the row is read. In this case, the error parameter is invalid.
  • A value of false indicates that the row fails to be read. In this case, the consumed, primary_key, and attribute_columns parameters are invalid.
error The error information in the response when the operation fails.
  • code indicates the error code in the response when the operation on the row fails.
  • message indicates the error message in the response when the operation on the row fails.
consumed The number of CUs that are consumed by this operation.
capacity_unit indicates the number of read and write CUs that are consumed.
  • read: the read throughput
  • write: the write throughput
primary_key The value of the primary key, which is consistent with that in the request.
Note If the row does not exist, primary_key is an empty list [].
attribute_columns The values of attribute columns.
Note If the row does not exist, attribute_columns is an empty list [].
  • Each attribute column is specified by parameters in the following sequence: the attribute column name, attribute column value (ColumnValue), attribute column value type (ColumnType), and timestamp.

    A timestamp is a 64-bit integer, which indicates a version of data.

  • The attribute columns in the response are sorted by attribute column name in alphabetical order. The versions of the attribute columns are sorted by timestamp in descending order.
  • The order of attribute columns in the response may be different from that in the request.
next_token The position from which the next wide-column read operation starts. This parameter is unavailable.

Result format

[
    'tables' => [
        [
            'table_name' => '<string>',
            'rows' => [
                [
                    'is_ok' => true || false,
                    'error' => [
                        'code' => '<string>',
                        'message' => '<string>',
                    ]
                    'consumed' => [
                        'capacity_unit' => [
                            'read' => <integer>,
                            'write' => <integer>
                        ]
                    ],
                    'primary_key' => [ 
                        ['<string>', <PrimaryKeyValue>], 
                        ['<string>', <PrimaryKeyValue>],
                        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
                    ],  
                    'attribute_columns' => [
                            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
                            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
                            ['<string>', <ColumnValue>, <ColumnType>, <integer>]
                    ],
                    'next_token' => '<string>'
                ],
                // Other rows. 
            ]
        ],
        // Other tables. 
    ]
]
            

Examples

The following code provides an example on how to read 30 rows of data from three tables at a time. 10 rows are read from each table.

// Read data from three tables. 10 rows are read from each table. 
$tables = array();
for($i = 0; $i < 3; $i++) {
    $primary_keys = array();
    for($j = 0; $j < 10; $j++) {
        $primary_keys[] = [
            ['pk0', $i],
            ['pk1', $j]
        ];
    }
    $tables[] = [
        'table_name' => 'SampleTable' . $i,
        'max_versions' => 1,
        'primary_keys' => $primary_keys
    ];
}
$request = [
    'tables' => $tables
];
$response = $otsClient->batchGetRow ($request);

// Process each table that is returned. 
foreach ($response['tables'] as $tableData) {
  print "Handling table {$tableData['table_name']} ...\n";

  // Process each row of data in the table. 
  foreach ($tableData['rows'] as $rowData) {

    if ($rowData['is_ok']) {

      // Process the data that is read. 
        $row = json_encode($rowData['primary_key']);
        print "Handling row: {$row}\n";

    } else {

      // Handle errors. 
      print "Error: {$rowData['error']['code']} {$rowData['error']['message']}\n";
    }
  }
}            

The following table describes the examples of detailed sample code.

Example Description
BatchGetRow1.php Shows you how to use BatchGetRow to read multiple rows from a table.
BatchGetRow2.php Shows you how to use BatchGetRow to read multiple rows from multiple tables.
BatchGetRow3.php Shows you how to use BatchGetRow to read specified columns of multiple rows from a table.
BatchGetRow4.php Shows you how to use BatchGetRow to process the results that are returned.
BatchGetRowWithColumnFilter.php Show you how to use BatchGetRow together with filters.

GetRange

You can call this operation to read data whose primary key is within a specified range in a forward or backward direction.

You can also specify the number of rows that you want to read. If the range is large and the number of scanned rows or the volume of scanned data exceeds the upper limit, the scan stops, and the rows that are read and information about the primary key of the next row are returned. You can initiate a request to start from where the last operation left off and read the remaining rows based on information about the primary key of the next row returned by the previous operation.

If one of the following conditions is met, the GetRange operation may stop and return data:
  • The amount of scanned data reaches 4 MB.
  • The number of scanned rows reaches 5,000.
  • The number of returned rows reaches the upper limit.
  • The read throughput is insufficient to read the next row of data because all reserved read throughput is consumed.
Note In Tablestore tables, all rows are sorted by primary key. The primary key of a table sequentially consists of all primary key columns. Therefore, do not assume that the rows are sorted based on a specific primary key column.

API operation

/**
 * Read data whose primary key is within the range that is specified by the start primary key and end primary key. 
 * Note that the server may truncate this range. You need to determine whether to call the GetRange operation again based on the next_start_primary_key value in the response. 
 * You can specify the maximum number of rows to read. 
 * When you specify the start primary key and end primary key, you can use INF_MIN to specify the minimum value and use INF_MAX to specify the maximum value. For more information, see the following sample code. 
 * @api
 * @param [] $request The request parameters. 
 * @return [] The response. 
 * @throws OTSClientException The exception that is returned when a parameter error occurs or the Tablestore server returns a verification error. 
 * @throws OTSServerException The exception that is returned when the Tablestore server returns an error. 
 */
public function getRange(array $request);            

Parameters

GetRange and GetRow have the following differences:
  • The primary_key parameter is changed to the inclusive_start_primary_key and exclusive_end_primary_key parameters. The range is a left-closed and right-open interval.
  • The direction parameter is added to specify the direction for reading.
  • The limit parameter is added to limit the number of returned rows.
Parameter Description
table_name The name of the data table.
inclusive_start_primary_key The start and end primary keys of the range to read. The start and end primary keys must be valid primary keys or virtual points that consist of the INF_MIN and INF_MAX type data. The number of columns for each virtual point must be the same as the number of columns of each primary key.

INF_MIN indicates an infinitely small value. All values of other types are greater than the INF_MIN type value. INF_MAX indicates an infinitely great value. All values of other types are smaller than the INF_MAX type value.

  • inclusive_start_primary_key indicates the start primary key. If the row that contains the start primary key exists, the row of data is returned.
  • exclusive_end_primary_key indicates the end primary key. No matter whether the row that contains the end primary key exists, the row of data is not returned.

The rows in the data table are sorted in ascending order based on the primary key values. The range to read is a left-closed and right-open interval. If data is read in the forward direction, the rows whose primary keys are greater than or equal to the start primary key but smaller than the end primary key are returned.

exclusive_end_primary_key
direction The order in which you want to sort the rows in the response.
  • If you set this parameter to DirectionConst::CONST_FORWARD, the value of the inclusive_start_primary_key parameter must be smaller than the value of the exclusive_end_primary_key parameter, and the rows in the response are sorted in ascending order of primary key values.
  • If you set of this parameter to DirectionConst::CONST_BACKWARD, the value of the inclusive_start_primary_key parameter must be greater than the value of the exclusive_end_primary_key parameter, and the rows in the response are sorted in descending order of primary key values.

For example, if you set the direction parameter to DirectionConst::CONST_FORWARD for a table that contains two primary keys A and B and the value of A is smaller than the value of B, the rows whose primary key values are greater than or equal to the value of A but smaller than the value of B are returned in ascending order from A to B. If you set the direction parameter to DirectionConst::CONST_BACKWARD, the rows whose primary key values are smaller than or equal to the value of B and greater than the value of A are returned in descending order from B to A.

limit The maximum number of rows that you want to return. The value of this parameter must be greater than 0.

An operation stops after the maximum number of rows that you want to return in the forward or backward direction is reached, even if some rows within the specified range are not returned. You can use the value of next_start_primary_key returned in the response to read remaining data in the next request.

max_versions The maximum number of data versions that you want to read.
Note You must specify at least one of max_versions and time_range.
  • If you specify only max_versions, data of up to the specified number of versions is returned from the latest to the earliest.
  • If you specify only time_range, data whose version number is within the specified range or a specified version of data is returned.
  • If you specify both max_versions and time_range, data of up to the specified number of versions within the time range is returned from the latest to the earliest.
time_range The range of versions or the specific version that you want to read. For more information, see TimeRange.
Note You must specify at least one of max_versions and time_range.
  • If you specify only max_versions, data of up to the specified number of versions is returned from the latest to the earliest.
  • If you specify only time_range, data whose version number is within the specified range or a specified version of data is returned.
  • If you specify both max_versions and time_range, data of up to the specified number of versions within the time range is returned from the latest to the earliest.
  • If you want to query data whose versions are within a specified time range, you must specify start_time and end_time. start_time indicates the start timestamp. end_time indicates the end timestamp. The specified range includes the start timestamp and excludes the end timestamp.
  • If you want to query data of a specified version, you must specify specific_time. specific_time indicates a specified timestamp.

You need to specify only one of specific_time and [start_time, end_time).

The timestamp used for the value of time_range ranges from 0 to INT64.MAX. Unit: milliseconds.

columns_to_get The columns that you want to read. You can specify the names of primary key columns or attribute columns.

If you do not specify a column name, all data in the row is returned.

Note
  • By default, Tablestore returns the data from all columns of the row when you query a row. You can configure the columns_to_get parameter to return the data in specified columns. For example, if you include col0 and col1 in columns_to_get, only the values of col0 and col1 are returned.
  • If a row is within the specified range to be read based on the primary key value but does not contain the specified columns to return, the response excludes the row.
  • If you use columns_to_get and column_filter together, Tablestore first queries the columns specified by columns_to_get, and then returns rows that meet the filter conditions.
start_column The column from which the read operation starts in the row. This parameter is used for wide-column read. The response includes the start column.

The columns are sorted based on their names in alphabetical order. Example: A table contains columns a, b, and c. If the value of start_column is b, the read operation starts from column b, and columns b and c are returned.

end_column The column at which the read operation ends in the row. This parameter is used for wide-column read. The response excludes the end column.

The columns are sorted based on their names in alphabetical order. Example: A table contains columns a, b, and c. If the value of end_column is b, the reading ends at column b, and column a is returned.

token The position from which the next wide-column read operation starts. This parameter is unavailable.
column_filter The filter used to filter the query results on the server side. Only rows that meet the filter conditions are returned. For more information, see Filter.
Note If you use columns_to_get and column_filter together, Tablestore first queries the columns specified by columns_to_get, and then returns rows that meet the filter conditions.

Request format

$result = $client->getRange([
    'table_name' => '<string>',                                     // Specify the name of the table. 
    'inclusive_start_primary_key' => [                              // Specify the start primary key. 
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ], 
    'exclusive_end_primary_key' => [                                // Specify the end primary key. 
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ], 
    'direction' => <Direction>,                                     // Specify the order in which you want to sort the rows in the response. 
    'limit' => <Direction>,
    'max_versions' => <integer>,
    'time_range' => [
        'start_time' => <integer>,
        'end_time' => <integer>,
        'specific_time' => <integer>
    ],
    'start_column' => '<string>',
    'end_column' => '<string>',
    'token' => '<string>',
    'columns_to_get' => [
        '<string>',
        '<string>',
        //...   
    ],
    'column_filter' =>  <ColumnCondition>
]);      

Response parameters

Parameter Description
consumed The number of CUs that are consumed by this operation.
capacity_unit indicates the number of read and write CUs that are consumed.
  • read: the read throughput
  • write: the write throughput
primary_key The value of the primary key, which is consistent with that in the request.
attribute_columns The values of attribute columns.
  • Each attribute column is specified by parameters in the following sequence: the attribute column name, attribute column value (ColumnValue), attribute column value type (ColumnType), and timestamp.

    A timestamp is a 64-bit integer, which indicates a version of data. Unit: milliseconds.

  • The attribute columns in the response are sorted by attribute column name in alphabetical order. The versions of the attribute columns are sorted by timestamp in descending order.
  • The order of attribute columns in the response may be different from that in the request.
next_start_primary_key The start primary key of the next read request. The value of next_start_primary_key can be used to determine whether all data is read.
  • If the value of next_start_primary_key is not empty in the response, the next_start_primary_key value can be used as the value of the start primary key for the next GetRange operation.
  • If the value of next_start_primary_key is empty in the response, all data within the range is returned.

Result format

[
    'consumed' => [
        'capacity_unit' => [
            'read' => <integer>,
            'write' => <integer>
        ]
    ],
    'next_start_primary_key' => [ 
        ['<string>', <PrimaryKeyValue>], 
        ['<string>', <PrimaryKeyValue>],
        ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
    ], 
    'rows' => [
        [
            'primary_key' => [ 
                ['<string>', <PrimaryKeyValue>], 
                ['<string>', <PrimaryKeyValue>],
                ['<string>', <PrimaryKeyValue>, <PrimaryKeyType>]
            ],  
            'attribute_columns' => [
                    ['<string>', <ColumnValue>, <ColumnType>, <integer>]
                    ['<string>', <ColumnValue>, <ColumnType>, <integer>]
                    ['<string>', <ColumnValue>, <ColumnType>, <integer>]
            ]
        ],
        // Other rows. 
    ]
]
            

Examples

The following code provides an example on how to read data whose primary key is within a specified range:

// Query the rows whose PK0 value is within [1, 4). 
// You must provide complete primary key columns to specify the range. If the query range does not involve the range of a column value, set the column value to an infinitely great (INF_MAX) or small (INF_MIN) value. 
$startPK = [
    ['PK0', 1], 
    ['PK1', null, PrimaryKeyTypeConst::CONST_INF_MIN]  // INF_MIN indicates an infinitely small value. 
];
// You must provide complete primary key columns to specify the range. If the query range does not involve the range of a column value, set the column value to an infinitely great (INF_MAX) or small (INF_MIN) value. 
$endPK = [
    ['PK0', 4], 
    ['PK1', null, PrimaryKeyTypeConst::CONST_INF_MAX]  // INF_MAX indicates an infinitely great value. 
];
$request = [
    'table_name' => 'SampleTable',
    'max_versions' => 1,                     // Set this parameter to 1 to read the latest version. 
    'direction' => DirectionConst::CONST_FORWARD, // Query data in the forward direction. 
    'inclusive_start_primary_key' => $startPK,    // Specify the start primary key. 
    'exclusive_end_primary_key' => $endPK,        // Specify the end primary key. 
    'limit' => 10                                 // Specify that a maximum of 10 columns can be returned. 
];
$response = $otsClient->getRange ($request);
print "Read CU Consumed: {$response['consumed']['capacity_unit']['read']}\n";

foreach ($response['rows'] as $rowData) {
  // Process each row of data. 
}           

The following table describes the examples of detailed sample code.

Example Description
GetRange1.php Shows you how to use GetRange.
GetRange2.php Shows you how to use GetRange to obtain the specified columns.
GetRange3.php Shows you how to use GetRange to obtain the specified number of rows.
GetRangeWithColumnFilter.php Shows you how you use GetRange together with filter.