我以前从未使用过颠簸变换,我也不知道如何修复我所做的事情,所以我很抱歉,如果这实际上是一个非常简单的修复。
我有两个XML文件(下面是虚拟版本,实际包含PII),我使用MergeRecord在NiFi中合并了这些文件。由于输出的方式(一个流文件和一个JSONS数组),建议我使用JoltTransform将它们正确地合并在一起。有人向我指出了this关于如何在NiFi中进行流连接的问题(这正是我所需要的)。
虽然这在很大程度上是可行的,但我仍然有一个问题。我的“基本”级别上的所有标记(FatherID、FatherName、BirthDate等)被转换成数组。我需要这些不是数组,因为我希望使用我在MergeRecord中使用的组合模式(它没有将这些字段作为数组)。
规范中是否需要更改某些内容,或者是否需要执行另一个JoltTransform (这很好)?
输入XML 1
<?xml version="1.0" encoding="UTF-8"?>
<FoundingFathers>
<FatherID>1234</FatherID>
<FatherName>George Washington</FatherName>
<ResidentialInformation>
<Name>Mount Vernon</Name>
<StreetAddress>3200 Mount Vernon Hwy</StreetAddress>
<City>Mt Vernon</City>
<State>VA</State>
<ZipCode>22121</ZipCode>
</ResidentialInformation>
<BirthDate>1732-02-22</BirthDate>
</FoundingFathers>输入XML 2
<?xml version="1.0" encoding="UTF-8"?>
<DOC>
<DOCID>1234</DOCID>
<FATHERNAME>George Washington</FATHERNAME>
<RAW_TXT>George Washington lived in Mount Vernon in Mt Vernon, VA. The Washington family had owned land in the area since 1674. The original house was built in 1734 by Washington's father.</RAW_TXT>
<TXT>
<S>
<FATHERNAME>George Washington</FATHERNAME>
<ESTATENAME>Mount Vernon</>
<ESTATEPLACE>VA</ESTATEPLACE>
</S>
<S>
<OWNER>Washington family</OWNER>
<YEAROWNED>1674</YEAROWNED>
</S>
<S>
<BUILTIN>1734</BUILTIN>
<BUILTBY>Washington's father</BUILTBY>
</S>
</TXT>
</DOC>MergeRecord Configs
Record Reader: XMLReader
Record Writer: JsonRecordSetWriter
Merge Strategy: Bin-Packing Algorithm
Correlation Attribute Name: FatherID
Attribute Strategy: Keep All Unique Attributes
Minimum Number of Records: 2
Maximum Number of Records: 2
Minimum Bin Size: 0 B
Maximum Bin Size: No value set
Max Bin Age: No value set
Maximum Number of Bins: 10模式
{
"namespace": "ff",
"name": "founders",
"type": "record",
"fields": [
{"name":"FatherID", "type": ["string", "null"], "default": null},
{"name":"FatherName", "type": ["string", "null"], "default": null},
{"name":"ResidentialInformation", "type": ["null", {
"name": "ResidentialInformation", "type": "array", "items": {
"name": "ResidentialInformation", "type": "record", "fields": [
{"name": "Name", "type": ["string","null"], "default":null},
{"name": "StreetAddress", "type": ["string","null"], "default":null},
{"name": "City", "type": ["string","null"], "default":null},
{"name": "State", "type": ["string","null"], "default":null},
{"name": "ZipCode", "type": ["string","null"], "default":null}
]
}
}]},
{"name":"BirthDate", "type": ["string", "null"], "default": null},
{"name": "DOCID", "type": ["string", "null"], "default": null},
{"name": "FINAME", "type": ["string", "null"], "default": null},
{"name": "CUSTNAME", "type": {"type": "array", "items": "string"}},
{"name": "RAW_TXT", "type": {"type": "array", "items": "string"}},
{"name": "TXT", "type": {
"name": "TXT", "type": "record", "namespace": "txt.sar", "fields": [
{"name": "S", "type": {
"type": "array", "items": {
"name": "RecordInArray", "type": "record", "fields": [
{"name": "FATHERNAME", "type": {"type": "array", "items": ["string","null"]}},
{"name": "ESTATENAME", "type": {"type": "array", "items": ["string","null"]}},
{"name": "ESTATEPLACE", "type": {"type": "array", "items": ["string","null"]}},
{"name": "OWNER", "type": {"type": "array", "items": ["string","null"]}},
{"name": "YEAROWNED", "type": {"type": "array", "items": ["string","null"]}},
{"name": "BUILTIN", "type": {"type": "array", "items": ["string","null"]}},
{"name": "BUILTBY", "type": {"type": "array", "items": ["string","null"]}}
]
}
}}
]
}}
]}抖动规范(移位操作)
{
"*": {
"*": "&"
}
}实际输出
[ {
"FatherID" : ["1234", null],
"FatherName" : ["George Washington", null],
"ResidentialInformation" : [ {
"Name" : "Mount Vernon",
"StreetAddress" : "3200 Mount Vernon Hwy",
"City" : "Mt Vernon",
"State" : "VA",
"ZipCode" : "22121"
} ],
"BirthDate" : ["1732-02-22", null],
"DOCID" : "1234",
"FATHERNAME" : "George Washington",
"RAW_TXT" : [ "\nGeorge Washington lived in Mount Vernon in Mt Vernon, VA. The Washington family had owned land in the area since 1674. The original house was built in 1734 by Washington's father.\n" ],
"TXT" : {
"S" : [ {
"FATHERNAME" : [ "George Washington" ],
"ESTATENAME" : [ "Mount Vernon" ],
"ESTATEPLACE" : [ "VA" ]
}, {
"OWNER" : [ "Washington family" ],
"YEAROWNED" : [ "1674" ]
}, {
"BUILTIN" : [ "1734" ],
"BUILTBY" : [ "Washington's father" ]
} ]
}
} ]预期输出
[ {
"FatherID" : "1234",
"FatherName" : "George Washington",
"ResidentialInformation" : [ {
"Name" : "Mount Vernon",
"StreetAddress" : "3200 Mount Vernon Hwy",
"City" : "Mt Vernon",
"State" : "VA",
"ZipCode" : "22121"
} ],
"BirthDate" : "1732-02-22",
"DOCID" : "1234",
"FATHERNAME" : "George Washington",
"RAW_TXT" : [ "\nGeorge Washington lived in Mount Vernon in Mt Vernon, VA. The Washington family had owned land in the area since 1674. The original house was built in 1734 by Washington's father.\n" ],
"TXT" : {
"S" : [ {
"FATHERNAME" : [ "George Washington" ],
"ESTATENAME" : [ "Mount Vernon" ],
"ESTATEPLACE" : [ "VA" ]
}, {
"OWNER" : [ "Washington family" ],
"YEAROWNED" : [ "1674" ]
}, {
"BUILTIN" : [ "1734" ],
"BUILTBY" : [ "Washington's father" ]
} ]
}
} ]发布于 2019-04-23 15:12:36
MergeContent和MergeRecord通常用于合并两个或多个模式相同的流文件,例如将单个JSON对象捆绑到更大的数组中。
您可以使用LookupRecord使用XMLFileLookupService,这将获取第二个XML文件的内容,并将其插入到您选择的位置的第一个流文件的记录中。我不确定的部分是如何查找DOCID (与FatherID匹配),然后返回顶级DOC元素中的每个字段。
如果这不起作用,您可以尝试ExecuteScript或InvokeScriptedProcessor (或ScriptedLookupService)手动进行“合并”。
编辑(附加信息):如果抖动规范总是将非空值放在第一位(或者数组中的所有元素都是空的或相同的),那么您可以向链中添加一个规范,用数组中的第一个元素替换字段值。
https://stackoverflow.com/questions/55812622
复制相似问题