You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by joetrite <gi...@git.apache.org> on 2017/02/23 16:00:20 UTC
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
GitHub user joetrite opened a pull request:
https://github.com/apache/nifi/pull/1536
NIFI-3497 ScanAttribute Tagging
Adding tagging to ScanAttribute.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/joetrite/nifi master
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/nifi/pull/1536.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1536
----
commit f52e1f2a064b31f87d4165af6075716fa7d55046
Author: Joe Trite <jo...@gmail.com>
Date: 2017-02-22T21:36:08Z
NIFI-3497 - Added metadata option
Added optional to post additional metadata as new attributed if a match is found in the dictionary.
commit 8eb54a50193897cf564eb7d222aae35481168af4
Author: Joe Trite <jo...@gmail.com>
Date: 2017-02-22T21:46:13Z
NIFI-3497 test cases for metadata updates
Adding test cases to support metadata option update.
commit a7a7b6ace80380416c342809ce95a4f4087bb066
Author: Joe Trite <jo...@gmail.com>
Date: 2017-02-22T21:48:10Z
NIFI-3497 - New dictionary files for test
Adding new dictionary files to support metadata dictionary option.
commit d71426037b142da8ca04dae38952c164d1614806
Author: Joe Trite <jo...@gmail.com>
Date: 2017-02-23T15:19:01Z
NIFI-3497 - excluding test files
Adding new test data files to exclude list.
----
---
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.
---
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
Posted by alopresto <gi...@git.apache.org>.
Github user alopresto commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1536#discussion_r104275792
--- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java ---
@@ -97,13 +107,23 @@
.addValidator(StandardValidators.createRegexValidator(0, 1, false))
.defaultValue(null)
.build();
+ public static final PropertyDescriptor DICTIONARY_ENTRY_METADATA_DEMARCATOR = new PropertyDescriptor.Builder()
+ .name("Dictionary Entry Metadata Demarcator")
+ .description("A single character used to demarcate the dictionary entry string between dictionary value and metadata.")
+ .required(false)
+ .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
--- End diff --
If this is a single character, this validator should be a `StringLengthValidator` with a minimum and maximum of 1 character. See [here for an example](https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java#L129-L135).
---
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.
---
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
Posted by alopresto <gi...@git.apache.org>.
Github user alopresto commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1536#discussion_r104275670
--- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java ---
@@ -97,13 +107,23 @@
.addValidator(StandardValidators.createRegexValidator(0, 1, false))
.defaultValue(null)
.build();
+ public static final PropertyDescriptor DICTIONARY_ENTRY_METADATA_DEMARCATOR = new PropertyDescriptor.Builder()
+ .name("Dictionary Entry Metadata Demarcator")
--- End diff --
Yes please. That recommendation was put in place after a lot of the code already existed, so what we are trying to enforce is that any new properties follow that model and people will go back and update existing properties as necessary. There have been many discussions about it, but one serious issue is that if a property name is changed (to make it more readable, rename it, fix a typo, etc.) the value stored in the `flow.xml.gz` file will not be picked up when the flow is read by NiFi and that data can be lost. So the combination of static `name` and malleable `displayName` solves this issue.
---
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.
---
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
Posted by joetrite <gi...@git.apache.org>.
Github user joetrite closed the pull request at:
https://github.com/apache/nifi/pull/1536
---
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.
---
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
Posted by alopresto <gi...@git.apache.org>.
Github user alopresto commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1536#discussion_r104273923
--- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java ---
@@ -97,13 +107,23 @@
.addValidator(StandardValidators.createRegexValidator(0, 1, false))
.defaultValue(null)
.build();
+ public static final PropertyDescriptor DICTIONARY_ENTRY_METADATA_DEMARCATOR = new PropertyDescriptor.Builder()
+ .name("Dictionary Entry Metadata Demarcator")
--- End diff --
The preferred code style is to use a "machine-readable" (aka no spaces) value for `name` and provide a human-formatted value for `displayName`.
---
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.
---
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
Posted by joetrite <gi...@git.apache.org>.
Github user joetrite commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1536#discussion_r104274990
--- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java ---
@@ -97,13 +107,23 @@
.addValidator(StandardValidators.createRegexValidator(0, 1, false))
.defaultValue(null)
.build();
+ public static final PropertyDescriptor DICTIONARY_ENTRY_METADATA_DEMARCATOR = new PropertyDescriptor.Builder()
+ .name("Dictionary Entry Metadata Demarcator")
--- End diff --
ok, cool. i copied and pasted the existing properties which have not implemented displayName yet. Do you want me to change it for the new properties that I added and leave the existing properties alone?
---
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.
---
[GitHub] nifi pull request #1536: NIFI-3497 ScanAttribute Tagging
Posted by alopresto <gi...@git.apache.org>.
Github user alopresto commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1536#discussion_r104277602
--- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanAttribute.java ---
@@ -206,36 +243,60 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
final boolean matchAll = context.getProperty(MATCHING_CRITERIA).getValue().equals(MATCH_CRITERIA_ALL);
- for (final FlowFile flowFile : flowFiles) {
- final boolean matched = matchAll ? allMatch(flowFile, attributePattern, dictionaryTerms) : anyMatch(flowFile, attributePattern, dictionaryTerms);
- final Relationship relationship = matched ? REL_MATCHED : REL_UNMATCHED;
+ for (FlowFile flowFile : flowFiles) {
+ final Map<String,String> matched = (matchAll ? matchAll(flowFile, attributePattern, dictionaryTerms) : matchAny(flowFile, attributePattern, dictionaryTerms));
+ flowFile = session.putAllAttributes(flowFile, matched);
+
+ final Relationship relationship = (((matched.size() == (attributeNameMatches.size() * 3) && matchAll) || (matched.size() > 0 && !matchAll))) ? REL_MATCHED : REL_UNMATCHED;
session.getProvenanceReporter().route(flowFile, relationship);
session.transfer(flowFile, relationship);
logger.info("Transferred {} to {}", new Object[]{flowFile, relationship});
}
}
- private boolean allMatch(final FlowFile flowFile, final Pattern attributePattern, final Set<String> dictionary) {
- for (final Map.Entry<String, String> entry : flowFile.getAttributes().entrySet()) {
- if (attributePattern == null || attributePattern.matcher(entry.getKey()).matches()) {
- if (!dictionary.contains(entry.getValue())) {
- return false;
+ private Map<String,String> matchAny(final FlowFile flowFile, final Pattern attributePattern, final Map<String,String> dictionary) {
+ Map<String,String> dictionaryTermMatches = new HashMap<String,String>();
+ attributeNameMatches = new HashSet<String>();
+
+ int hitCounter = 0;
+
+ for (final Map.Entry<String, String> attribute : flowFile.getAttributes().entrySet()) {
+ if (attributePattern == null || attributePattern.matcher(attribute.getKey()).matches()) {
+ attributeNameMatches.add(attribute.getKey());
+
+ if (dictionary.containsKey(attribute.getValue())) {
+ hitCounter++;
+ dictionaryTermMatches.put("dictionary.hit." + hitCounter + ".attribute", attribute.getKey());
+ dictionaryTermMatches.put("dictionary.hit." + hitCounter + ".term", attribute.getValue());
+ dictionaryTermMatches.put("dictionary.hit." + hitCounter + ".metadata", dictionary.get(attribute.getValue()));
--- End diff --
It looks like these statements could be refactored to a method as they are reused in the `matchAll` scenario.
---
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.
---
[GitHub] nifi issue #1536: NIFI-3497 ScanAttribute Tagging
Posted by joetrite <gi...@git.apache.org>.
Github user joetrite commented on the issue:
https://github.com/apache/nifi/pull/1536
created new pull request #1564 with single commit. closing this. thanks @joewitt @alopresto for all the help and advise.
---
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.
---
[GitHub] nifi issue #1536: NIFI-3497 ScanAttribute Tagging
Posted by joewitt <gi...@git.apache.org>.
Github user joewitt commented on the issue:
https://github.com/apache/nifi/pull/1536
@joetrite it would be good to get a clean master, create a branch, put your changes on it, then submit that PR. This one has a couple merge commits now and they're probably not needed (rebase would likely have done the trick). Can you clean up the commit history for this PR? Definitely appreciate the work you're putting in and don't want to put you through hoops but would like to keep the commit clean.
---
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.
---