You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GridDB插入TimeSeries容器触发GSException的原因及正确插入方法

异常原因

错误码140002:ROW_KEY_NOT_FOUND的原因很明确:你插入的行未设置TimeSeries容器要求的行键。GridDB的TimeSeries容器默认将TIMESTAMP类型的列作为行键(主键),所有时间序列数据必须包含有效的时间戳才能被存储。你的代码中仅设置了value列的值,完全未指定timestamp列的内容,因此触发了该异常。

正确插入方式

方式1:直接操作Row对象

需要为Row补充设置timestamp列的值,同时修正TimeSeries的泛型参数(直接操作Row时泛型应为Row):

GridStore store = ...;
ContainerInfo containerInfo = new ContainerInfo();
containerInfo.setType(TimeSeries.class);
containerInfo.setColumnInfoList(Arrays.asList(
    new ColumnInfo("timestamp", GSType.TIMESTAMP),
    new ColumnInfo("value", GSType.INTEGER)
));

// 泛型指定为Row,匹配直接操作Row对象的场景
TimeSeries<Row> ts = store.putTimeSeries("sensor_data", containerInfo);

Row row = ts.createRow();
// 按列索引设置timestamp(索引0对应第一个列),这里用当前时间示例
row.setTimestamp(0, new Date());
// 也可以按列名设置:row.setTimestamp("timestamp", new Date());
row.setInteger(1, 100);
ts.put(row);

方式2:使用自定义实体类(更简洁)

定义带@RowKey注解的实体类,让GridDB自动映射字段:

// 实体类定义
public class SensorData {
    @RowKey // 标记该字段为行键(对应timestamp列)
    private Date timestamp;
    private int value;

    // 构造函数
    public SensorData(Date timestamp, int value) {
        this.timestamp = timestamp;
        this.value = value;
    }

    // 必须提供无参构造函数(GridDB反射需要)
    public SensorData() {}

    // 省略getter和setter方法
}

然后直接插入实体对象:

TimeSeries<SensorData> ts = store.putTimeSeries("sensor_data", SensorData.class);
// 创建实体对象并插入
ts.put(new SensorData(new Date(), 100));

内容的提问来源于stack exchange,提问作者Nooruddin Lakhani

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 04:42:13