eolivelli commented on a change in pull request #9481:
URL: https://github.com/apache/pulsar/pull/9481#discussion_r572682722
##########
File path:
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/generic/GenericAvroWriter.java
##########
@@ -52,4 +67,29 @@ public GenericAvroWriter(Schema schema) {
this.byteArrayOutputStream.reset();
}
}
+
+ /**
+ * This is an adapter from Pulsar GenericRecord to Avro classes.
+ */
+ private class GenericRecordAdapter extends SpecificRecordBase {
+ private GenericRecord message;
+
+ void setCurrentMessage(GenericRecord message) {
+ this.message = message;
+ }
+ @Override
+ public Schema getSchema() {
+ return schema;
+ }
+
+ @Override
+ public Object get(int field) {
+ return message.getField(schema.getFields().get(field).name());
+ }
+
+ @Override
+ public void put(int field, Object value) {
+ throw new UnsupportedOperationException();
+ }
+ }
Review comment:
here we are adding an adapter from a Pulsar GenericRecord to
SpecificRecordBase but we are interested in implementing only read-only methods.
if you prefer I can leave the implementation of this method empty, the
method won't be called by the writer.
If you run the integration test you will see that we are passing thru this
code.
Current implementation in master assumes that the GenericRecord is always a
GenericAvroRecord, but in case of this new feature it can be any implementation
of GenericRecord (and in fact in my case it will be a generic data structure
generated dynamically, with a dynamic schema)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]