Class RouteText

java.lang.Object
org.apache.nifi.components.AbstractConfigurableComponent
org.apache.nifi.processor.AbstractSessionFactoryProcessor
org.apache.nifi.processor.AbstractProcessor
org.apache.nifi.processors.standard.RouteText
All Implemented Interfaces:
org.apache.nifi.components.ConfigurableComponent, org.apache.nifi.processor.Processor

@SideEffectFree @SupportsBatching @InputRequirement(INPUT_REQUIRED) @Tags({"attributes","routing","text","regexp","regex","Regular Expression","Expression Language","csv","filter","logs","delimited","find","string","search","filter","detect"}) @CapabilityDescription("Routes textual data based on a set of user-defined rules. Each line in an incoming FlowFile is compared against the values specified by user-defined Properties. The mechanism by which the text is compared to these user-defined properties is defined by the \'Matching Strategy\'. The data is then routed according to these rules, routing each line of the text individually.") @DynamicProperty(name="Relationship Name", value="value to match against", description="Routes data that matches the value specified in the Dynamic Property Value to the Relationship specified in the Dynamic Property Key.", expressionLanguageScope=FLOWFILE_ATTRIBUTES) @DynamicRelationship(name="Name from Dynamic Property", description="FlowFiles that match the Dynamic Property\'s value") @WritesAttribute(attribute="RouteText.Route",description="The name of the relationship to which the FlowFile was routed.") @WritesAttribute(attribute="RouteText.Group",description="The value captured by all capturing groups in the \'Grouping Regular Expression\' property. If this property is not set or contains no capturing groups, this attribute will not be added.") @UseCase(description="Drop blank or empty lines from the FlowFile\'s content.",keywords={"filter","drop","empty","blank","remove","delete","strip out","lines","text"},configuration="\"Routing Strategy\" = \"Route to each matching Property Name\"\n\"Matching Strategy\" = \"Matches Regular Expression\"\n\"Empty Line\" = \"^$\"\n\nAuto-terminate the \"Empty Line\" relationship.\nConnect the \"unmatched\" relationship to the next processor in your flow.\n") @UseCase(description="Remove specific lines of text from a file, such as those containing a specific word or having a line length over some threshold.",keywords={"filter","drop","empty","blank","remove","delete","strip out","lines","text","expression language"},configuration="\"Routing Strategy\" = \"Route to each matching Property Name\"\n\"Matching Strategy\" = \"Satisfies Expression\"\n\nAn additional property should be added named \"Filter Out.\" The value should be a NiFi Expression Language Expression that can refer to two variables (in addition to FlowFile attributes): `line`, which is the line of text being evaluated; and `lineNo`, which is the line number in the file (starting with 1). The Expression should return `true` for any line that should be dropped.\n\nFor example, to remove any line that starts with a # symbol, we can set \"Filter Out\" to `${line:startsWith(\"#\")}`.\nWe could also remove the first 2 lines of text by setting \"Filter Out\" to `${lineNo:le(2)}`. Note that we use the `le` function because we want lines numbers less than or equal to `2`, since the line index is 1-based.\n\nAuto-terminate the \"Filter Out\" relationship.\nConnect the \"unmatched\" relationship to the next processor in your flow.\n") public class RouteText extends org.apache.nifi.processor.AbstractProcessor
  • Field Details

    • ROUTE_ATTRIBUTE_KEY

      public static final String ROUTE_ATTRIBUTE_KEY
      See Also:
    • GROUP_ATTRIBUTE_KEY

      public static final String GROUP_ATTRIBUTE_KEY
      See Also:
    • routeAllMatchValue

      private static final String routeAllMatchValue
      See Also:
    • routeAnyMatchValue

      private static final String routeAnyMatchValue
      See Also:
    • routePropertyNameValue

      private static final String routePropertyNameValue
      See Also:
    • startsWithValue

      private static final String startsWithValue
      See Also:
    • endsWithValue

      private static final String endsWithValue
      See Also:
    • containsValue

      private static final String containsValue
      See Also:
    • equalsValue

      private static final String equalsValue
      See Also:
    • matchesRegularExpressionValue

      private static final String matchesRegularExpressionValue
      See Also:
    • containsRegularExpressionValue

      private static final String containsRegularExpressionValue
      See Also:
    • satisfiesExpression

      private static final String satisfiesExpression
      See Also:
    • ROUTE_TO_MATCHING_PROPERTY_NAME

      public static final org.apache.nifi.components.AllowableValue ROUTE_TO_MATCHING_PROPERTY_NAME
    • ROUTE_TO_MATCHED_WHEN_ALL_PROPERTIES_MATCH

      public static final org.apache.nifi.components.AllowableValue ROUTE_TO_MATCHED_WHEN_ALL_PROPERTIES_MATCH
    • ROUTE_TO_MATCHED_WHEN_ANY_PROPERTY_MATCHES

      public static final org.apache.nifi.components.AllowableValue ROUTE_TO_MATCHED_WHEN_ANY_PROPERTY_MATCHES
    • STARTS_WITH

      public static final org.apache.nifi.components.AllowableValue STARTS_WITH
    • ENDS_WITH

      public static final org.apache.nifi.components.AllowableValue ENDS_WITH
    • CONTAINS

      public static final org.apache.nifi.components.AllowableValue CONTAINS
    • EQUALS

      public static final org.apache.nifi.components.AllowableValue EQUALS
    • MATCHES_REGULAR_EXPRESSION

      public static final org.apache.nifi.components.AllowableValue MATCHES_REGULAR_EXPRESSION
    • CONTAINS_REGULAR_EXPRESSION

      public static final org.apache.nifi.components.AllowableValue CONTAINS_REGULAR_EXPRESSION
    • SATISFIES_EXPRESSION

      public static final org.apache.nifi.components.AllowableValue SATISFIES_EXPRESSION
    • ROUTE_STRATEGY

      public static final org.apache.nifi.components.PropertyDescriptor ROUTE_STRATEGY
    • MATCH_STRATEGY

      public static final org.apache.nifi.components.PropertyDescriptor MATCH_STRATEGY
    • TRIM_WHITESPACE

      public static final org.apache.nifi.components.PropertyDescriptor TRIM_WHITESPACE
    • IGNORE_CASE

      static final org.apache.nifi.components.PropertyDescriptor IGNORE_CASE
    • GROUPING_REGEX

      static final org.apache.nifi.components.PropertyDescriptor GROUPING_REGEX
    • CHARACTER_SET

      public static final org.apache.nifi.components.PropertyDescriptor CHARACTER_SET
    • PROPERTY_DESCRIPTORS

      private static final List<org.apache.nifi.components.PropertyDescriptor> PROPERTY_DESCRIPTORS
    • REL_ORIGINAL

      public static final org.apache.nifi.processor.Relationship REL_ORIGINAL
    • REL_NO_MATCH

      public static final org.apache.nifi.processor.Relationship REL_NO_MATCH
    • REL_MATCH

      public static final org.apache.nifi.processor.Relationship REL_MATCH
    • EMPTY_GROUP

      private static final RouteText.Group EMPTY_GROUP
    • relationships

      private final AtomicReference<Set<org.apache.nifi.processor.Relationship>> relationships
    • configuredRouteStrategy

      private volatile String configuredRouteStrategy
    • dynamicPropertyNames

      private volatile Set<String> dynamicPropertyNames
    • propertyMap

      private volatile Map<org.apache.nifi.processor.Relationship,org.apache.nifi.components.PropertyValue> propertyMap
      Cache of dynamic properties set during onScheduled(ProcessContext) for quick access in onTrigger(ProcessContext, ProcessSession)
    • groupingRegex

      private volatile Pattern groupingRegex
    • PATTERNS_CACHE_MAXIMUM_ENTRIES

      static final int PATTERNS_CACHE_MAXIMUM_ENTRIES
      See Also:
    • patternsCache

      final ConcurrentMap<String,Pattern> patternsCache
      LRU cache for the compiled patterns. The size of the cache is determined by the value of PATTERNS_CACHE_MAXIMUM_ENTRIES.
  • Constructor Details

    • RouteText

      public RouteText()
  • Method Details

    • cachedCompiledPattern

      private Pattern cachedCompiledPattern(String regex, boolean ignoreCase)
    • getRelationships

      public Set<org.apache.nifi.processor.Relationship> getRelationships()
      Specified by:
      getRelationships in interface org.apache.nifi.processor.Processor
      Overrides:
      getRelationships in class org.apache.nifi.processor.AbstractSessionFactoryProcessor
    • getSupportedPropertyDescriptors

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

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

      public void onPropertyModified(org.apache.nifi.components.PropertyDescriptor descriptor, String oldValue, String newValue)
      Specified by:
      onPropertyModified in interface org.apache.nifi.components.ConfigurableComponent
      Overrides:
      onPropertyModified in class org.apache.nifi.components.AbstractConfigurableComponent
    • onScheduled

      @OnScheduled public void onScheduled(org.apache.nifi.processor.ProcessContext context)
      When this processor is scheduled, update the dynamic properties into the map for quick access during each onTrigger call
      Parameters:
      context - ProcessContext used to retrieve dynamic properties
    • customValidate

      protected Collection<org.apache.nifi.components.ValidationResult> customValidate(org.apache.nifi.components.ValidationContext validationContext)
      Overrides:
      customValidate in class org.apache.nifi.components.AbstractConfigurableComponent
    • onTrigger

      public void onTrigger(org.apache.nifi.processor.ProcessContext context, org.apache.nifi.processor.ProcessSession session)
      Specified by:
      onTrigger in class org.apache.nifi.processor.AbstractProcessor
    • getGroup

      private RouteText.Group getGroup(String line, Pattern groupPattern)
    • appendLine

      private void appendLine(org.apache.nifi.processor.ProcessSession session, Map<org.apache.nifi.processor.Relationship,Map<RouteText.Group,org.apache.nifi.flowfile.FlowFile>> flowFileMap, org.apache.nifi.processor.Relationship relationship, org.apache.nifi.flowfile.FlowFile original, String line, Charset charset, RouteText.Group group)
    • lineMatches

      protected static boolean lineMatches(String line, Object comparison, String matchingStrategy, boolean ignoreCase, org.apache.nifi.flowfile.FlowFile flowFile, Map<String,String> variables)