mirror of https://github.com/apache/nifi.git
NIFI-5189 Schema name is not available for RecordSchema
This closes #2700 Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
parent
03adaeca22
commit
04745a556a
1
nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/pom.xml
Normal file → Executable file
1
nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/pom.xml
Normal file → Executable file
|
@ -53,6 +53,7 @@
|
|||
<excludes combine.children="append">
|
||||
<exclude>src/test/resources/org/apache/nifi/avro/data.avro</exclude>
|
||||
<exclude>src/test/resources/org/apache/nifi/avro/schema.json</exclude>
|
||||
<exclude>src/test/resources/org/apache/nifi/avro/simpleSchema.json</exclude>
|
||||
<exclude>src/test/resources/org/apache/nifi/avro/defaultArrayValue1.json</exclude>
|
||||
<exclude>src/test/resources/org/apache/nifi/avro/defaultArrayValue2.json</exclude>
|
||||
<exclude>src/test/resources/org/apache/nifi/avro/defaultArrayInRecords1.json</exclude>
|
||||
|
|
|
@ -62,6 +62,7 @@ import org.apache.nifi.serialization.record.RecordField;
|
|||
import org.apache.nifi.serialization.record.RecordFieldType;
|
||||
import org.apache.nifi.serialization.record.RecordSchema;
|
||||
import org.apache.nifi.serialization.record.SchemaIdentifier;
|
||||
import org.apache.nifi.serialization.record.StandardSchemaIdentifier;
|
||||
import org.apache.nifi.serialization.record.type.ArrayDataType;
|
||||
import org.apache.nifi.serialization.record.type.ChoiceDataType;
|
||||
import org.apache.nifi.serialization.record.type.MapDataType;
|
||||
|
@ -367,7 +368,8 @@ public class AvroTypeUtil {
|
|||
throw new IllegalArgumentException("Avro Schema cannot be null");
|
||||
}
|
||||
|
||||
return createSchema(avroSchema, avroSchema.toString(), SchemaIdentifier.EMPTY);
|
||||
SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build();
|
||||
return createSchema(avroSchema, avroSchema.toString(), identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -396,6 +396,14 @@ public class TestAvroTypeUtil {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSchemaNameNotEmpty() throws IOException {
|
||||
Schema schema = new Schema.Parser().parse(getClass().getResourceAsStream("simpleSchema.json"));
|
||||
RecordSchema recordSchema = AvroTypeUtil.createSchema(schema);
|
||||
Assert.assertTrue(recordSchema.getIdentifier().getName().isPresent());
|
||||
Assert.assertEquals(Optional.of("record_name"), recordSchema.getIdentifier().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringToBytesConversion() {
|
||||
Object o = AvroTypeUtil.convertToAvroObject("Hello", Schema.create(Type.BYTES), StandardCharsets.UTF_16);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"type": "record",
|
||||
"name": "record_name",
|
||||
"namespace": "namespace",
|
||||
"fields": [
|
||||
{
|
||||
"name": "field1",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue