You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing support for custom attributes on primitive types #368
Avro allows attaching custom properties to any type, including primitives.
In avro-rs, primitive schemas like Schema::Long/Schema::Int/etc are modeled as bare enum variants and there is no field to store custom properties. Schema::custom_attributes() also returns None for primitives.
As a result, parsing an object-form primitive schema silently drops all extra properties, and serializing the parsed schema emits just "long", so the metadata cannot be inspected or round-tripped.
reproducer:
use apache_avro::Schema;use apache_avro_test_helper::TestResult;use serde_json::json;#[test]fntest1() -> TestResult{let input = json!({"type":"long","custom-prop":"value"});let schema = Schema::parse(&input)?;assert!(matches!(schema,Schema::Long));let serialized = serde_json::to_string(&schema)?;assert!(
serialized.contains("custom-prop"),"Expected serialized schema to include custom property key, but it was dropped. Serialized: {serialized}. Parsed schema: {schema:?}");Ok(())}
output:
Expected serialized schema to include custom property key, but it was dropped. Serialized: "long". Parsed schema: Long
Iceberg encodes types like timestamptz to Avro as a primitive long with additional properties (e.g. {"type":"long","logicalType":"timestamp-micros","adjust-to-utc":true} or similar depending on precision).
Since apache-avro cannot represent custom properties on primitive types, the adjust-to-utc flag is dropped during parsing and the original schema semantics cannot be preserved.
The spec also says Attributes not defined in this document are permitted as metadata, but must not affect the format of serialized data.. I'm not a spec-lawyer, but I think it's reasonable to interpret this as: primitives have no "specified" attributes, but can still have attributes that are "not defined in the spec".
Activity
martin-g commentedon Dec 16, 2025
The reason why the primitive types have no custom attributes is the following sentence from the specification:
If the Java SDK supports custom attributes for primitive types then I'm OK to add support here too.
yshcz commentedon Dec 16, 2025
hi @martin-g
The spec also says
Attributes not defined in this document are permitted as metadata, but must not affect the format of serialized data.. I'm not a spec-lawyer, but I think it's reasonable to interpret this as: primitives have no "specified" attributes, but can still have attributes that are "not defined in the spec".Python and C# impls had similar issues(https://issues.apache.org/jira/browse/AVRO-1545, https://issues.apache.org/jira/browse/AVRO-2862)
The Java impl has a specific test for this case https://github.com/apache/avro/blob/release-1.12.1/lang/java/avro/src/test/java/org/apache/avro/TestSchemaBuilder.java#L92-L97
Kriskras99 commentedon Dec 16, 2025
If we're going to add custom attributes to all variants, it might be wise to split them from the Schema enum. So maybe something like this:
Although how would we handle decimal and uuid in that case? Put the attributes in the inner type or in the logical type?
yshcz commentedon Dec 16, 2025
I'm not particularly familiar with the codebase, but arrow-avro's approach might be a good start: https://github.com/apache/arrow-rs/blob/57.1.0/arrow-avro/src/schema.rs#L166
FYI, I'm not planning to work on this myself. I just wanted to report the issue since it was blocking my use case.