Skip to content
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

schema from .avsc files #408

Closed
Oskar-PJ opened this issue Oct 4, 2022 · 1 comment
Closed

schema from .avsc files #408

Oskar-PJ opened this issue Oct 4, 2022 · 1 comment

Comments

@Oskar-PJ
Copy link

Oskar-PJ commented Oct 4, 2022

Hi,

I can't seem to figure out how to load a schema from an .avsc file. Are there any examples on how to do this?
I'd like to recursively do so from several files in a directory.

So far I've only ever used Python to connect to a kafka stream sending avro's. There I use the following to load a schema:
fastavro.schema.load_schema(<path to top .avsc file>)
https://fastavro.readthedocs.io/en/latest/schema.html#:~:text=load_schema(schema_path%3A

@Oskar-PJ
Copy link
Author

Oskar-PJ commented Oct 5, 2022

Ok, so I found out I can do this like so: #32
However, since I have 20 odd .avsc files this becomes very messy.

I solved my problem by using the fastavro python library to merge all the .avsc's into one json.

and then reading that with avsc.parse:

type= avsc.parse(JSON.parse(fs.readFileSync('./ipm-avro-legacy/avro.json')));

....

type.fromBuffer(kafkamsg.value)

@Oskar-PJ Oskar-PJ closed this as completed Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant