You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by pvillard31 <gi...@git.apache.org> on 2016/09/12 19:01:58 UTC

[GitHub] nifi pull request #858: NIFI-1971 - Introduce QueryWhois processor

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

    https://github.com/apache/nifi/pull/858#discussion_r78433868
  
    --- 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 --
    
    With this configuration:
    <img width="761" alt="screen shot 2016-09-12 at 8 59 36 pm" src="https://cloud.githubusercontent.com/assets/11541012/18448541/dc06e528-792b-11e6-9c87-a3b7b81bd921.png">
    
    ````
    2016-09-12 20:55:35,606 WARN [Timer-Driven Process Thread-6] o.a.nifi.processors.enrich.QueryWhois QueryWhois[id=9108305e-0156-1000-ebb0-99ae7aeaff21] Processor Administratively Yielded for 1 sec due to processing failure
    2016-09-12 20:55:35,606 WARN [Timer-Driven Process Thread-6] o.a.n.c.t.ContinuallyRunProcessorTask Administratively Yielding QueryWhois[id=9108305e-0156-1000-ebb0-99ae7aeaff21] due to uncaught Exception: java.lang.IllegalArgumentException: No group with name <KEY>
    2016-09-12 20:55:35,607 WARN [Timer-Driven Process Thread-6] o.a.n.c.t.ContinuallyRunProcessorTask 
    java.lang.IllegalArgumentException: No group with name <KEY>
    	at java.util.regex.Matcher.getMatchedGroupIndex(Matcher.java:1316) ~[na:1.8.0_77]
    	at java.util.regex.Matcher.group(Matcher.java:572) ~[na:1.8.0_77]
    	at org.apache.nifi.processors.enrich.AbstractEnrichProcessor.parseBatchResponse(AbstractEnrichProcessor.java:221) ~[na:na]
    	at org.apache.nifi.processors.enrich.QueryWhois.onTrigger(QueryWhois.java:276) ~[na:na]
    	at org.apache.nifi.processor.AbstractProcessor.onTrigger(AbstractProcessor.java:27) ~[nifi-api-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    	at org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1060) ~[nifi-framework-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    	at org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:136) [nifi-framework-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    	at org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:47) [nifi-framework-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    	at org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:127) [nifi-framework-core-1.0.0-SNAPSHOT.jar:1.0.0-SNAPSHOT]
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_77]
    	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_77]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_77]
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_77]
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_77]
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_77]
    	at java.lang.Thread.run(Thread.java:745) [na:1.8.0_77]
    ````
    
    I believe this should be caught and logged.


---
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.
---