在esper语句中使用自定义类型属性的QuarkIoE

时间:2016-06-16 09:34:42

标签: cumulocity

我很难使用自定义类型的属性来编写像上下文这样的语句。例如,这是有效的:

create context TripContext
  context PartionBySource
    partition by source from EventCreated,

  context ContextBorders
    initiated by EventCreated(
      type="c8y_SwitchPowerReport") as startEvent

    terminated by EventCreated(
      type="c8y_SwitchPowerReport") as endEvent;

然而,这还不够,我需要检查一些自定义属性以更好地定义上下文。我希望能够做到这样的事情:

create context TripContext
  context PartionBySource
    partition by
      source,
      getString(????, "customProp1"),
      getNumber(????, "customProp2"),
      ...
    from EventCreated,

  context ContextBorders
    initiated by EventCreated(
      type="c8y_SwitchPowerReport",
      getString(startEvent, "c8y_SwitchPower.newStatus") = "ON") as startEvent

    terminated by EventCreated(
      type="c8y_SwitchPowerReport",
      getString(endEvent, "c8y_SwitchPower.newStatus") = "OFF") as endEvent;

我不知道该放什么而不是????引用该事件。它对源,时间,类型等“本机”属性是透明的,但只要有自定义属性,我就不知道如何访问它。

至于启动/终止的语法,有些东西真的很奇怪,我不明白,但也许它更像是Esper而不是Cumulocity问题。这是有效的:

terminated by EventCreated(
  type="c8y_SwitchPowerReport",
  getString(endEvent, "c8y_SwitchPower.newStatus") = "OFF") as endEvent

但这不是:

initiated by EventCreated(
  type="c8y_SwitchPowerReport",
  getString(startEvent, "c8y_SwitchPower.newStatus") = "ON") as startEvent

我收到错误说:

  

无法验证单行函数参数表达式'startEvent':名为'startEvent'的属性在任何流中无效

任何见解都将受到赞赏。

1 个答案:

答案 0 :(得分:1)

我也找不到像你一样尝试快速运行的方法。 但我会建议采用以下方法。如果你在自定义片段上大量相关,那么通过提取这个值的附加流来运行事件是有意义的:

create schema MyCustomEvent(
  event Event,
  myCustomString String,
  myCustomNumber BigDecimal
);

insert into MyCustomEvent
select
  e.event as Event,
  getString(e, "myCustomString") as myCustomString,
  getNumber(e, "myCustomNumber") as myCustomNumber
from EventCreated e
where getString(e, "myCustomString") is not null
and getNumber(e, "myCustomNumber") is not null;

现在,您可以在EventCreated上轻松地在MyCustomEvent上创建上下文。