英文:
Access both object and array first element value in nifi
问题
I'm using executesql processor in apache nifi to extract data from a table.
Table Data
在nifi的executeSql处理器中,在执行SQL查询后,根据给定的条件和数据,我们可以获得一行或两行数据作为输出。
一行输出
两行输出
我找不到一种方法来访问第一行的值,不包括行数因素。
在执行SQL查询后,如果行数大于一,则我必须在EvaluateJsonPath处理器中使用$[0].id
值来获取第一行的id列的值,如果SQL查询的输出只有一行,则我必须使用$.id
值来获取第一行的id列的值。
在这里,如果输出有多行,它会给我们提供对象数组,只能使用$[0].id
来访问,如果输出只有一行,它会给我们提供一个对象,只能使用$.id
来访问。无论行数是1还是多于1,都无法使用$[0].id
来处理两种情况。我应该使用哪个处理器或方法,以便无论行数是1还是多于1,我都可以访问第一行的数据。
英文:
I'm using executesql processor in apache nifi to extract data from a table.
Table Data
Here in executeSql Processor of nifi after executing the sql query we can get one row of data as output or both the rows based on the given conditions and data present.
One Row Output
Two Row Output
I'm not able to find a way to access the values of the first row excluding the number of rows factor.
After executing SQL Query if the number of rows is more than one then I've to use $[0].id
value in EvaluateJsonPath processor to get the value of id column of first row and if the output of sql query is one row only then I've to use $.id
value in EvaluateJsonPath processor to get the value of id column of first row.
Here if the output have multiple rows it gives us arrays of object which can be accessed only using $[0].id
and if the output have only one row it gives us one object which can be accessed only using $.id
. Both the scenario can't be handled using $[0].id
.
Which processor or method should I use so that I can access the data of first row even if the number of rows is 1 only or more than 1.
答案1
得分: 1
One option would be adding a JoltTransformJSON
processor just after the current mentioned processor with the following specification
[
{
"operation": "shift",
"spec": {
"0": { // $[0].id, eg. if there is an array of objects
"id": ""
},
"id": "" // $.id, eg. if there is a single object
}
}
]
英文:
One option would be adding a JoltTransformJSON
processor just after the current mentioned processor with the following speification
[
{
"operation": "shift",
"spec": {
"0": { // $[0].id, eg. if there is array of objects
"id": ""
},
"id": "" // $.id, eg. if there is a single object
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论