2

I have written a custom http receiver, it get events from another system, and the json sample like :

{"tag":"A01","time":"10:01:00","value":"30.01"},
{"tag":"A01","time":"10:01:01","value":"35.01"},
{"tag":"A01","time":"10:01:02","value":"31.01"},
{"tag":"B01","time":"10:01:00","value":"105.017"},
{"tag":"B01","time":"10:01:01","value":"230.01"},
{"tag":"B01","time":"10:01:02","value":"117.01"}

than the receiver send the json one by one to stream name "tag_input_stream" which contains fields:

tag string, time string, value double

now I have another stream name format_tag_stream which contains field:

time string, tag_A_val double, tag_B_val double

I want to insert values into format_tag_stream from tag_input_stream like this:

10:01:00, 30.01 , 105.017
10:01:01, 35.01 , 230.01
10:01:02, 31.01 , 117.01

I used Execustion Plan to write siddhi script :

from every(e1=tag_input_stream)->e2=tag_input_stream[time==e1.time]
select e1.time as time, e1.value as v1, e2.value as v2
insert into format_tag_stream

But it doesn't work. How to write the script, any example? Thanks

Community
  • 1
  • 1
yeahliu
  • 154
  • 1
  • 8
  • Your query is correct and it should work. probably the events are not received at the execution plan. you can check that by enabling tracing for execution plan HTTP receiver. – Upul Bandara May 12 '16 at 06:19
  • Yes,it should work.But some lines in format_tag_stream was wrong, for example, the value 30.01 that should appear in tag_A_value field, but it actually appear in tag_B_value field. So I changed the 'from' to " from every(e1=tag_input_stream[tag=='A01'])->e2=tag_input_stream[time==e1.time AND tag=='B01'] " .But it only insert one line. – yeahliu May 12 '16 at 06:30

1 Answers1

0

In the query:

from every(e1=tag_input_stream[tag=='A01'])-> e2=tag_input_stream[time==e1.time AND tag=='B01'] 

You assume that event A01 comes first and B01 comes next. However, if they come in reverse order above query will not be executed.

Therefore, please write another query as given below in order to cope with reverse order events.

from every(e1=tag_input_stream[tag=='B01'])-> e2=tag_input_stream[time==e1.time AND tag=='A01']

Thanks,

Upul

Upul Bandara
  • 5,973
  • 4
  • 37
  • 60
  • Do you mean I should write two queries, because of the order? But the receiver will receive so many difference tags values, we can't guarantee the order in which they appear. – yeahliu May 12 '16 at 07:46
  • 1
    Number of events doesn't matter as long as tag values are either A01 or B01. But are there more than 2 tag values? In that case the existing logic won't work. – Rajeev Sampath May 12 '16 at 10:59
  • Yes,more than 2 tag ,for example, "C01" "D01"..., so how siddhi script can do this? – yeahliu May 12 '16 at 11:15