mirror of https://github.com/apache/nifi.git
NIFI-2998: Add validator to Avro Record Name in InferAvroSchema
This closes #1187
This commit is contained in:
parent
78020825e9
commit
63bda32a8b
|
@ -57,6 +57,7 @@ import java.util.Set;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Tags({"kite", "avro", "infer", "schema", "csv", "json"})
|
@Tags({"kite", "avro", "infer", "schema", "csv", "json"})
|
||||||
@InputRequirement(InputRequirement.Requirement.INPUT_REQUIRED)
|
@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 CSV_MIME_TYPE = "text/csv";
|
||||||
public static final String AVRO_MIME_TYPE = "application/avro-binary";
|
public static final String AVRO_MIME_TYPE = "application/avro-binary";
|
||||||
public static final String AVRO_FILE_EXTENSION = ".avro";
|
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()
|
public static final PropertyDescriptor SCHEMA_DESTINATION = new PropertyDescriptor.Builder()
|
||||||
.name("Schema Output Destination")
|
.name("Schema Output Destination")
|
||||||
|
@ -202,10 +204,11 @@ public class InferAvroSchema
|
||||||
|
|
||||||
public static final PropertyDescriptor RECORD_NAME = new PropertyDescriptor.Builder()
|
public static final PropertyDescriptor RECORD_NAME = new PropertyDescriptor.Builder()
|
||||||
.name("Avro Record Name")
|
.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)
|
.required(true)
|
||||||
.expressionLanguageSupported(true)
|
.expressionLanguageSupported(true)
|
||||||
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
|
.addValidator(StandardValidators.createRegexMatchingValidator(AVRO_RECORD_NAME_PATTERN))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
|
public static final PropertyDescriptor CHARSET = new PropertyDescriptor.Builder()
|
||||||
|
|
|
@ -63,6 +63,30 @@ public class TestInferAvroSchema {
|
||||||
runner.setProperty(InferAvroSchema.PRETTY_AVRO_OUTPUT, "true");
|
runner.setProperty(InferAvroSchema.PRETTY_AVRO_OUTPUT, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void inferAvroSchemaFromHeaderDefinitionOfCSVFile() throws Exception {
|
public void inferAvroSchemaFromHeaderDefinitionOfCSVFile() throws Exception {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue