Skip to main content

rename_field

The rename_field processor renames fields on a DataEntity or DataWindow according to an explicit { oldField: newField } mapping. Each value is moved to its new field name and the original field is removed.

Usage

Rename fields on a document

Example of a job using the rename_field processor

{
"name" : "testing",
"workers" : 1,
"slicers" : 1,
"lifecycle" : "once",
"assets" : [
"standard"
],
"operations" : [
{
"_op": "test-reader"
},
{
"_op": "rename_field",
"field_mapping": {
"STATION": "station",
"LATITUDE": "latitude",
"LONGITUDE": "longitude"
}
}
]
}

Here is a representation of what the processor will do with the configuration listed in the job above

const data = [
DataEntity.make({ STATION: 'ACW00011647', LATITUDE: 17.1333, LONGITUDE: -61.7833, wind_speed: 0 }),
DataEntity.make({ STATION: 'ACW00011648', LATITUDE: 40, LONGITUDE: 60, wind_speed: 1.5 }),
]

const results = await processor.run(data);

results = [
{ station: 'ACW00011647', latitude: 17.1333, longitude: -61.7833, wind_speed: 0 },
{ station: 'ACW00011648', latitude: 40, longitude: 60, wind_speed: 1.5 },
]

Fields listed in the mapping that are not present on a record are skipped, and a field mapped to its own name is left unchanged. Values are moved as-is, including falsy values such as 0, "", or false.

Parameters

ConfigurationDescriptionTypeNotes
_opName of operation, it must reflect the exact name of the fileStringrequired
field_mappingObject mapping an existing field name to the new field name it should be renamed to. The original field is removedObjectrequired, no default