Repository: nifi
Updated Branches:
  refs/heads/master 78020825e -> 63bda32a8


NIFI-2998: Add validator to Avro Record Name in InferAvroSchema

This closes #1187


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/63bda32a
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/63bda32a
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/63bda32a

Branch: refs/heads/master
Commit: 63bda32a8befe7f0da01a6c543462f6b2b2daced
Parents: 7802082
Author: Matt Burgess <mattyb...@apache.org>
Authored: Tue Nov 8 11:56:14 2016 -0500
Committer: Oleg Zhurakousky <o...@suitcase.io>
Committed: Tue Nov 8 14:14:40 2016 -0500

----------------------------------------------------------------------
 .../nifi/processors/kite/InferAvroSchema.java   |  7 ++++--
 .../processors/kite/TestInferAvroSchema.java    | 24 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/63bda32a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/InferAvroSchema.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/InferAvroSchema.java
 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/InferAvroSchema.java
index aad48ae..0edbd2b 100644
--- 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/InferAvroSchema.java
+++ 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/InferAvroSchema.java
@@ -57,6 +57,7 @@ import java.util.Set;
 import java.util.HashSet;
 import java.util.Collections;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Pattern;
 
 @Tags({"kite", "avro", "infer", "schema", "csv", "json"})
 @InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
@@ -111,6 +112,7 @@ public class InferAvroSchema
     public static final String CSV_MIME_TYPE = "text/csv";
     public static final String AVRO_MIME_TYPE = "application/avro-binary";
     public static final String AVRO_FILE_EXTENSION = ".avro";
+    public static final Pattern AVRO_RECORD_NAME_PATTERN = 
Pattern.compile("[A-Za-z_]+[A-Za-z0-9_.]*[^.]");
 
     public static final PropertyDescriptor SCHEMA_DESTINATION = new 
PropertyDescriptor.Builder()
             .name("Schema Output Destination")
@@ -202,10 +204,11 @@ public class InferAvroSchema
 
     public static final PropertyDescriptor RECORD_NAME = new 
PropertyDescriptor.Builder()
             .name("Avro Record Name")
-            .description("Value to be placed in the Avro record schema 
\"name\" field.")
+            .description("Value to be placed in the Avro record schema 
\"name\" field. The value must adhere to the Avro naming "
+                    + "rules for fullname. If Expression Language is present 
then the evaluated value must adhere to the Avro naming rules.")
             .required(true)
             .expressionLanguageSupported(true)
-            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            
.addValidator(StandardValidators.createRegexMatchingValidator(AVRO_RECORD_NAME_PATTERN))
             .build();
 
     public static final PropertyDescriptor CHARSET = new 
PropertyDescriptor.Builder()

http://git-wip-us.apache.org/repos/asf/nifi/blob/63bda32a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
index 171a64a..e1a9ef9 100644
--- 
a/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
+++ 
b/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/test/java/org/apache/nifi/processors/kite/TestInferAvroSchema.java
@@ -64,6 +64,30 @@ public class TestInferAvroSchema {
     }
 
     @Test
+    public void testRecordName() throws Exception {
+
+        // Dot at the end is invalid
+        runner.setProperty(InferAvroSchema.RECORD_NAME, 
"org.apache.nifi.contact.");
+        runner.assertNotValid();
+        // Dashes are invalid
+        runner.setProperty(InferAvroSchema.RECORD_NAME, "avro-schema");
+        runner.assertNotValid();
+        // Name cannot start with a digit
+        runner.setProperty(InferAvroSchema.RECORD_NAME, "1Record");
+        runner.assertNotValid();
+        // Name cannot start with a dot
+        runner.setProperty(InferAvroSchema.RECORD_NAME, ".record");
+        runner.assertNotValid();
+
+        runner.setProperty(InferAvroSchema.RECORD_NAME, "avro_schema");
+        runner.assertValid();
+        runner.setProperty(InferAvroSchema.RECORD_NAME, 
"org.apache.nifi.contact");
+        runner.assertValid();
+        runner.setProperty(InferAvroSchema.RECORD_NAME, "${filename}"); // EL 
is valid, although its value may not be when evaluated
+        runner.assertValid();
+    }
+
+    @Test
     public void inferAvroSchemaFromHeaderDefinitionOfCSVFile() throws 
Exception {
 
         runner.assertValid();

Reply via email to