Class UpdateRecord
java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.AbstractRecordProcessor
org.apache.nifi.processors.standard.UpdateRecord
- All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent,org.apache.nifi.processor.Processor
@SideEffectFree
@SupportsBatching
@InputRequirement(INPUT_REQUIRED)
@Tags({"update","record","generic","schema","json","csv","avro","log","logs","freeform","text"})
@CapabilityDescription("Updates the contents of a FlowFile that contains Record-oriented data (i.e., data that can be read via a RecordReader and written by a RecordWriter). This Processor requires that at least one user-defined Property be added. The name of the Property should indicate a RecordPath that determines the field that should be updated. The value of the Property is either a replacement value (optionally making use of the Expression Language) or is itself a RecordPath that extracts a value from the Record. Whether the Property value is determined to be a RecordPath or a literal value depends on the configuration of the <Replacement Value Strategy> Property.")
@WritesAttribute(attribute="record.index",description="This attribute provides the current row index and is only available inside the literal value expression.") @WritesAttribute(attribute="record.error.message",description="This attribute provides on failure the error message encountered by the Reader or Writer.")
@DynamicProperty(name="A RecordPath.",
value="The value to use to replace fields in the record that match the RecordPath",
description="Allows users to specify values to use to replace fields in the record that match the RecordPath.",
expressionLanguageScope=FLOWFILE_ATTRIBUTES)
@SeeAlso(ConvertRecord.class)
@UseCase(description="Combine multiple fields into a single field.",keywords={"combine","concatenate","recordpath"},configuration="\"Replacement Value Strategy\" = \"Record Path Value\"\n\nA single additional property is added to the Processor. The name of the property is a RecordPath identifying the field to place the result in.\nThe value of the property uses the concat Record Path function to concatenate multiple values together, potentially using other string literal values.\nFor example, to combine the `title`, `firstName` and `lastName` fields into a single field named `fullName`, we add a property with the name `/fullName` and a value of `concat(/title, \' \', /firstName, \' \', /lastName)`\n") @UseCase(description="Change the value of a record field to an explicit value.",keywords={"change","update","replace","transform"},configuration=" \"Replacement Value Strategy\" = \"Literal Value\"\n\n A single additional property is added to the Processor. The name of the property is a RecordPath identifying the field to place the result in.\n The value of the property is the explicit value to set the field to. For example, we can set any field with a name of `txId`, regardless of its level in the data\'s hierarchy, to `1111-1111` by adding a property with a name of `//txId` and a value of `1111-1111`\n") @UseCase(description="Copy the value of one record field to another record field.",keywords={"change","update","copy","recordpath","hierarchy","transform"},configuration=" \"Replacement Value Strategy\" = \"Record Path Value\"\n\n A single additional property is added to the Processor. The name of the property is a RecordPath identifying the field to update.\n The value of the property is a RecordPath identifying the field to copy the value from.\n For example, we can copy the value of `/identifiers/all/imei` to the `identifier` field at the root level, by adding a property named `/identifier` with a value of `/identifiers/all/imei`.\n") @UseCase(description="Enrich data by injecting the value of an attribute into each Record.",keywords={"enrich","attribute","change","update","replace","insert","transform"},configuration="\"Replacement Value Strategy\" = \"Literal Value\"\n\nA single additional property is added to the Processor. The name of the property is a RecordPath identifying the field to place the result in.\nThe value of the property is an Expression Language expression that references the attribute of interest. We can, for example, insert a new field name `filename` into each record by adding a property named `/filename` with a value of `${filename}`\n") @UseCase(description="Change the format of a record field\'s value.",keywords={"change","update","replace","insert","transform","format","date/time","timezone","expression language"},notes="Use the RenameRecordField Processor in order to change a field\'s name.",configuration="\"Replacement Value Strategy\" = \"Literal Value\"\n\nA single additional property is added to the Processor. The name of the property is a RecordPath identifying the field to update.\nThe value is an Expression Language expression that references the `field.value` variable. For example, to change the date/time format of a field named `txDate` from `year-month-day` format to `month/day/year` format, we add a property named `/txDate` with a value of `${field.value:toDate(\'yyyy-MM-dd\'):format(\'MM/dd/yyyy\')}`. We could also change the timezone of a timestamp field (and insert the timezone for clarity) by using a value of `${field.value:toDate(\'yyyy-MM-dd HH:mm:ss\', \'UTC-0400\'):format(\'yyyy-MM-dd HH:mm:ss Z\', \'UTC\')}`.\n")
public class UpdateRecord
extends AbstractRecordProcessor
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static final Stringprivate static final String(package private) static final org.apache.nifi.components.AllowableValueprivate static final String(package private) static final org.apache.nifi.components.AllowableValueprivate RecordPathCache(package private) static final org.apache.nifi.components.PropertyDescriptorFields inherited from class org.apache.nifi.processors.standard.AbstractRecordProcessor
INCLUDE_ZERO_RECORD_FLOWFILES, RECORD_READER, RECORD_WRITER, REL_FAILURE, REL_SUCCESS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateRecordPaths(org.apache.nifi.processor.ProcessContext context) protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext) private ObjectgetReplacementObject(List<FieldValue> selectedFields) private List<FieldValue> getSelectedFields(RecordPath replacementRecordPath, FieldValue fieldValue, Record record) protected org.apache.nifi.components.PropertyDescriptorgetSupportedDynamicPropertyDescriptor(String propertyDescriptorName) protected List<org.apache.nifi.components.PropertyDescriptor> private booleanisReplacingRoot(List<FieldValue> destinationFields) voidprotected Recordprocess(Record record, org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.ProcessContext context, long count) private RecordprocessAbsolutePath(RecordPath replacementRecordPath, Stream<FieldValue> destinationFields, Record record) private RecordprocessRelativePath(RecordPath replacementRecordPath, Stream<FieldValue> destinationFields, Record record) private voidupdateFieldValue(FieldValue fieldValue, Object replacement) private RecordupdateRecord(List<FieldValue> destinationFields, List<FieldValue> selectedFields, Record record) Methods inherited from class org.apache.nifi.processors.standard.AbstractRecordProcessor
getRelationships, onTriggerMethods inherited from class org.apache.nifi.processor.AbstractProcessor
onTriggerMethods inherited from class org.apache.nifi.processor.AbstractSessionFactoryProcessor
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, init, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrueMethods inherited from class org.apache.nifi.components.AbstractConfigurableComponent
equals, getPropertyDescriptor, getPropertyDescriptors, hashCode, onPropertyModified, validateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.nifi.components.ConfigurableComponent
getPropertyDescriptor, getPropertyDescriptors, onPropertyModified, validateMethods inherited from interface org.apache.nifi.processor.Processor
isStateful, migrateRelationships
-
Field Details
-
FIELD_NAME
- See Also:
-
FIELD_VALUE
- See Also:
-
FIELD_TYPE
- See Also:
-
RECORD_INDEX
- See Also:
-
recordPathCache
-
recordPaths
-
LITERAL_VALUES
static final org.apache.nifi.components.AllowableValue LITERAL_VALUES -
RECORD_PATH_VALUES
static final org.apache.nifi.components.AllowableValue RECORD_PATH_VALUES -
REPLACEMENT_VALUE_STRATEGY
static final org.apache.nifi.components.PropertyDescriptor REPLACEMENT_VALUE_STRATEGY
-
-
Constructor Details
-
UpdateRecord
public UpdateRecord()
-
-
Method Details
-
getSupportedPropertyDescriptors
- Overrides:
getSupportedPropertyDescriptorsin classAbstractRecordProcessor
-
migrateProperties
- Specified by:
migratePropertiesin interfaceorg.apache.nifi.processor.Processor- Overrides:
migratePropertiesin classAbstractRecordProcessor
-
getSupportedDynamicPropertyDescriptor
protected org.apache.nifi.components.PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) - Overrides:
getSupportedDynamicPropertyDescriptorin classorg.apache.nifi.components.AbstractConfigurableComponent
-
customValidate
protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext) - Overrides:
customValidatein classorg.apache.nifi.components.AbstractConfigurableComponent
-
createRecordPaths
@OnScheduled public void createRecordPaths(org.apache.nifi.processor.ProcessContext context) -
process
protected Record process(Record record, org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.ProcessContext context, long count) - Specified by:
processin classAbstractRecordProcessor
-
processAbsolutePath
private Record processAbsolutePath(RecordPath replacementRecordPath, Stream<FieldValue> destinationFields, Record record) -
isReplacingRoot
-
processRelativePath
private Record processRelativePath(RecordPath replacementRecordPath, Stream<FieldValue> destinationFields, Record record) -
updateRecord
private Record updateRecord(List<FieldValue> destinationFields, List<FieldValue> selectedFields, Record record) -
updateFieldValue
-
getSelectedFields
private List<FieldValue> getSelectedFields(RecordPath replacementRecordPath, FieldValue fieldValue, Record record) -
getReplacementObject
-