-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map JSON Objects to Record instead of Map #130
Comments
It's been a few years since the original implementation, but I think that the rationale was that Perhaps @flavray remembers this detail more clearly, but I am not quite sure. |
For this problem, can we maybe make use of the Avro schemas? If we let the user provide one when going from JSON value to Avro value, we could get from the schema if it's defined as a record? |
I think you could, but I agree with @poros that it's not really the right thing to do. Using an Avro map means that you've actively decided that you need to support a possibly different set of keys in each instance. If you have a specific structure, you'd use a record instead. It's the same on the serde_json side. Using |
Hmm, yeah, I understand what you are saying. What would be the option to go from user input (which is completely dynamic) to an Avro Value? Like, user specifies a schema they want to follow and then input a document of some kind and I want to convert it to Avro and send it out? Currently, I am taking the user input as JSON, which is how I came up with this problem, but maybe there is a better solution to handle this with this library? |
Ahh yes, now I see what you're saying! For that, Avro defines a JSON encoding to go along with the binary encoding. And some of the other language bindings have a helper tool that reads in a bunch of JSON values and converts them to a binary Avro file according to some schema. The exact same JSON input can give you completely different Avro output files depending on which schema you choose. I don't think that's implemented in this library just yet, but I think you'd do it by adding something similar to |
Interesting approach and thoughts, thank you for your input. I'm gonna take a look into that after work :) maybe I can come up with something that's worth a PR. |
I noticed that the implementation for
ToAvro
on the serde_jsonValue
type maps values of typeObject
to the Avro valueMap
instead of the complex typeRecord
. Is there a specific reason for that? As far as I can tell, theRecord
type for Avro schemas is much more common in the definition than maps. Could we change the implementation to mapRecord
instead? I'd be happy to contribute that if there's nothing that blocks us from doing so.The text was updated successfully, but these errors were encountered: