Skip to content

feat: Duration inner fixed schema and serialization - #382

Merged
Kriskras99 merged 10 commits into
apache:mainfrom
jdarais:feat-serde-duration
Jan 7, 2026
Merged

Kriskras99 merged 10 commits into
apache:mainfrom
jdarais:feat-serde-duration

Conversation

@jdarais

@jdarais jdarais commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

This PR adds some missing functionality for the Duration type:

  • Schema::Duration is updated to contain a FixedSchema struct, which contains name, namespace, size, doc, etc. fields that can exist on Duration types. (Name and Namespace fields for Schema::Duration #378)
  • apache_avro's Duration type is updated to implement Serialize and Deserialize to support inclusion in structs de/serialized from/to avro "the serde way"
  • Small fix to the Deserializer implementation in serde/de.rs to allow Value::Duration to be deserialized. (Duration is deserialized as bytes.)

This PR also deprecates SchemaKind::is_named in favor of a new Schema::is_named function, which can correctly determine whether a schema is for a named type, even when it is for a logical type that could have either a named or non-named underlying type, (such as "decimal" or "uuid".)

One note on this change: I noticed that the derive macro for AvroSchema was using the Duration schema for core::time::Duration. It is no longer trivial to create a schema for a Duration type, since the schema would need to be given a name. It looks like other named types are excluded from these derive macros, so I just deleted the impl_schema!(core::time::Duration, Schema::Duration) line, but I'm not sure if there's something better that can be done here.

@Kriskras99 Kriskras99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First glance looks good, I'll have a more in depth look tomorrow

Comment thread avro/src/decode.rs Resolved
Comment thread avro/src/duration.rs Resolved
Comment thread avro/src/duration.rs Resolved
Comment thread avro/src/schema_equality.rs Resolved
@jdarais

jdarais commented Dec 30, 2025

Copy link
Copy Markdown
Contributor Author

@Kriskras99 thanks for the feedback, I made the suggested changes

Comment thread avro/src/serde/de.rs Resolved
Comment thread avro/src/schema.rs Resolved
Comment thread avro/src/schema.rs Resolved
Comment thread avro/src/schema.rs Resolved
Comment thread avro/src/schema.rs Resolved
Comment thread avro/src/types.rs Resolved
Comment thread avro/src/schema_equality.rs Resolved
Comment thread avro/src/duration.rs Resolved
Comment thread avro/src/schema.rs Resolved
@jdarais

jdarais commented Jan 4, 2026

Copy link
Copy Markdown
Contributor Author

@martin-g thanks for all the feedback! I should have taken a closer look at the Schema enum and schema comparison functions. I made fixes and added some tests to address all but one of your comments, and on the one remaining one, I responded and would be interested in your thoughts.

@martin-g martin-g added this to the 0.22.0 milestone Jan 5, 2026
Comment thread avro/src/schema.rs Resolved
Comment thread avro/src/writer.rs Resolved
Comment thread avro/src/serde/de.rs Resolved
Comment thread avro/src/schema.rs Resolved
Comment thread avro/src/schema_equality.rs Resolved
Comment thread avro/src/schema_equality.rs Resolved
@martin-g martin-g changed the title Duration inner fixed schema and serialization feat: Duration inner fixed schema and serialization Jan 7, 2026
@Kriskras99

Copy link
Copy Markdown
Contributor

Thanks for your contribution @jdarais!

@Kriskras99
Kriskras99 merged commit 086bc67 into apache:main Jan 7, 2026
KitFieldhouse added a commit to KitFieldhouse/avro-rs that referenced this pull request Jan 14, 2026
@Kriskras99 Kriskras99 mentioned this pull request Jun 28, 2026
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

Successfully merging this pull request may close these issues.

3 participants