[英]Nifi QueryRecord on Array of String contains value
Using Apache Nifi i am trying to figure out how to find records which have a string in an array that start with a value使用 Apache Nifi,我试图找出如何在数组中查找以值开头的字符串的记录
Given the below array, i would like only record which have a tag that start with '/test2/'给定以下数组,我只想记录具有以 '/test2/' 开头的标签
[
{
"name":"bob",
"tags":[ "/test1/foo","/alpha"]
}
,
{
"name":"bill",
"tags":[ "/test2/blah","/beta"]
}
]
SELECT * FROM FLOWFILE WHERE RPATH_STRING(tags, '/') LIKE '/test2/%' SELECT * FLOWFILE WHERE RPATH_STRING(tags, '/') LIKE '/test2/%'
due to java.lang.String cannot be cast to org.apache.nifi.serialization.record.Record: java.lang.ClassCastException: java.lang.String cannot be cast to org.apache.nifi.serialization.record.Record
I've tried a few other permutations, but no luck.我尝试了其他一些排列,但没有运气。
Possible solution with 2 processors ( ScriptedTransformProcessor
-> QueryRecord
):使用 2 个处理器(
ScriptedTransformProcessor
-> QueryRecord
)的可能解决方案:
ScriptedTransformProcessor (add new field tags_str
- concatenating all of the elements in tags
with delimiter |
) ScriptedTransformProcessor (添加新字段
tags_str
- 用分隔符|
连接tags
中的所有元素)
Script Language
: Groovy
Script Language
: Groovy
Script Body
: Script Body
:record.setValue('tags_str', record.getValue('tags').join("|"))
record
Output (JSON): Output(JSON):
[ {
"name" : "bob",
"tags" : [ "/test1/foo", "/alpha" ],
"tags_str" : "/test1/foo|/alpha"
}, {
"name" : "bill",
"tags" : [ "/test2/blah", "/beta" ],
"tags_str" : "/test2/blah|/beta"
} ]
QueryRecord (filter)查询记录(过滤器)
SELECT name, tags
FROM FLOWFILE
WHERE tags_str LIKE '%/test2/%'
output (JSON): output(JSON):
[ {
"name" : "bill",
"tags" : [ "/test2/blah", "/beta" ]
} ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.