@Test public void testSimpleRecursiveSchema() { Schema recursiveSchema = new Schema.Parser().parse("{\n" + " \"namespace\": \"org.apache.nifi.testing\",\n" + " \"name\": \"NodeRecord\",\n" + " \"type\": \"record\",\n" + " \"fields\": [\n" + " {\n" + " \"name\": \"id\",\n" + " \"type\": \"int\"\n" + " },\n" + " {\n" + " \"name\": \"value\",\n" + " \"type\": \"string\"\n" + " },\n" + " {\n" + " \"name\": \"parent\",\n" + " \"type\": [\n" + " \"null\",\n" + " \"NodeRecord\"\n" + " ]\n" + " }\n" + " ]\n" + "}\n"); RecordSchema result = AvroTypeUtil.createSchema(recursiveSchema); Assert.assertEquals(3, result.getFieldCount()); Optional<RecordField> idField = result.getField("id"); Assert.assertTrue(idField.isPresent()); Assert.assertEquals(RecordFieldType.INT, idField.get().getDataType().getFieldType()); Optional<RecordField> valueField = result.getField("value"); Assert.assertTrue(valueField.isPresent()); Assert.assertEquals(RecordFieldType.STRING, valueField.get().getDataType().getFieldType()); Optional<RecordField> parentField = result.getField("parent"); Assert.assertTrue(parentField.isPresent()); Assert.assertEquals(RecordFieldType.RECORD, parentField.get().getDataType().getFieldType()); Assert.assertEquals(result, ((RecordDataType) parentField.get().getDataType()).getChildSchema()); }
public static RecordSchema createSchema(final Schema avroSchema) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build(); return createSchema(avroSchema, avroSchema.toString(), identifier); }
AvroTypeUtil { public static RecordSchema createSchema(final Schema avroSchema) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build(); return createSchema(avroSchema, avroSchema.toString(), identifier); } }
AvroTypeUtil { public static RecordSchema createSchema(final Schema avroSchema) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build(); return createSchema(avroSchema, avroSchema.toString(), identifier); }  }
AvroTypeUtil { public static RecordSchema createSchema(final Schema avroSchema) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build(); return createSchema(avroSchema, avroSchema.toString(), identifier); }  static Schema extractAvroSchema(final RecordSchema recordSchema); static DataType determineDataType(final Schema avroSchema); static DataType determineDataType(final Schema avroSchema, Map<String, DataType> knownRecordTypes); static RecordSchema createSchema(final Schema avroSchema); static RecordSchema createSchema(final Schema avroSchema, final String schemaText, final SchemaIdentifier schemaId); static boolean isNullable(final Schema schema); static Object[] convertByteArray(final byte[] bytes); static ByteBuffer convertByteArray(final Object[] bytes); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema, final Charset charset); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema, final Charset charset); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema, final Charset charset); }
AvroTypeUtil { public static RecordSchema createSchema(final Schema avroSchema) { if (avroSchema == null) { throw new IllegalArgumentException("Avro Schema cannot be null"); } SchemaIdentifier identifier = new StandardSchemaIdentifier.Builder().name(avroSchema.getName()).build(); return createSchema(avroSchema, avroSchema.toString(), identifier); }  static Schema extractAvroSchema(final RecordSchema recordSchema); static DataType determineDataType(final Schema avroSchema); static DataType determineDataType(final Schema avroSchema, Map<String, DataType> knownRecordTypes); static RecordSchema createSchema(final Schema avroSchema); static RecordSchema createSchema(final Schema avroSchema, final String schemaText, final SchemaIdentifier schemaId); static boolean isNullable(final Schema schema); static Object[] convertByteArray(final byte[] bytes); static ByteBuffer convertByteArray(final Object[] bytes); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema); static GenericRecord createAvroRecord(final Record record, final Schema avroSchema, final Charset charset); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema); static Object convertToAvroObject(final Object rawValue, final Schema fieldSchema, final Charset charset); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema); static Map<String, Object> convertAvroRecordToMap(final GenericRecord avroRecord, final RecordSchema recordSchema, final Charset charset); static final String AVRO_SCHEMA_FORMAT; }