Cloud Workflows 中的数据操作或扩充

data manipulation or enrichment in Cloud Workflows

如何进行简单的数据操作或扩充?

通常,在管道中,您使用 DataFlow 作业,但 Cloud Workflows 中是否有选项来做这类事情?

您可以通过声明一个 Dictionary 并重复使用来随时随地收集东西来实现此功能。

需要注意的是,您需要在添加新值时再次重新键入所有键,因为变量引用、合并键或 YAML 锚点尚未实现。

所以如果你开始:

- initDictionary:
    assign:
      - myDictionary:
          name: John
          lastName: Smith
          dayOfTheWeek: ${currentTime.body.dayOfTheWeek}

您稍后可以从另一个结果中添加一个键,例如从维基百科中这样:

- enrichStep:
    assign:
      - myDictionary:
          name: ${myDictionary.name}
          lastName: ${myDictionary.lastName}
          dayOfTheWeek: ${currentTime.body.dayOfTheWeek}
          wikiResult: ${wikiResult.body[1]}

这里有完整的 wikipedia_enrichment.yaml 序列。

- getCurrentTime:
    call: http.get
    args:
        url: https://us-central1-workflowsample.cloudfunctions.net/datetime
    result: currentTime
- initDictionary:
    assign:
      - myDictionary:
          name: John
          lastName: Smith
          dayOfTheWeek: ${currentTime.body.dayOfTheWeek}
- readWikipedia:
    call: http.get
    args:
        url: https://en.wikipedia.org/w/api.php
        query:
            action: opensearch
            search: ${currentTime.body.dayOfTheWeek}
    result: wikiResult
- enrichStep:
    assign:
      - myDictionary:
          name: ${myDictionary.name}
          lastName: ${myDictionary.lastName}
          dayOfTheWeek: ${currentTime.body.dayOfTheWeek}
          wikiResult: ${wikiResult.body[1]}
- returnResult:
    return: ${myDictionary}