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:
JohannesDaniel 2018-05-14 16:28:46 +02:00 committed by Mike Thomsen
parent 03adaeca22
commit 04745a556a
4 changed files with 23 additions and 1 deletions

View 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>

View File

@ -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);
}
/**

View File

@ -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);

View File

@ -0,0 +1,11 @@
{
"type": "record",
"name": "record_name",
"namespace": "namespace",
"fields": [
{
"name": "field1",
"type": "string"
}
]
}