Comments (10)
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.
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.
@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.
can anyone share any example?
from avro.
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.
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.
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.
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.
@iyashjayesh let me know if this code helps you
https://gist.github.com/TuSKan/35ae72fac0ec6aa9e71a0ffbedd4790f
from avro.
Closing as this is not a planned feature of the library.
from avro.
Related Issues (20)
- Ref types error HOT 3
- Proposal: allow adjusting array/map block header format HOT 1
- Support tinygo HOT 6
- Are cross schema references supported? HOT 2
- PropertySchema properties are not JSON marshalled/unmarshalled HOT 5
- Referencing defined type throw error "unknown type" HOT 5
- Encoding Fixed Type In A Union
- AvroGen: generates duplicate structs due to a name resolution conflict HOT 7
- Schema with duplicate names should throw error
- Encoding to JSON does not reference reused types HOT 1
- Unmarshaling Interface Types in a Union HOT 6
- Reset the schema cache? HOT 4
- AVRO schema refs with Hamba avro HOT 8
- Support original name for structs
- Add protocol original schema string HOT 4
- Infinite loop parsing recursive schema HOT 1
- Encoding a struct with a sub-record field default value failed HOT 2
- avrogen: does not support logicalType: "uuid" in a union
- Support TextMarshaler/TextUnmarshaler for map keys HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avro.