0

我在我的租户中部署了以下示例:

从MeasurementCreated创建上下文HourlyAvgMeasurementDeviceContext分区measurement.source.value;

@Name("Creating_hourly_measurement")
context HourlyAvgMeasurementDeviceContext
insert into CreateMeasurement
select
  m.measurement.source as source,
  current_timestamp().toDate() as time,
  "c8y_AverageTemperatureMeasurement" as type,
  {
    "c8y_AverageTemperatureMeasurement.T.value", avg(cast(getNumber(m, "c8y_TemperatureMeasurement.T.value"), double)),
    "c8y_AverageTemperatureMeasurement.T.unit", getString(m, "c8y_TemperatureMeasurement.T.unit")
  } as fragments
from MeasurementCreated.win:time(1 hours) m
where getObject(m, "c8y_TemperatureMeasurement") is not null
output last every 1 hours;

之后我想得到一个小时内的平均温度值(最好是单位),如下所示:

Select event.c8y_AverageTemperatureMeasurement.T.value from CreateMeasurement event;

但是在将查询部署为时出现错误:

错误开始语句:无法验证选择子句表达式“event.c8y_AverageTemperatureMeasure ...(47个字符)”:无法将属性“event.c8y_AverageTemperatureMeasurement.T.value”解析为流或流中的嵌套属性[选择事件。 c8y_AverageTemperatureMeasurement.T.value 来自 CreateMeasurement 事件

你能帮忙吗?

4

1 回答 1

1

代替

select event.c8y_AverageTemperatureMeasurement.T.value from CreateMeasurement event;

你需要使用

select getNumber(event, "c8y_AverageTemperatureMeasurement.T.value") from CreateMeasurement event;

如果对象中有自定义属性,则无法通过点语法访问它们。您需要使用 getNumber 或 getString 之类的函数来传递对象和要抓取的 JSONPath。如果未找到,这些函数将返回 null。

于 2017-03-16T12:18:50.923 回答