@EventDriven @SideEffectFree @SupportsBatching @Tags(value={"attributes","hash"}) @InputRequirement(value=INPUT_REQUIRED) @CapabilityDescription(value="Hashes together the key/value pairs of several FlowFile Attributes and adds the hash as a new attribute. Optional properties are to be added such that the name of the property is the name of a FlowFile Attribute to consider and the value of the property is a regular expression that, if matched by the attribute value, will cause that attribute to be used as part of the hash. If the regular expression contains a capturing group, only the value of the capturing group will be used.") @WritesAttribute(attribute="<Hash Value Attribute Key>", description="This Processor adds an attribute whose value is the result of Hashing the existing FlowFile attributes. The name of this attribute is specified by the <Hash Value Attribute Key> property.") @DynamicProperty(name="A flowfile attribute key for attribute inspection", value="A Regular Expression", description="This regular expression is evaluated against the flowfile attribute values. If the regular expression contains a capturing group, the value of that group will be used when comparing flow file attributes. Otherwise, the original flow file attribute\'s value will be used if and only if the value matches the given regular expression.") public class HashAttribute extends AbstractProcessor
This processor identifies groups of user-specified flowfile attributes and assigns a unique hash value to each group, recording this hash value in the flowfile's attributes using a user-specified attribute key. The groups are identified dynamically and preserved across application restarts.
The user must supply optional processor properties during runtime to correctly configure this processor. The optional property key will be used as the flowfile attribute key for attribute inspection. The value must be a valid regular expression. This regular expression is evaluated against the flowfile attribute values. If the regular expression contains a capturing group, the value of that group will be used when comparing flow file attributes. Otherwise, the original flow file attribute's value will be used if and only if the value matches the given regular expression.
If a flowfile does not have an attribute entry for one or more processor configured values, then the flowfile is routed to failure.
An example hash value identification: Assume Processor Configured with Two Properties ("MDKey1" = ".*" and "MDKey2" = "(.).*"). FlowFile 1 has the following attributes: MDKey1 = a MDKey2 = b and will be assigned to group 1 (since no groups exist yet) FlowFile 2 has the following attributes: MDKey1 = 1 MDKey2 = 2 and will be assigned to group 2 (attribute keys do not match existing groups) FlowFile 3 has the following attributes: MDKey1 = a MDKey2 = z and will be assigned to group 3 (attribute keys do not match existing groups) FlowFile 4 has the following attribute: MDKey1 = a MDKey2 = bad and will be assigned to group 1 (because the value of MDKey1 has the regular expression ".*" applied to it, and that evaluates to the same as MDKey1 attribute of the first flow file. Similarly, the capturing group for the MDKey2 property indicates that only the first character of the MDKey2 attribute must match, and the first character of MDKey2 for Flow File 1 and Flow File 4 are both 'b'.) FlowFile 5 has the following attributes: MDKey1 = a and will route to failure because it does not have MDKey2 entry in its attribute
The following flow file attributes are created or modified:
Modifier and Type | Field and Description |
---|---|
static PropertyDescriptor |
HASH_VALUE_ATTRIBUTE |
private List<PropertyDescriptor> |
properties |
private AtomicReference<Map<String,Pattern>> |
regexMapRef |
static Relationship |
REL_FAILURE |
static Relationship |
REL_SUCCESS |
private Set<Relationship> |
relationships |
Constructor and Description |
---|
HashAttribute() |
Modifier and Type | Method and Description |
---|---|
Set<Relationship> |
getRelationships() |
private SortedMap<String,String> |
getRelevantAttributes(FlowFile flowFile,
Map<String,Pattern> patterns) |
protected PropertyDescriptor |
getSupportedDynamicPropertyDescriptor(String propertyDescriptorName) |
protected List<PropertyDescriptor> |
getSupportedPropertyDescriptors() |
protected void |
init(ProcessorInitializationContext context) |
void |
onPropertyModified(PropertyDescriptor descriptor,
String oldValue,
String newValue) |
void |
onTrigger(ProcessContext context,
ProcessSession session) |
onTrigger
getControllerServiceLookup, getIdentifier, getLogger, getNodeTypeProvider, initialize, isConfigurationRestored, isScheduled, toString, updateConfiguredRestoredTrue, updateScheduledFalse, updateScheduledTrue
customValidate, equals, getPropertyDescriptor, getPropertyDescriptors, hashCode, validate
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getPropertyDescriptor, getPropertyDescriptors, validate
public static final PropertyDescriptor HASH_VALUE_ATTRIBUTE
public static final Relationship REL_SUCCESS
public static final Relationship REL_FAILURE
private Set<Relationship> relationships
private List<PropertyDescriptor> properties
private final AtomicReference<Map<String,Pattern>> regexMapRef
protected void init(ProcessorInitializationContext context)
init
in class AbstractSessionFactoryProcessor
public Set<Relationship> getRelationships()
getRelationships
in interface Processor
getRelationships
in class AbstractSessionFactoryProcessor
protected List<PropertyDescriptor> getSupportedPropertyDescriptors()
getSupportedPropertyDescriptors
in class AbstractConfigurableComponent
protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(String propertyDescriptorName)
getSupportedDynamicPropertyDescriptor
in class AbstractConfigurableComponent
public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue)
onPropertyModified
in interface ConfigurableComponent
onPropertyModified
in class AbstractConfigurableComponent
public void onTrigger(ProcessContext context, ProcessSession session)
onTrigger
in class AbstractProcessor
Copyright © 2017 Apache NiFi Project. All rights reserved.