This topic describes how to query data in a Lastpoint index by using Tablestore SDK for Java.
Usage notes
The Lastpoint index feature is supported by Tablestore SDK for Java V5.17.1 or later. To use this feature, you must upgrade your Tablestore SDK for Java to V5.17.1 or later.
For information about how to download a new version of Tablestore SDK for Java, see Version history of Tablestore SDK for Java.
Prerequisites
A Lastpoint index is created for a time series table. For more information, see Create a Lastpoint index.
Sample code
The following sample code provides an example on how to call the GetRange operation to read all data from a Lastpoint index:
private static void getRange(SyncClient client) {
// Specify the name of the Lastpoint index.
RangeRowQueryCriteria rangeRowQueryCriteria = new RangeRowQueryCriteria("<LASTPOINT_INDEX_NAME>");
// Construct the start primary key and end primary key. Set the start value to INF_MIN and set the end value to INF_MAX for each primary key column.
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();
rangeRowQueryCriteria.setInclusiveStartPrimaryKey(startPrimaryKey);
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();
rangeRowQueryCriteria.setExclusiveEndPrimaryKey(endPrimaryKey);
//Set the maximum number of versions to 1. Time series tables do not support the max versions feature.
rangeRowQueryCriteria.setMaxVersions(1);
System.out.println("Scan results:");
while (true) {
GetRangeResponse getRangeResponse = client.getRange(new GetRangeRequest(rangeRowQueryCriteria));
for (Row row : getRangeResponse.getRows()) {
System.out.println(row);
}
// If nextStartPrimaryKey is not null, continue reading data.
if (getRangeResponse.getNextStartPrimaryKey() != null) {
rangeRowQueryCriteria.setInclusiveStartPrimaryKey(getRangeResponse.getNextStartPrimaryKey());
} else {
break;
}
}
}
References
For information about how to read data by using Tablestore SDK for Java, see Read data.
If you want to query data in a Lastpoint index by using various query methods in an accelerated manner, such as Boolean query, full-text search, prefix query, and fuzzy query, you can create a search index for the Lastpoint index and use the search index to query data. For more information, see Retrieve a Lastpoint index.