如何从筛选器中选择一个属性?

huangapple go评论93阅读模式
英文:

How to select an attribute from filters?

问题

我有一个查询,如下所示 -

from xyzStream [str:contains(name,'John') or str:contains(name,'Peter')  or str:contains(name,'Sandy') ]
select name 
insert into outputStream

但现在我想进行一个增强,其中我要传递匹配的过滤子字符串。例如,如果str:contains(name,'John')返回true,那么在输出流中插入'John'。

在SiddhiQL中是否有一种方法可以做到这一点?

英文:

I have a query written as -

from xyzStream [str:contains(name,'John') or str:contains(name,'Peter')  or str:contains(name,'Sandy') ]
select name 
insert into outputStream

but now i want to make an enhancement where i pass the filter substring that matched. Like for example if str:contains(name,'John') returns true, insert 'John' in output stream.

Is there a way to do it in SiddhiQL?

答案1

得分: 1

截止目前,不支持此功能,但您可以在选择子句中使用str:contains和ifthenElse来实现相同的效果,

from xyzStream [str:contains(name,'John') or str:contains(name,'Peter')  or str:contains(name,'Sandy') ]
select name, 
    ifthenElse(str:contains('John'), 'John', ifThenElse(str:contains('Peter'), 'Peter', 'Sandy')) as matchedString
insert into outputStream

更多详情请参见示例中的ifThenElse函数。

英文:

As of now, this is not supported, however you can do the same in the select clause with str:contains and ifthenElse,

from xyzStream [str:contains(name,'John') or str:contains(name,'Peter')  or str:contains(name,'Sandy') ]
select name, 
    ifthenElse(str:contains('John'), 'John', ifThenElse(str:contains('Peter'), 'Peter', 'Sandy')) as matchedString
insert into outputStream

See example on ifThenElse function for more details

huangapple
  • 本文由 发表于 2020年1月3日 20:43:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578868.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定