AVRO-1932: Java: Allow setting the SchemaStore on generated classes.#141
AVRO-1932: Java: Allow setting the SchemaStore on generated classes.#141nielsbasjes wants to merge 4 commits intoapache:masterfrom
Conversation
gszadovszky
left a comment
There was a problem hiding this comment.
Thanks for the patch.
I've added some comments. Please, check them out.
| public void setSchemaStore(SchemaStore newResolver) { | ||
| if (newResolver != null) { | ||
| this.resolver = newResolver; | ||
| } |
There was a problem hiding this comment.
Don't you think the user of this method should be informed about the fact that the resolver was not set? I would suggest throwing an exception here (e.g. IllegalStateException).
There was a problem hiding this comment.
Easier: Remove that check and thus allow 'removing' the SchemaStore again.
There was a problem hiding this comment.
Yes, this would be simpler if it fits the logic. :)
There was a problem hiding this comment.
It does. The resolver is an optional thing that is common to be null.
| * | ||
| * @param newResolver a {@link SchemaStore} to use when decoding buffers | ||
| */ | ||
| public void setSchemaStore(SchemaStore newResolver) { |
There was a problem hiding this comment.
This class supposed to be thread-safe. I would suggest having this one synchronized.
gszadovszky
left a comment
There was a problem hiding this comment.
Thanks for the modification and the description.
LGTM.
|
It looks like the only motivation for adding I originally thought that the best path for setting up a reader for evolving schemas would be to create a new MessageDecoder rather than using the one backing the convenience methods. But this seems pretty reasonable use case. What about instead of changing the schema store, adding a static method What do you think? |
|
The core of what I need is to be able to set a custom backend to retrieve the schemas from when using the IDL generated classes and transparently deserialize both older and newer schemas. I want to be able to add them manually (i.e. If the producing application puts messages with a new schema into Kafka and the downstream application has not yet been updated I want it (without any code modification) be able to pickup the schema from the registry and simply read the provided record and continue. Thus simply having the option to explicitly add new schema's is not enough for the project I'm working on. When trying to solve this I found a lot of the related variables are either 'final' and/or 'private'. This makes it impossible to add an extra schema to the generated classes at all. Effectively blocking the very nice schema evolution features from the application developer. With the change I presented here the developer can set a single instance of the SchemaStore per (generated) class. I consider that to be enough. I do not expect people to have a need for multiple 'databases' for their schema's for a single record type (or even in a single application). If they do then they can always create a SchemaStore that retrieves the data from multiple backends. I tried to minimize the impact on the generated classes so I chose to only add the getDecoder method to open it up and add a method to set the SchemaStore which in case of the generated classes was a final variable set to null. The In fact today I wrote (as an experiment) a script that loops over the last 20 git commits, generate the source, do a creative fgrep/sed combination and generate a helper class that does a Foo.getDecoder.addSchema for each of the older versions into a class that is then part of my project. Effectively I generate a static method that does something like this: I'm still testing that experiment in combination with Flink and Kafka and a custom DeserializationSchema instance (sofar it looks good) So from my perspective I think the current code in my pull request are (close to) optimal. |
|
I don't think that I think it's fine to add the |
…bility of the SchemaStore in the decoder.
|
@rdblue Please have a look at this change. I made the SchemaStore final again yet I added a convenience function to more easily create a new decoder for the specific class. What do you think? |
|
+1 Thanks, @nielsbasjes! I think this is a better way forward. |
|
Committed |
This change is needed to allow setting a different SchemaStore in the IDL generated classes.