Skip to content

Missing support for custom attributes on primitive types #368

Open

Description

@yshcz

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]
fn test1() -> 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.

Activity

  1. martin-g commented on Dec 16, 2025

    @martin-g
    Member

    The reason why the primitive types have no custom attributes is the following sentence from the specification:

    Primitive types have no specified attributes.
    

    If the Java SDK supports custom attributes for primitive types then I'm OK to add support here too.

  2. yshcz commented on Dec 16, 2025

    @yshcz
    Author

    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

  3. Kriskras99 commented on Dec 16, 2025

    @Kriskras99
    Contributor

    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:

    struct Schema {
        kind: SchemaEnum // what's currently Schema
        attributes: HashMap<String, Value>
    }

    Although how would we handle decimal and uuid in that case? Put the attributes in the inner type or in the logical type?

  4. yshcz commented on Dec 16, 2025

    @yshcz
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions