全部产品
Search
文档中心

表格存储:读取 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

最新时间点包含的数据字段及其值。