Giter Club home page Giter Club logo

Comments (10)

nrwiersma avatar nrwiersma commented on June 3, 2024

Nothing like this existing in this library.

A method would be to use reflect to parse the struct an make the required Schema. From there you could JSON marshal it into a schema string.

from avro.

TuSKan avatar TuSKan commented on June 3, 2024

I have a code for that. From Go Struct to avro.Schema and vice versa.
@nrwiersma Do you have any interest to include this feature in the library ?

By the way, in my implementation I'm loosing the properties.
As a avro.Field is not a avro.Schema, the properties belong to the field and not to the type of the field which is a avro.Schema
Any idea on that?

from avro.

nrwiersma avatar nrwiersma commented on June 3, 2024

@TuSKan The library already has Schema -> Struct in cmd/avrogen. I would gladly accept Struct -> Schema, perhaps in cmd/schemagen?

By the way, in my implementation I'm loosing the properties.

The fields should maintain the properties as it inherits the properties struct, like most Schemas (not all Schemas can have properties), but like most Schemas, we dont marshal it back to JSON. It should be possible to do though. Check MarshalJSON.

from avro.

iyashjayesh avatar iyashjayesh commented on June 3, 2024

can anyone share any example?

from avro.

TuSKan avatar TuSKan commented on June 3, 2024

My problem is different from avrogen, I need to generate a Go Struct as a reflect.Type dynamically to Encode or Decode in runtime, rather than have a code gen to use further.

I looked to MarshalJSON, as you mention there is no properties there.

Why a avro.Field is not a avro.Schema ? Just missings a Fingerprint...

from avro.

nrwiersma avatar nrwiersma commented on June 3, 2024

These are the properties on the Field: https://github.com/hamba/avro/blob/main/schema.go#L537

Why a avro.Field is not a avro.Schema ? Just missings a Fingerprint...

The Field is not a Schema by spec.

There is no need to create a struct on the fly, and you can just decode/encoder from a map[string]any.

from avro.

TuSKan avatar TuSKan commented on June 3, 2024

I build a recursive func for avro.Schema, so for avro.RecordSchema I lose the properties of the Field. A Fingerprint method for Field doesn't make sense?

There is no need to create a struct on the fly, and you can just decode/encoder from a map[string]any.

mp[string]any is not a option to me. I work with huge files and databases, I need to have a real schema.

from avro.

nrwiersma avatar nrwiersma commented on June 3, 2024

Fields are not Schemas, regardless of the fingerprint. Assuming you parsed a non-canonical schema, any properties of the Field still exist and are accessible in the same way they are on a Schema.

from avro.

TuSKan avatar TuSKan commented on June 3, 2024

@iyashjayesh let me know if this code helps you
https://gist.github.com/TuSKan/35ae72fac0ec6aa9e71a0ffbedd4790f

from avro.

nrwiersma avatar nrwiersma commented on June 3, 2024

Closing as this is not a planned feature of the library.

from avro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.