This topic describes how to query data in a Lastpoint index by using Tablestore SDK for Go.
Usage notes
The Lastpoint index feature is supported by Tablestore SDK for Go V1.7.15 or later. To use this feature, you must upgrade your Tablestore SDK for Go to V1.7.15 or later.
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:
func GetRange(client *tablestore.TableStoreClient, lastpointName string) {
getRangeRequest := &tablestore.GetRangeRequest{}
rangeRowQueryCriteria := &tablestore.RangeRowQueryCriteria{}
rangeRowQueryCriteria.TableName = lastpointName
startPK := new(tablestore.PrimaryKey)
startPK.AddPrimaryKeyColumnWithMinValue("_#h")
startPK.AddPrimaryKeyColumnWithMinValue("_m_name")
startPK.AddPrimaryKeyColumnWithMinValue("_data_source")
startPK.AddPrimaryKeyColumnWithMinValue("_tags")
endPK := new(tablestore.PrimaryKey)
endPK.AddPrimaryKeyColumnWithMaxValue("_#h")
endPK.AddPrimaryKeyColumnWithMaxValue("_m_name")
endPK.AddPrimaryKeyColumnWithMaxValue("_data_source")
endPK.AddPrimaryKeyColumnWithMaxValue("_tags")
rangeRowQueryCriteria.StartPrimaryKey = startPK
rangeRowQueryCriteria.EndPrimaryKey = endPK
rangeRowQueryCriteria.Direction = tablestore.FORWARD
//Set the maximum number of versions to 1. Time series tables do not support the max versions feature.
rangeRowQueryCriteria.MaxVersion = 1
getRangeRequest.RangeRowQueryCriteria = rangeRowQueryCriteria
getRangeResp, err := client.GetRange(getRangeRequest)
fmt.Println("get range result is ", getRangeResp)
for {
if err != nil {
fmt.Println("get range failed with error:", err)
}
for _, row := range getRangeResp.Rows {
fmt.Println("range get row with key", row.PrimaryKey.PrimaryKeys[0].Value, row.PrimaryKey.PrimaryKeys[1].Value, row.PrimaryKey.PrimaryKeys[2].Value)
}
if getRangeResp.NextStartPrimaryKey == nil {
break
} else {
fmt.Println("next pk is :", getRangeResp.NextStartPrimaryKey.PrimaryKeys[0].Value, getRangeResp.NextStartPrimaryKey.PrimaryKeys[1].Value, getRangeResp.NextStartPrimaryKey.PrimaryKeys[2].Value)
getRangeRequest.RangeRowQueryCriteria.StartPrimaryKey = getRangeResp.NextStartPrimaryKey
getRangeResp, err = client.GetRange(getRangeRequest)
}
fmt.Println("continue to query rows")
}
fmt.Println("range get row finished")
}References
For information about how to read data by using Tablestore SDK for Go, 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.