nifi-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pvillard31 <...@git.apache.org>
Subject [GitHub] nifi pull request #858: NIFI-1971 - Introduce QueryWhois processor
Date Mon, 12 Sep 2016 19:02:55 GMT
Github user pvillard31 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/858#discussion_r78433995
  
    --- 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"))) {
    +                        results.put(matcher.group(lookupKey), "enrich." + schema + recordPosition
+ ".group" + String.valueOf(r), matcher.group(r));
    +                    } else {
    +                        getLogger().warn("Could not find group {} while processing result.
Ignoring row", new Object[] {lookupKey});
    --- End diff --
    
    I would add ``rawResult`` in the log to help users to debug the processor configuration.
Thoughts?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message