@SuppressWarnings("unchecked") private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException { recordClazz = (Class<? extends SpecificRecord>) inputStream.readObject(); schemaString = inputStream.readUTF(); typeInfo = (RowTypeInfo) AvroSchemaConverter.<Row>convertToTypeInfo(schemaString); schema = new Schema.Parser().parse(schemaString); if (recordClazz != null) { record = (SpecificRecord) SpecificData.newInstance(recordClazz, schema); } else { record = new GenericData.Record(schema); } datumReader = new SpecificDatumReader<>(schema); this.inputStream = new MutableByteArrayInputStream(); decoder = DecoderFactory.get().binaryDecoder(this.inputStream, null); } }
@Override public Object createFixed(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.createFixed(old, schema); // punt to generic return c.isInstance(old) ? old : newInstance(c, schema); }
@Override public Object newRecord(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.newRecord(old, schema); // punt to generic return (c.isInstance(old) ? old : newInstance(c, schema)); }
@Override public Object createFixed(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.createFixed(old, schema); // punt to generic return c.isInstance(old) ? old : newInstance(c, schema); }
@Override public Object newRecord(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.newRecord(old, schema); // punt to generic return (c.isInstance(old) ? old : newInstance(c, schema)); }
/** * Creates a Avro deserialization schema for the given specific record class. Having the * concrete Avro record class might improve performance. * * @param recordClazz Avro record class used to deserialize Avro's record to Flink's row */ public AvroRowDeserializationSchema(Class<? extends SpecificRecord> recordClazz) { Preconditions.checkNotNull(recordClazz, "Avro record class must not be null."); this.recordClazz = recordClazz; schema = SpecificData.get().getSchema(recordClazz); typeInfo = (RowTypeInfo) AvroSchemaConverter.convertToTypeInfo(recordClazz); schemaString = schema.toString(); record = (IndexedRecord) SpecificData.newInstance(recordClazz, schema); datumReader = new SpecificDatumReader<>(schema); inputStream = new MutableByteArrayInputStream(); decoder = DecoderFactory.get().binaryDecoder(inputStream, null); }
return SpecificData.newInstance(collectionClass, schema);
return SpecificData.newInstance(collectionClass, schema);
@Override @SuppressWarnings("unchecked") public void start() { // Should do the right thing whether it is generic or specific this.currentRecord = (T) ((this.specificClass == null) ? new GenericData.Record(avroSchema) : SpecificData.newInstance(specificClass, avroSchema)); }
@Override public Object newRecord(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.newRecord(old, schema); // punt to generic return (c.isInstance(old) ? old : newInstance(c, schema)); }
@Override public Object createFixed(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.createFixed(old, schema); // punt to generic return c.isInstance(old) ? old : newInstance(c, schema); }
@Override public Object newRecord(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.newRecord(old, schema); // punt to generic return (c.isInstance(old) ? old : newInstance(c, schema)); }
@Override public Object createFixed(Object old, Schema schema) { Class c = getClass(schema); if (c == null) return super.createFixed(old, schema); // punt to generic return c.isInstance(old) ? old : newInstance(c, schema); }
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException { recordClazz = (Class<? extends SpecificRecord>) inputStream.readObject(); schemaString = inputStream.readUTF(); typeInfo = (RowTypeInfo) AvroSchemaConverter.<Row>convertToTypeInfo(schemaString); schema = new Schema.Parser().parse(schemaString); if (recordClazz != null) { record = (SpecificRecord) SpecificData.newInstance(recordClazz, schema); } else { record = new GenericData.Record(schema); } datumReader = new SpecificDatumReader<>(schema); this.inputStream = new MutableByteArrayInputStream(); decoder = DecoderFactory.get().binaryDecoder(this.inputStream, null); } }
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream inputStream) throws ClassNotFoundException, IOException { recordClazz = (Class<? extends SpecificRecord>) inputStream.readObject(); schemaString = inputStream.readUTF(); typeInfo = (RowTypeInfo) AvroSchemaConverter.<Row>convertToTypeInfo(schemaString); schema = new Schema.Parser().parse(schemaString); if (recordClazz != null) { record = (SpecificRecord) SpecificData.newInstance(recordClazz, schema); } else { record = new GenericData.Record(schema); } datumReader = new SpecificDatumReader<>(schema); this.inputStream = new MutableByteArrayInputStream(); decoder = DecoderFactory.get().binaryDecoder(this.inputStream, null); } }
@Override protected Object newArray(Object old, int size, Schema schema) { Class<?> collectionClass = ReflectData.getClassProp(schema, SpecificData.CLASS_PROP); Class<?> elementClass = ReflectData.getClassProp(schema, SpecificData.ELEMENT_PROP); if (collectionClass == null && elementClass == null) return super.newArray(old, size, schema); // use specific/generic if (collectionClass != null && !collectionClass.isArray()) { if (old instanceof Collection) { ((Collection<?>)old).clear(); return old; } if (collectionClass.isAssignableFrom(ArrayList.class)) return new ArrayList<Object>(); return SpecificData.newInstance(collectionClass, schema); } if (elementClass == null) { elementClass = collectionClass.getComponentType(); } if (elementClass == null) { ReflectData data = (ReflectData)getData(); elementClass = data.getClass(schema.getElementType()); } return Array.newInstance(elementClass, size); }
/** * Creates a Avro deserialization schema for the given record. * * @param recordClazz Avro record class used to deserialize Avro's record to Flink's row */ public AvroRowDeserializationSchema(Class<? extends SpecificRecord> recordClazz) { Preconditions.checkNotNull(recordClazz, "Avro record class must not be null."); this.schema = SpecificData.get().getSchema(recordClazz); this.datumReader = new SpecificDatumReader<>(schema); this.record = (SpecificRecord) SpecificData.newInstance(recordClazz, schema); this.inputStream = new MutableByteArrayInputStream(); this.decoder = DecoderFactory.get().binaryDecoder(inputStream, null); }
/** * Creates a Avro deserialization schema for the given specific record class. Having the * concrete Avro record class might improve performance. * * @param recordClazz Avro record class used to deserialize Avro's record to Flink's row */ public AvroRowDeserializationSchema(Class<? extends SpecificRecord> recordClazz) { Preconditions.checkNotNull(recordClazz, "Avro record class must not be null."); this.recordClazz = recordClazz; schema = SpecificData.get().getSchema(recordClazz); typeInfo = (RowTypeInfo) AvroSchemaConverter.convertToTypeInfo(recordClazz); schemaString = schema.toString(); record = (IndexedRecord) SpecificData.newInstance(recordClazz, schema); datumReader = new SpecificDatumReader<>(schema); inputStream = new MutableByteArrayInputStream(); decoder = DecoderFactory.get().binaryDecoder(inputStream, null); }
/** * Creates a Avro deserialization schema for the given specific record class. Having the * concrete Avro record class might improve performance. * * @param recordClazz Avro record class used to deserialize Avro's record to Flink's row */ public AvroRowDeserializationSchema(Class<? extends SpecificRecord> recordClazz) { Preconditions.checkNotNull(recordClazz, "Avro record class must not be null."); this.recordClazz = recordClazz; schema = SpecificData.get().getSchema(recordClazz); typeInfo = (RowTypeInfo) AvroSchemaConverter.convertToTypeInfo(recordClazz); schemaString = schema.toString(); record = (IndexedRecord) SpecificData.newInstance(recordClazz, schema); datumReader = new SpecificDatumReader<>(schema); inputStream = new MutableByteArrayInputStream(); decoder = DecoderFactory.get().binaryDecoder(inputStream, null); }
return SpecificData.newInstance(collectionClass, schema);