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

如何通过QuantumLeap将同模型不同属性数据存入Timescale两张独立表?

同一NGSI-LD实体类型分属性存储到独立Timescale表的解决方案

问题背景

使用NGSI-LD和Orion Context Broker v1.4,需要将Vehicle实体的静态属性(如alternateName、color)和动态属性(如location、speed)分别存储到两张独立的Timescale表中。当前创建的两个订阅均将数据写入同一张表,原始订阅配置如下:

原始订阅1(静态数据)

{
    "description": "Store vehicle data",
    "type": "Subscription",
    "entities": [
        {
            "type": "Vehicle"
        }
    ],
    "watchedAttributes": ["alternateName", "color", "license_plate", "name"],
    "notification": {
        "attributes": ["id", "alternateName", "color", "license_plate", "name"],
        "format": "normalized",
        "endpoint": {
            "uri": "{{quantumleap}}:8668/v2/notify",
            "accept": "application/json"
        }
    }
}

原始订阅2(动态数据)

{
    "description": "Store dynamic data",
    "type": "Subscription",
    "entities": [
        {
            "type": "Vehicle"
        }
    ],
    "watchedAttributes": ["location", "heading", "speed"],
    "notification": {
        "attributes": ["id","location", "heading", "speed"],
        "format": "normalized",
        "endpoint": {
            "uri": "{{quantumleap}}:8668/v2/notify",
            "accept": "application/json"
        }
    }
}

问题原因

QuantumLeap默认根据实体类型(Vehicle)自动创建数据表并映射所有同类型实体的通知数据,因此两个订阅的内容都会写入默认的vehicle表。

解决方法

通过在订阅的通知端点URI中添加table查询参数,强制指定不同的目标表名,Orion会将该参数原样转发给QuantumLeap,实现分表存储。

修改后的订阅配置

静态数据订阅(写入static_vehicle表)

{
    "description": "Store vehicle static data",
    "type": "Subscription",
    "entities": [
        {
            "type": "Vehicle"
        }
    ],
    "watchedAttributes": ["alternateName", "color", "license_plate", "name"],
    "notification": {
        "attributes": ["id", "alternateName", "color", "license_plate", "name"],
        "format": "normalized",
        "endpoint": {
            "uri": "{{quantumleap}}:8668/v2/notify?table=static_vehicle",
            "accept": "application/json"
        }
    }
}

动态数据订阅(写入dynamic_vehicle表)

{
    "description": "Store vehicle dynamic data",
    "type": "Subscription",
    "entities": [
        {
            "type": "Vehicle"
        }
    ],
    "watchedAttributes": ["location", "heading", "speed"],
    "notification": {
        "attributes": ["id","location", "heading", "speed"],
        "format": "normalized",
        "endpoint": {
            "uri": "{{quantumleap}}:8668/v2/notify?table=dynamic_vehicle",
            "accept": "application/json"
        }
    }
}

注意事项

  • 表名需符合PostgreSQL/Timescale的命名规则,避免使用特殊字符或保留字。
  • QuantumLeap默认允许自定义表名,若配置中禁用了该功能,需修改ALLOW_CUSTOM_TABLES参数为true。
  • 查询数据时需指定对应的自定义表名,而非默认的实体类型表名。

内容的提问来源于stack exchange,提问作者sgonzalez.hiades

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 22:12:46