lerouxrgd / rsgen-avro

Command line and library for generating Rust types from Avro schemas
MIT License
37 stars 29 forks source link

Support logical date and timestamp types #51

Closed hsn10 closed 1 year ago

hsn10 commented 1 year ago

I need support for:

{"name":"day", "type" : {"type":"int", "logicalType":"date"}},

and

{"name":"start",            "type" : {"type":"long", "logicalType":"timestamp-millis"}},
hsn10 commented 1 year ago

Logical types are supported in Official Rust version of AVRO:

https://github.com/apache/avro/blob/master/lang/rust/avro/src/schema.rs

I don't really understand their official rust code. Do they deserialize logical types to integer/long? In this case, their support will be just adding logicalType label to reading/writing schema. In Java these types are deserialized to java.time.LocalTime;

lerouxrgd commented 1 year ago

I made a basic implementation on this branch with chrono (You then need to add it to your Cargo.toml with the serde feature).

Could you give it a try with:

git clone https://github.com/lerouxrgd/rsgen-avro.git
cd rsgen-avro
git checkout chrono-dates
cargo run -- <path/to/your/schema.avsc> --chrono-dates -

Let me know how it goes.

lerouxrgd commented 1 year ago

Released in version 0.11.11, don't hesitate to re-open if something is wrong.

hsn10 commented 1 year ago

I need to test it against spark. if timezone is correct.