Github user trixpan commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/858#discussion_r78475823
  
    --- Diff: 
nifi-nar-bundles/nifi-enrich-bundle/nifi-enrich-processors/src/main/java/org/apache/nifi/processors/enrich/AbstractEnrichProcessor.java
 ---
    @@ -152,10 +166,68 @@
                     // Fails to NONE
                 default:
                     // NONE was chosen, just appending the record result as 
group0 without further splitting
    -                results.put("enrich." + schema + ".record" + 
String.valueOf(recordPosition) + ".group0", rawResult);
    +                results.put("enrich." + schema + ".record" + 
recordPosition + ".group0", rawResult);
                     break;
             }
             return results;
         }
     
    +    /**
    +     * This method returns the parsed record string in the form of
    +     * a map of two strings, consisting of a iteration aware attribute
    +     * names and its values
    +     *
    +
    +     * @param  rawResult the raw query results to be parsed
    +     * @param queryParser The parsing mechanism being used to parse the 
data into groups
    +     * @param queryRegex The regex to be used to split the query results 
into groups. The regex MUST implement at least on named capture group "KEY" to 
be used to populate the table rows
    +     * @param lookupKey The regular expression named capture group or 
number of the column of a split to be used for matching
    +     * @return  Table with attribute names and values where each Table row 
uses the value of the KEY named capture group specified in @param queryRegex
    +     */
    +    protected Table<String, String, String> parseBatchResponse(String 
rawResult, String queryParser, String queryRegex, String lookupKey, String 
schema) {
    +        // Note the hardcoded record0.
    +        //  Since iteration is done within the parser and Multimap is 
used, the record number here will always be 0.
    +        // Consequentially, 0 is hardcoded so that batched and non batched 
attributes follow the same naming
    +        // conventions
    +        final String recordPosition = ".record0";
    +
    +        final Table<String, String, String> results = 
HashBasedTable.create();
    +
    +        switch (queryParser) {
    +            case "Split":
    +                Scanner scanner = new Scanner(rawResult);
    +                while (scanner.hasNextLine()) {
    +                    String line = scanner.nextLine();
    +                    // Time to Split the results...
    +                    String[] splitResult = line.split(queryRegex);
    +
    +                    for (int r = 0; r < splitResult.length; r++) {
    +                        results.put(splitResult[ 
Integer.valueOf(lookupKey) - 1 ], "enrich." + schema + recordPosition + 
".group" + String.valueOf(r), splitResult[r]);
    +
    +                    }
    +                }
    +                break;
    +            case "RegEx":
    +            // prepare the regex
    +            Pattern p;
    +            // Regex is multiline. Each line should include a KEY for 
lookup
    +            p = Pattern.compile(queryRegex, Pattern.MULTILINE);
    +
    +            Matcher matcher = p.matcher(rawResult);
    +            while (matcher.find()) {
    +                // Note that RegEx matches capture group 0 is usually 
broad but starting with it anyway
    +                // for the sake of purity
    +                for (int r = 0; r <= matcher.groupCount(); r++) {
    +                    if (!StringUtils.isEmpty(matcher.group("KEY"))) {
    --- End diff --
    
    Pierre, 
    
    This KEY reference should have been removed so I guess I stuffed up 
something on my git... I rewrote the code to unify on regex capture group 
numbers.
    
    I also add code to catch IndexOutOfBoundsException (the equivalent to the 
IllegalArgumentException you mentioned above)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to