joewitt commented on a change in pull request #3317: NIFI-6047 Add 
DetectDuplicateRecord Processor
URL: https://github.com/apache/nifi/pull/3317#discussion_r258009986
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/DetectDuplicateRecord.java
 ##########
 @@ -0,0 +1,620 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.processors.standard;
+
+import com.google.common.base.Joiner;
+import com.google.common.hash.BloomFilter;
+import com.google.common.hash.Funnels;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.codec.digest.MessageDigestAlgorithms;
+import org.apache.nifi.annotation.behavior.*;
+import org.apache.nifi.annotation.behavior.InputRequirement.Requirement;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.SeeAlso;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.*;
+import org.apache.nifi.distributed.cache.client.Deserializer;
+import org.apache.nifi.distributed.cache.client.DistributedMapCacheClient;
+import org.apache.nifi.distributed.cache.client.Serializer;
+import 
org.apache.nifi.distributed.cache.client.exception.DeserializationException;
+import 
org.apache.nifi.distributed.cache.client.exception.SerializationException;
+import org.apache.nifi.expression.AttributeExpression.ResultType;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.flowfile.attributes.CoreAttributes;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.processor.*;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.record.path.RecordPath;
+import org.apache.nifi.record.path.RecordPathResult;
+import org.apache.nifi.record.path.util.RecordPathCache;
+import org.apache.nifi.record.path.validation.RecordPathPropertyNameValidator;
+import org.apache.nifi.record.path.validation.RecordPathValidator;
+import org.apache.nifi.schema.access.SchemaNotFoundException;
+import org.apache.nifi.serialization.*;
+import org.apache.nifi.serialization.record.Record;
+import org.apache.nifi.serialization.record.RecordSchema;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.toList;
+import static org.apache.commons.codec.binary.StringUtils.getBytesUtf8;
+import static org.apache.commons.lang3.StringUtils.*;
+
+@EventDriven
+@SupportsBatching
+@InputRequirement(Requirement.INPUT_REQUIRED)
+@SystemResourceConsideration(resource = SystemResource.MEMORY,
+        description = "Caches records from each incoming FlowFile and 
determines if the cached record has " +
+                "already been seen. The name of user-defined properties 
determines the RecordPath values used to " +
+                "determine if a record is unique. If no user-defined 
properties are present, the entire record is " +
+                "used as the input to determine uniqueness. All duplicate 
records are routed to 'duplicate'. " +
+                "If the record is not determined to be a duplicate, the 
Processor routes the record to 'non-duplicate'.")
+@Tags({"text", "record", "update", "change", "replace", "modify", "distinct", 
"unique",
+        "filter", "hash", "dupe", "duplicate", "dedupe"})
+@CapabilityDescription("Caches records from each incoming FlowFile and 
determines if the cached record has " +
+        "already been seen. The name of user-defined properties determines the 
RecordPath values used to " +
+        "determine if a record is unique. If no user-defined properties are 
present, the entire record is " +
+        "used as the input to determine uniqueness. All duplicate records are 
routed to 'duplicate'. " +
+        "If the record is not determined to be a duplicate, the Processor 
routes the record to 'non-duplicate'."
+)
+@ReadsAttributes({@ReadsAttribute(attribute="", description="")})
+@WritesAttributes({
+        @WritesAttribute(attribute = "record.count", description = "The number 
of records in the FlowFile")
+})
+@DynamicProperty(
+        name = "RecordPath",
+        value = "User-defined property values are ignored",
+        description = "The name of each user-defined property must be a valid 
RecordPath.")
+@SeeAlso(classNames = {
+        
"org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService",
+        
"org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer",
+        "org.apache.nifi.processors.standard.DetectDuplicate"
+})
+public class DetectDuplicateRecord extends AbstractProcessor {
+
+    private volatile RecordPathCache recordPathCache;
+    private volatile List<String> recordPaths;
+
+    // VALUES
+
+    static final AllowableValue MD5_ALGORITHM_VALUE = new 
AllowableValue(MessageDigestAlgorithms.MD5, "MD5",
+            "The MD5 message-digest algorithm.");
+    static final AllowableValue SHA1_ALGORITHM_VALUE = new 
AllowableValue(MessageDigestAlgorithms.SHA_1, "SHA-1",
+            "The SHA-1 cryptographic hash algorithm.");
+    static final AllowableValue SHA256_ALGORITHM_VALUE = new 
AllowableValue(MessageDigestAlgorithms.SHA3_256, "SHA-256",
+            "The SHA-256 cryptographic hash algorithm.");
+    static final AllowableValue SHA512_ALGORITHM_VALUE = new 
AllowableValue(MessageDigestAlgorithms.SHA3_512, "SHA-512",
+            "The SHA-512 cryptographic hash algorithm.");
+
+//    static final AllowableValue ENTIRE_RECORD_VALUE = new 
AllowableValue("entire-record", "Entire Record",
 
 Review comment:
   These should be removed unless they're to be used

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to