siddhi-io / siddhi

Stream Processing and Complex Event Processing Engine
http://siddhi.io
Apache License 2.0
1.53k stars 528 forks source link

Siddhi Query works with Array fields #1554

Closed pranjal0811 closed 5 years ago

pranjal0811 commented 5 years ago

Does siddhi stream support the nested structure?

Let's consider I have the stream like -

eg :

{
"name" : "abc",
"id" : "xyz",
"account" : [
{"bank":"sbi","bal":100},{"bank":"pnb","bal":1000}
]
}

I have two questions-

  1. How can we define the stream?
  2. How the queries would work in this scenario.

from inputStream(id == 'qwerty' and account.bank == 'sbi') select "AAA" as signal insert into outputStream

Any suggestions?

pcnfernando commented 5 years ago

There are two approaches to achieve your requirement.

  1. You can manually map the incoming complex json object to a attributes using Siddhi-map-json's custom mapping support and use the mapped attributes in the queries.
  2. You can get the complete complex event as a single string attribute and thereafter parse it to a JSON Object using json:toObject() and use the functionalities in https://siddhi-io.github.io/siddhi-execution-json to extract the intended elements.
pcnfernando commented 5 years ago

Closing since answered. Please re-open the issue if you have any concerns.