Field Flattener
The Field Flattener processor flattens list and map fields. The processor can flatten the entire record to produce a record with no nested fields. Or it can flatten specific list or map fields.
Use the Field Flattener processor when you have nested fields that you need to flatten. For example, the Drift Synchronization Solution for Hive cannot process records with nested fields, so you can use the Field Flattener processor to flatten records before passing them to the Hive Metadata processor.
When you configure a Field Flattener processor, you configure whether to flatten the entire record or specific fields in the record. When flattening specific fields, you configure whether to flatten the fields in place or into another field. You also configure the name separator to use for flattened field names and specify whether to output the flattened fields to a list-map or list root field.
Flatten the Entire Record
When the Field Flattener flattens the entire record, it flattens all nested structures in the record until the record is flat.
{
"store": {
"id": "10342",
"location": {
"street": "34 2nd St",
"city": "Wilma",
"state": "OH",
"zipcode": "33333"
},
"ip": "234.56.7890"
}
}
store.id | store.location.street | store.location.city | store.location.state | store.location.zipcode | store.ip |
---|---|---|---|---|---|
10342 | 34 2nd St | Wilma | OH | 33333 | 234.56.7890 |
Flatten Specific Fields
The Field Flattener processor can flatten specified fields, either list or map fields, that contain additional nested list or map fields. When flattening a list or map field, the processor flattens all nested structures in the field until the field is flat. The processor can flatten fields in place (at their current position in the record), or the processor can flatten fields into another list or map field in the record, such as into the root field.
For example, say you have the following record with nested map fields:
{
"contact": {
"name": "Jane Smith",
"id": "557",
"address": {
"home": {
"street": "101 3rd St",
"city": "Huntsville",
"state": "NC",
"zipcode": "27023"
},
"work": {
"street": "15 Main St",
"city": "Jonestown",
"state": "NC",
"zipcode": "27011"
}
}
}
}
address
map field in
place using a period as the name separator, the processor generates the following record:
{
"contact": {
"name": "Jane Smith",
"id": "557",
"address": {
"home.street": "101 3rd St",
"home.city": "Huntsville",
"home.state": "NC",
"home.zipcode": "27023",
"work.street": "15 Main St",
"work.city": "Jonestown",
"work.state": "NC",
"work.zipcode": "27011"
}
}
}
address
map field into the target field contact
using a
period as the name separator, the processor generates the following record:
{
"contact": {
"name": "Jane Smith",
"id": "557",
"address": {
"home": {
"street": "101 3rd St",
"city": "Huntsville",
"state": "NC",
"zipcode": "27023"
},
"work": {
"street": "15 Main St",
"city": "Jonestown",
"state": "NC",
"zipcode": "27011"
"home.street": "101 3rd St",
"home.city": "Huntsville",
"home.state": "NC",
"home.zipcode": "27023",
"work.street": "15 Main St",
"work.city": "Jonestown",
"work.state": "NC",
"work.zipcode": "27011"
}
}
address
field into the
contact
field and remove the flattened field, the processor generates the
following record:
{
"contact": {
"name": "Jane Smith",
"id": "557",
"home.street": "101 3rd St",
"home.city": "Huntsville",
"home.state": "NC",
"home.zipcode": "27023",
"work.street": "15 Main St",
"work.city": "Jonestown",
"work.state": "NC",
"work.zipcode": "27011"
}
}
Configuring a Field Flattener Processor
Configure a Field Flattener processor to flatten fields.