【发布时间】:2020-06-08 11:07:26
【问题描述】:
我需要执行复杂的 json 处理。 我几乎完成了,但对基于属性过滤事件的逻辑感到震惊。我知道在正常基础上进行过滤,但这是将 tokenizeAsObject 函数写在 from 语句旁边的情况。 在这种情况下,过滤部分应该写在哪里以及如何写? 非常感谢您的帮助。 我可以找到查询的正常过滤,但在代码的查询/分析数据部分中找不到任何具有标记化方法的内容。
--THE CODE GOES HERE
@App:name('CompanyClientDetailingApp3')
@App:description('Description of the client details of the company')
@source(type='http', receiver.url='http://localhost:5005/clientDetails',
@map(type='json', @attributes(json = '$')
)
)
define stream CompanyClientStream3 (json string);
@sink(type = 'log',
@map(type = 'passThrough'))
define stream EachProjectStream3 (Client string, clientContractTerm string, projectName string, projectContractTerm int);
@info(name = 'clientProjectquery')
from CompanyClientStream3#json:tokenizeAsObject(json, '$.CompanyClients')
select json:getString(jsonElement, '$.Client') as Client, json:getString(jsonElement, '$.Invoice.ContractTerm') as clientContractTerm, json:getObject(jsonElement, '$.Invoice.Projects') as projectList
insert into EachClientProjectStream3;
@info(name = 'projectSttreamQuery')
from EachClientProjectStream3#json:tokenizeAsObject(projectList, "$")
select Client, clientContractTerm, json:getString(jsonElement, '$.ProjectName') as projectName, json:getInt(jsonElement, '$.ProjectTerm') as projectContractTerm
insert into EachProjectStream3;
过滤基于 ProjectTerm。即 Projecterm > 5 年的项目必须流出。
--Inputs for the same
{
"CompanyClients": [
{
"Client": "C1",
"Invoice": {
"ContractTerm": "5",
"Unit": "years",
"Projects": [
{"ProjectName":"C1P1", "ProjectTerm":"5", "TermUnit": "years"},
{"ProjectName":"C1P2", "ProjectTerm":"3", "TermUnit": "years"},
{"ProjectName":"C1P3", "ProjectTerm":"2", "TermUnit": "years"}
]
}
},
{
"Client": "C3",
"Invoice": {
"ContractTerm": "10",
"Unit": "years",
"Projects": [
{"ProjectName":"C3P1", "ProjectTerm":"8", "TermUnit": "years"},
{"ProjectName":"C3P2", "ProjectTerm":"5", "TermUnit": "years"},
{"ProjectName":"C3P3", "ProjectTerm":"6", "TermUnit": "years"}
]
}
}
]
}
谢谢, 考希克。
【问题讨论】:
标签: json wso2 complex-event-processing siddhi wso2sp