Add UNKNOWN eventstreams to CEP Engine and get a list of all properties (payload) of this event

微笑、不失礼 提交于 2021-01-07 02:35:28

问题


I want to be able to add event streams where I don't know beforehand what kind of properties the events have. So I don't know before if there is an integer ID or if there is a date timestamp and which payload might be there. As soon as I add such an unknown event, Esper should examine the stream and return the contained properties of the stream to me.


回答1:


Thank you very much. That actually helps me a lot. But a function which returns all property names directly does not exist, does it? So I would have to use dynamic parameters (trial and error) until I know which ones exist in the eventstream.

Thank you for your help :)




回答2:


See similar to Add Sensorevents to CEP Engine and get a list of all properties

In the case that you don't have some or all of the properties, you can add the stream without any properties or with those properties that you know that the events have. Here is how to add a stream where you don't know any properties in advance:

@public @buseventtype create schema MyStream()

You can now use EPEventServive#sendEvent to send events.

You can use this stream in various ways. You can simply select the event.

select * from MyStream

Or you can use the dynamic property names, those with a '?' questionmark appended to them. This can refer to properties that may or may not exist.

select id? as id from MyStream

The "id?" returns an Object-type value. You can use "cast" to make it, for instance, a double-type value to total up.

select id? as id, sum(cast(someNumericProperty?, double)) as total from MyStream where 

When the property doesn't exist the "?" expression returns null. There is an "exists" function that returns true when the parameter that is a dynamic property exists.

I don't think the Esper runtime actually knows about any dynamic property until the EPL attempts to use that dynamic property. The runtime doesn't inspect any event for actual properties.

You can add your own user-defined function that determines what the property names may be for your specific event underlying. So when the underlying is a java.util.Map the user-defined function can return "event.keySet()".



来源:https://stackoverflow.com/questions/65094492/add-unknown-eventstreams-to-cep-engine-and-get-a-list-of-all-properties-payload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!