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 Details

    • FIELD_NAME

      private static final String FIELD_NAME
      See Also:
    • FIELD_VALUE

      private static final String FIELD_VALUE
      See Also:
    • FIELD_TYPE

      private static final String FIELD_TYPE
      See Also:
    • RECORD_INDEX

      private static final String RECORD_INDEX
      See Also:
    • recordPathCache

      private volatile RecordPathCache recordPathCache
    • recordPaths

      private volatile List<String> 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

      protected List<org.apache.nifi.components.PropertyDescriptor> getSupportedPropertyDescriptors()
      Overrides:
      getSupportedPropertyDescriptors in class AbstractRecordProcessor
    • migrateProperties

      public void migrateProperties(PropertyConfiguration config)
      Specified by:
      migrateProperties in interface org.apache.nifi.processor.Processor
      Overrides:
      migrateProperties in class AbstractRecordProcessor
    • getSupportedDynamicPropertyDescriptor

      protected org.apache.nifi.components.PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName)
      Overrides:
      getSupportedDynamicPropertyDescriptor in class org.apache.nifi.components.AbstractConfigurableComponent
    • customValidate

      protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext)
      Overrides:
      customValidate in class org.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:
      process in class AbstractRecordProcessor
    • processAbsolutePath

      private Record processAbsolutePath(RecordPath replacementRecordPath, Stream<FieldValue> destinationFields, Record record)
    • isReplacingRoot

      private boolean isReplacingRoot(List<FieldValue> destinationFields)
    • processRelativePath

      private Record processRelativePath(RecordPath replacementRecordPath, Stream<FieldValue> destinationFields, Record record)
    • updateRecord

      private Record updateRecord(List<FieldValue> destinationFields, List<FieldValue> selectedFields, Record record)
    • updateFieldValue

      private void updateFieldValue(FieldValue fieldValue, Object replacement)
    • getSelectedFields

      private List<FieldValue> getSelectedFields(RecordPath replacementRecordPath, FieldValue fieldValue, Record record)
    • getReplacementObject

      private Object getReplacementObject(List<FieldValue> selectedFields)