全部產品
Search
文件中心

Tablestore:讀取 Lastpoint 索引資料

更新時間:Aug 04, 2026

使用 Java SDK 按主鍵範圍讀取 Lastpoint 索引中每條時間軸的最新時間點資料。

前提條件

安裝Tablestore Java SDK並初始化用戶端。Lastpoint 索引需要使用 5.17.1 及以上版本,建議使用最新版本。

功能說明

Lastpoint 索引可以按資料表讀取。調用 getRange 方法並指定主鍵範圍,可讀取範圍內的最新時間點資料。對於使用預設時間軸標識的時序表,Lastpoint 索引依次包含 _#h_m_name_data_source_tags 四個主鍵列。

public GetRangeResponse getRange(GetRangeRequest getRangeRequest) throws TableStoreException, ClientException

以下樣本將四個主鍵列的起始值設定為 INF_MIN,結束值設定為 INF_MAX,分頁讀取 example_lastpoint_index 中的全部資料。

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());
}

參數說明

GetRangeRequest 包含以下參數。

名稱

類型

說明

rangeRowQueryCriteria(必選)

RangeRowQueryCriteria

範圍讀取條件。

範圍讀取條件

rangeRowQueryCriteria 包含以下參數。

名稱

類型

說明

tableName(必選)

String

Lastpoint 索引名稱。

inclusiveStartPrimaryKey(必選)

PrimaryKey

讀取範圍的起始主鍵,包含該主鍵。必須按索引中的順序設定全部主鍵列。

exclusiveEndPrimaryKey(必選)

PrimaryKey

讀取範圍的結束主鍵,不包含該主鍵。必須按索引中的順序設定全部主鍵列。

maxVersions(必選)

int

每列最多返回的版本數。Lastpoint 索引中的每個欄位只保留最新值,設定為 1

columnsToGet(可選)

Set<String>

要返回的屬性列名稱。不設定時返回全部屬性列。

direction(可選)

Direction

讀取方向,取值為 FORWARDBACKWARD,預設值為 FORWARD

limit(可選)

int

單次請求最多返回的行數,必須大於 0。不設定時使用 SDK 預設值 -1

傳回值

GetRangeResponse 包含以下業務返回欄位。

欄位

類型

說明

rows

List<Row>

通過 getRows() 擷取本次請求返回的 Lastpoint 資料。

nextStartPrimaryKey

PrimaryKey

通過 getNextStartPrimaryKey() 擷取下一次讀取的起始主鍵。返回 null 表示已讀取完指定範圍內的資料。

Lastpoint 資料結構

對於使用預設時間軸標識的時序表,每行 Lastpoint 資料包含以下欄位。

欄位

類型

說明

_#h

String

系統根據時間軸產生的分區鍵。

_m_name

String

度量名稱。

_data_source

String

資料來源。

_tags

String

時間軸標籤。

_time

long

最新時間點的時間戳記,單位為微秒。

資料欄位

ColumnValue

最新時間點包含的資料欄位及其值。