apache-nifi - Concat multiple columns with filter in QueryRecord (NiFi)
问题描述
I have a JSON looks like:
[ {
"metric_name" : "ga:bounces",
"metric_value" : "16",
"report_date" : "20210625",
"utm_campaign" : "retail_group",
"utm_source" : "(direct)",
"utm_content" : "(not set)",
"utm_term" : "(not set)",
"utm_medium" : "search"
}, {
"metric_name" : "ga:sessionDuration",
"metric_value" : "1576.0",
"report_date" : "20210625",
"utm_campaign" : "rb_olv",
"utm_source" : "google",
"utm_content" : "(not set)",
"utm_term" : "(not set)",
"utm_medium" : "cpc"
}]
What I want:
[ {
"metric_name" : "ga:bounces",
"metric_value" : "16",
"report_date" : "20210625",
"utm_marks" : "utm_campaign=retail_group&utm_medium=search"
}, {
"metric_name" : "ga:sessionDuration",
"metric_value" : "1576.0",
"report_date" : "20210625",
"utm_marks" : "utm_campaign=rb_olv&utm_source=google&utm_medium=cpc"
}]
If some of utm values are inside ()
I should ignore it (key + value), it can be (none)
, (direct)
, (not provided)
, (not set)
I tried with QueryRecord
:
SELECT
metric_name,
metric_value,
'utm_campaign=' || utm_campaign || '&utm_source=' || utm_source || '&utm_medium=' || utm_medium || '&utm_term=' || utm_term || '&utm_content=' || utm_content as utm_marks
FROM FLOWFILE
But it will not truncate values like (none)
, (direct)
. How can I improve statement?
解决方案
QueryRecord 使用 Apache Calcite 进行 SQL 解析/评估,看看他们的 CASE 语句,你也许可以做类似的事情CASE WHEN utm_source != '(not set)' THEN '&utm_source=' || utm_source ELSE '' END
推荐阅读
- javascript - 更改元素值时更新复选框状态
- android - Vimeo 上传:恢复上传时出现意外状态代码 (404)
- python - 'str' 对象不能解释为整数(Python 3.8)
- r - data.table - 删除 R 中计数不等的所有组
- powerbi - DAX - 获取先前的值
- powershell - ADO API 使用变更集编号下载文件
- node.js - 尝试使用 mongoose 将对象保存到 MongoDB 时出错
- r - 从变量名创建字符串并通过递归函数运行
- python - 通过 Python 从维基百科下载数据时如何解决 SSL 错误问题
- asp.net-core - 如何在 Asp.Net Core 中的 Web api 的 SimpleInjector 等依赖容器中注册 IHubContext?