Skip to main content

keep_field

The keep_field processor keeps only the specified field, or fields, on a DataEntity or DataWindow and removes all others. It is the inverse of drop_field.

Usage

Keep only the specified field on a document

Example of a job using the keep_field processor

{
"name" : "testing",
"workers" : 1,
"slicers" : 1,
"lifecycle" : "once",
"assets" : [
"standard"
],
"operations" : [
{
"_op": "test-reader"
},
{
"_op": "keep_field",
"field": "name"
}
]
}

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

const data = [
DataEntity.make({ name: 'lilly', otherField: 1 }),
DataEntity.make({ name: 'willy', otherField: 2 }),
DataEntity.make({ name: 'billy', otherField: 3 }),
DataEntity.make({ otherField: 4 }),
]

const results = await processor.run(data);

results = [
{ name: 'lilly' },
{ name: 'willy' },
{ name: 'billy' },
{ },
]

Parameters

ConfigurationDescriptionTypeNotes
_opName of operation, it must reflect the exact name of the fileStringrequired
fieldName of field, or array of field names, to keep; all other fields are removedString or String[]required, no default