-
Notifications
You must be signed in to change notification settings - Fork 147
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
ambiguous unwrapped union #52
Comments
Yes, you can use var type = avro.parse(['int', 'double'], {wrapUnions: true}); This will change the decoded representation of the union's branches to include their type: this is required to not risk corrupting data since Avro types don't map perfectly to JavaScript types. Continuing the above example: type.isValid(12); // false
type.isValid({int: 12}); // true
type.isValid({double: 48}); // true Finally, the Does this answer your question? You can also read more about which unions are ambiguous and why on the API page. The issues referenced in #42 might be helpful too. |
Thanks for the fast response! I'm not sure this does answer the question, or, more specifically, I need some more help. I have an Avro data file which contains both data and schema. I don't know the schema "ahead of time." Is there a way to pass the wrapUnions option to the file decoder somehow? Or, is the only way to use that option is if I know the schema before trying to process a data file? Thanks. |
I see. Then you would still use the same option, applying it via // Hook called when the schema inside a file gets parsed.
function hook(attrs) { return avro.parse(attrs, {wrapUnions: true}); }
// A readable stream where all unions are wrapped.
var readable = avro.createFileDecoder('data.avro', {parseHook: hook}); |
That worked! Thank you very, very much!!! |
@mtth is there a way to use the code above, but from a buffer instead of from a file? Can't seem to figure that out.... Thanks! |
Do you mean decoding a buffer with a single encoded value, decoding a buffer with an entire container file inside of it, something else? If the first, the example in my first reply above should work, if the second you can "wrap" the buffer in a readable stream and pipe it to a |
It's a buffer containing a group of values (e.g. multiple "sets" of data). Can you give me an example of that syntax? Is it something like:
Thanks! |
I got it! Thanks! |
I get an error that says "ambiguous unwrapped union" when I try process one of my company's Avro log files.
Is there any way to somehow support this?
Thanks!
The text was updated successfully, but these errors were encountered: