全部產品
Search
文件中心

Tablestore:查詢Lastpoint索引資料

更新時間:Apr 30, 2026

通過Go SDK調用GetRange介面,讀取Lastpoint索引中的全部資料。

注意事項

Lastpoint索引功能要求Table StoreGo SDK v1.7.15及以上版本,請在使用前確認SDK版本。

前提條件

已在時序表上建立Lastpoint索引。具體操作,請參見建立Lastpoint索引

查詢Lastpoint索引資料

Lastpoint索引為每個時間序列儲存最新的資料點,無需掃描整張時序表即可擷取各時間序列的最新狀態。使用GetRange介面可全量掃描Lastpoint索引,一次性讀取所有時間序列的最新值。

以下樣本讀取Lastpoint索引中的全部行。MaxVersion固定設定為1:Lastpoint索引採用最新點語義,每個主鍵只保留最近一次寫入,因此每行只存在一個版本。

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
	// MaxVersion固定為1:Lastpoint索引採用最新點語義,每個主鍵只保留最近一次寫入。
	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")
}

相關文檔

  • 如需瞭解更多通過Go SDK讀取資料的方式,請參見讀取資料

  • 如需對Lastpoint索引執行多條件組合查詢、全文檢索索引、首碼查詢、模糊查詢等更靈活的加速查詢,可在Lastpoint索引上建立多元索引。更多資訊,請參見檢索Lastpoint索引