0

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

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”的属性在任何流中均无效

任何见解将不胜感激。

4

1 回答 1

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;

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

于 2016-06-16T10:07:05.500 回答