【问题标题】:Concat multiple columns with filter in QueryRecord (NiFi)在 QueryRecord (NiFi) 中使用过滤器连接多列
【发布时间】:2021-07-14 23:52:02
【问题描述】:

我有一个 JSON 看起来像:

[ {
  "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"
}]

我想要什么:

[ {
  "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"
}]

如果某些utm值在()内我应该忽略它(键+值),它可以是(none)(direct)(not provided)(not set)

我试过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

但它不会截断像(none)(direct) 这样的值。如何改进语句?

【问题讨论】:

    标签: apache-nifi


    【解决方案1】:

    QueryRecord 使用 Apache Calcite 进行 SQL 解析/评估,看看他们的 CASE 语句,你也许可以做类似CASE WHEN utm_source != '(not set)' THEN '&utm_source=' || utm_source ELSE '' END的事情

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多