Read data from a Lastpoint index
Use Tablestore SDK for Java to read the latest data point of each time series from a Lastpoint index by primary key range.
Prerequisites
Install the Tablestore SDK for Java and initialize a client. Lastpoint indexes require version 5.17.1 or later. We recommend that you use the latest version.
Description
A Lastpoint index can be read as a data table. Call getRange and specify a primary key range to read the latest data points in the range. For a time series table that uses the default time series identifiers, the Lastpoint index contains the _#h, _m_name, _data_source, and _tags primary key columns in this order.
public GetRangeResponse getRange(GetRangeRequest getRangeRequest) throws TableStoreException, ClientException
The following example sets the start values of the four primary key columns to INF_MIN and the end values to INF_MAX. The example then reads all data from example_lastpoint_index across multiple pages.
RangeRowQueryCriteria criteria =
new RangeRowQueryCriteria("example_lastpoint_index");
PrimaryKey startPrimaryKey = PrimaryKeyBuilder.createPrimaryKeyBuilder()
.addPrimaryKeyColumn("_#h", PrimaryKeyValue.INF_MIN)
.addPrimaryKeyColumn("_m_name", PrimaryKeyValue.INF_MIN)
.addPrimaryKeyColumn("_data_source", PrimaryKeyValue.INF_MIN)
.addPrimaryKeyColumn("_tags", PrimaryKeyValue.INF_MIN)
.build();
PrimaryKey endPrimaryKey = PrimaryKeyBuilder.createPrimaryKeyBuilder()
.addPrimaryKeyColumn("_#h", PrimaryKeyValue.INF_MAX)
.addPrimaryKeyColumn("_m_name", PrimaryKeyValue.INF_MAX)
.addPrimaryKeyColumn("_data_source", PrimaryKeyValue.INF_MAX)
.addPrimaryKeyColumn("_tags", PrimaryKeyValue.INF_MAX)
.build();
criteria.setInclusiveStartPrimaryKey(startPrimaryKey);
criteria.setExclusiveEndPrimaryKey(endPrimaryKey);
criteria.setMaxVersions(1);
while (true) {
GetRangeResponse response =
client.getRange(new GetRangeRequest(criteria));
response.getRows().forEach(System.out::println);
if (response.getNextStartPrimaryKey() == null) {
break;
}
criteria.setInclusiveStartPrimaryKey(
response.getNextStartPrimaryKey());
}
Parameters
GetRangeRequest contains the following parameter.
|
Name |
Type |
Description |
|
rangeRowQueryCriteria (required) |
|
The range read criteria. |
Range read criteria
rangeRowQueryCriteria contains the following parameters.
|
Name |
Type |
Description |
|
tableName (required) |
|
The Lastpoint index name. |
|
inclusiveStartPrimaryKey (required) |
|
The inclusive start primary key. Specify all primary key columns in the order defined in the index. |
|
exclusiveEndPrimaryKey (required) |
|
The exclusive end primary key. Specify all primary key columns in the order defined in the index. |
|
maxVersions (required) |
|
The maximum number of versions to return for each column. A Lastpoint index retains only the latest value of each field. Set this parameter to |
|
columnsToGet (optional) |
|
The attribute columns to return. If this parameter is not specified, all attribute columns are returned. |
|
direction (optional) |
|
The read direction. Valid values: |
|
limit (optional) |
|
The maximum number of rows to return in a request. The value must be greater than |
Response
GetRangeResponse contains the following operation-specific fields.
|
Field |
Type |
Description |
|
|
|
Call |
|
|
|
Call |
Lastpoint row schema
For a time series table that uses the default time series identifiers, each Lastpoint row contains the following fields.
|
Field |
Type |
Description |
|
|
|
The system-generated partition key for the time series. |
|
|
|
The measurement name. |
|
|
|
The data source. |
|
|
|
The time series tags. |
|
|
|
The timestamp of the latest data point, in microseconds. |
|
Data fields |
|
The data fields and values in the latest data point. |