【问题标题】:Conditional expression in SnapLogicSnapLogic 中的条件表达式
【发布时间】:2020-04-01 06:59:32
【问题描述】:

我需要检查 REST 调用的数据输出中是否存在条目。 JSON 输出如下所示:

{
  "entity":  {
    "entries":[
      {
        "ID": "1",
        "Pipeline": "Pipeline_1",
        "State":"Completed"
      }
    ],
  "duration":1074,
  "create_time":"2010-10-10"
  }
}

我想检查例如 Pipeline_1 是否丢失,然后我希望管道打印出“Pipeline_1 丢失”,如果不是 - null。我尝试过使用三元 (?) 表达式:

!$Pipeline.contains ("Pipeline_1") ? "Pipeline_1 is missing" : null && !$Pipeline.contains ("Pipeline_2") ? "Pipeline_2 is missing" : null

我的语法有问题,我无法使用此方法正确处理,因为它只处理第一个查询。

我也尝试过使用match 方法,但也没有成功:

match $Pipeline {
    $Pipeline!=("Pipeline_1") => 'Pipeline_1 is missing',
    $Pipeline!=("Pipeline_2") => 'Pipeline_2 is missing',
    _ => 'All of the pipelines have been executed successfully'
}

我必须检查多个条件。关于我应该如何嵌套条件表达式的任何建议?提前谢谢你。

【问题讨论】:

  • 目前还不清楚您期望的最终输出是什么。
  • 另外,如果 $Pipelineentries[] 数组中的对象的一部分,您如何在根中获取它。在进行验证之前,您是否使用表达式 $entity.entries[*] 进行拆分?
  • 如果是拆分,那么如何仅基于一个对象进行验证?如果你不分裂,那么共享表达式都不会起作用。

标签: json nested mapping match snaplogic


【解决方案1】:

假设您没有拆分数组 $entity.entries[*] 并按原样处理传入的文档,以下是可能的解决方案。

测试管道:

输入:

{
    "entity": {
        "entries": [
            {
                "ID": "1",
                "Pipeline": "Pipeline_1",
                "State": "Completed"
            }
        ],
        "duration": 1074,
        "create_time": "2010-10-10"
    }
}

表达式:

{
    "Pipeline_1": $entity.entries.reduce((a, c) => c.Pipeline == "Pipeline_1" || a, false),
    "Pipeline_2": $entity.entries.reduce((a, c) => c.Pipeline == "Pipeline_2" || a, false)
}.values().reduce((a, c) => c && a, true) ? "All pipelines executed successfully" : "Pipeline(s) missing"

输出:


如果您不想希望在单个表达式中执行此操作,则可以使用 Conditional 快照,如下所示。

以下是条件快照的输出。

那么你就可以随意处理了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多