NiFi UpdateRecord不会更新嵌套字段

时间:2019-04-19 11:30:04

标签: apache-nifi

我正在尝试使用UpdateRecord替换嵌套字段的值。我敢肯定我正确地遵循了the documentation,但是即使使用//也无法正常工作,但我只能更新顶级字段的值。我在下面的UpdateRecord设置中有几种配置,但是只有最后一个用于更新requestObject的配置才起作用。

我确定自己的架构是正确的,因为我已使用它将XML毫无问题地转换为JSON。

我有以下内容:

输入XML文件:

<request>
    <requestType>BULKRETRIEVE</requestType>
    <requestDomainType>ROI</requestDomainType>
    <systemName>SYSTEMTEST</systemName>
    <location>USA</location>    
    <userInformation>
        <userId>1313</userId>
        <firstName>Some</firstName> <!-- required -->
        <lastName>Guy</lastName> <!-- required -->
        <email>email@address.com</email> <!-- required if phone not included -->
        <phone></phone> <!-- required if email not included -->
    </userInformation>  
    <requestObject>
        <startDate>2019-01-01T00:00:00.000-05:00</startDate>
        <endDate>2019-01-31T00:00:00.000-05:00</endDate>
        <type>ROI</type>
    </requestObject>
</request>

AVRO模式:

{
    "namespace": "com.organization.somethingspecific",
    "name": "request",
    "type": "record",
    "fields": [
      {"name": "requestType", "type": ["string","null"], "default": null},
      {"name": "requestDomainType", "type": ["string","null"], "default": null},
      {"name": "systemName", "type": ["string","null"], "default": null},
      {"name": "location", "type": ["string","null"], "default": null},
      {"name": "userInformation", "type": ["null", {
        "name": "userInformation", "type": "array", "items": {
          "name": "userInformation", "type": "record", "fields": [
            {"name": "userId", "type": ["string","null"], "default": null},
            {"name": "firstName", "type": ["string","null"], "default": null},
            {"name": "lastName", "type": ["string","null"], "default": null},
            {"name": "email", "type": ["string","null"], "default": null},
            {"name": "phone", "type": ["string","null"], "default": null}
          ]
        }
      }], "default": null},
      {"name": "requestObject", "type": ["null",{
        "name": "requestObject", "type": "array", "items": {
          "name": "requestObject", "type": "record", "fields": [
            {"name": "startDate", "type": ["string","null"], "default": null},
            {"name": "endDate", "type": ["string","null"], "default": null},
            {"name": "type", "type": ["string","null"], "default": null}
          ]
        }
      }], "default": null}
    ]
}

并且我的UpdateRecord处理器配置为: UpdateRecord

1 个答案:

答案 0 :(得分:1)

在您的架构中,requestObject字段是一个数组,因此您无法指定/ requestObject / startDate之类的内容,因为它不指示要更新数组中的哪个元素。

我认为您应该可以执行/ requestObject [*] / startDate之类的操作,该操作可以更改requestObject数组中所有条目的startDate字段。

参考文档:

https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.2/org.apache.nifi.processors.standard.UpdateRecord/additionalDetails.html