0

I need to assign a value to a particular attribute in a stream by checking a condition.

How do I do it?

e.g

if a person's name is 'John' and I need to modify his name into 'Peter' and insert into another stream, how do I do it?

from myStream [name == 'John']
select *
insert into outStream;
Community
  • 1
  • 1
DesirePRG
  • 6,122
  • 15
  • 69
  • 114

1 Answers1

0
define stream myStream (name string, attribute1 int, attribute2 bool);

from myStream [name == 'John']                  --This filter matches any event with name equal to 'John'
select "Peter" as name, attribute1, attribute2  --Replaces the current name with 'Peter'
insert into outStream;

Example 1

Input:

{Dilini, 123, true}

Output:

(there'll be no output, since the name doesn't satisfy the condition in the filter, name=='John')

Example 2

Input:

{John, 123, true}

Output:

{Peter, 123, true}

Refer 'Query Projection' capabilities in Siddhi. Check the action: 'Introducing the default value'.

Dilini
  • 777
  • 8
  • 22
  • Mind to [explain your solution](http://stackoverflow.com/help/how-to-answer) a bit? – Markus W Mahlberg Nov 28 '15 at 17:38
  • 2
    It wasn't about me, I don't even know what this is all about. Stumbled upon your answer in the review queue and thought it could need a bit of explanation to improve usefulness for others. – Markus W Mahlberg Nov 28 '15 at 20:02