@Test public void testDefaultArrayValuesInRecordsCase1() throws IOException { Schema avroSchema = new Schema.Parser().parse(getClass().getResourceAsStream("defaultArrayInRecords1.json")); GenericRecordBuilder builder = new GenericRecordBuilder(avroSchema); Record field1Record = new GenericRecordBuilder(avroSchema.getField("field1").schema()).build(); builder.set("field1", field1Record); Record r = builder.build(); @SuppressWarnings("unchecked") GenericData.Array<Integer> values = (GenericData.Array<Integer>) ((GenericRecord) r.get("field1")) .get("listOfInt"); assertArrayEquals(new Object[] {}, values.toArray()); RecordSchema record = AvroTypeUtil.createSchema(avroSchema); RecordField field = record.getField("field1").get(); assertEquals(RecordFieldType.RECORD, field.getDataType().getFieldType()); RecordDataType data = (RecordDataType) field.getDataType(); RecordSchema childSchema = data.getChildSchema(); RecordField childField = childSchema.getField("listOfInt").get(); assertEquals(RecordFieldType.ARRAY, childField.getDataType().getFieldType()); assertTrue(childField.getDefaultValue() instanceof Object[]); assertArrayEquals(new Object[] {}, ((Object[]) childField.getDefaultValue())); }
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; }