Skip to content

regression bug, logicalType is dropped from custom attributes #654

Closed

Description

@JosephLenton

Hey, in version 0.22.0 the attribute logicalType was dropped entirely. I believe this is a regression, and is incorrect behaviour. I am pretty new to Avro, so I'm looking for some help on asserting if this is right. I have replicated the behaviour in both the Java and Rust Avro projects, and the results are different.

Steps to reproduce

  • You create a valid Json schema which contains a logicalType attribute.
  • You parse the Json into an Avro type.
  • You then serialise the schema back to Json.

What do I expect?

  • The logicalType should still be present.
  • The behaviour should match the Java implementation.

What happened?

  • The logicalType is missing.
  • The behaviour does not match the Java implementation.
  • The logicalType is entirely dropped, making it impossible to correctly identify map types for Iceberg.

Context

I am trying to upgrade the Iceberg repo from Avro 0.21.0 to 0.22.0. One test there is failing, which is for map types. There is no Avro equivalent, so the Iceberg spec asks for an array of key/value pairs + adding logicalType: map to the schema (see https://iceberg.apache.org/spec/#avro).

Avro 0.22.0 drops logicalType, which makes it impossible to truly identify the map type.

The Java version preserved the logicalType. The Java version has tests which perform a round trip and asserts what they started and ended with are the same. This implies the logicalType is preserved. See: https://github.com/apache/avro/blob/main/lang/java/avro/src/test/java/org/apache/avro/TestLogicalType.java#L190-L195

Finally the original PR was about fixing duplicate outputs of logicalType, not removing logicalType entirely. I suspect removing it entirely has crept in as a mistake.

Tests to reproduce

For Java

Here is a passing test for the Java Apache Avro repo at (https://github.com/apache/avro). It's a bit noisy. The key part is logicalType is at the end of the Json schema, and turning it from the schema to string yields the original schema.,

@Test
void logicalTypeTestReplication() {
  String rawSchema = "{\n" + "  \"type\" : \"array\",\n" + "  \"items\" : {\n" + "    \"type\" : \"record\",\n"
      + "    \"name\" : \"k12_v13\",\n" + "    \"fields\" : [ {\n" + "      \"name\" : \"key\",\n"
      + "      \"type\" : \"int\",\n" + "      \"field-id\" : 12\n" + "    }, {\n" + "      \"name\" : \"value\",\n"
      + "      \"type\" : \"string\",\n" + "      \"field-id\" : 13\n" + "    } ]\n" + "  },\n"
      + "  \"logicalType\" : \"map\"\n" + "}";

  Schema schema = SchemaParser.parseSingle(rawSchema);
  String output = schema.toString(true);

  assertEquals(rawSchema, output, "logicalType and custom properties should survive parsing");
}

For Rust

Here is the same test for your repo:

#[test]
fn it_should_preserve_map_logical_type_on_outer_item() -> TestResult {
    let raw_schema = r#"{
        "type": "array",
        "logicalType": "map",
        "items": {
            "type": "record",
            "name": "k12_v13",
            "fields": [
                {
                    "name": "key",
                    "type": "int",
                    "field-id": 12
                },
                {
                    "name": "value",
                    "type": "string",
                    "field-id": 13
                }
            ]
        }
    }"#;

    let schema = Schema::parse_str(raw_schema)?;
    let output = serde_json::to_string_pretty(&schema).unwrap();
    pretty_assertions::assert_eq!(r#"{
  "type": "array",
  "logicalType": "map", // <-- this is missing!
  "items": {
    "type": "record",
    "name": "k12_v13",
    "fields": [
      {
        "name": "key",
        "type": "int",
        "field-id": 12
      },
      {
        "name": "value",
        "type": "string",
        "field-id": 13
      }
    ]
  }
}"#, output);

    let logical_type = schema
        .custom_attributes()
        .unwrap()
        .get("logicalType");

    // !!! This fails !!!
    assert!(logical_type.is_some());

    Ok(())
}

Blocks: github.com/apache/iceberg-rust/issues/3063

(If someone can double check and confirm my findings, then I would be happy to make a PR that fixes this.)

Activity

  1. changed the title [-]`logicalType` is dropped from custom attributes[/-] [+]regression bug, `logicalType` is dropped from custom attributes[/+] on Sep 2, 2026
  2. Kriskras99 commented on Sep 3, 2026

    @Kriskras99
    Contributor

    In 0.21.0 we used to unconditionally keep the attribute in custom attributes (even if we recognize it). In 0.22.0 we unconditionally remove it from custom attributes.
    I have a fix in mind.

  3. JosephLenton commented on Sep 3, 2026

    @JosephLenton
    Author

    @Kriskras99 I would be happy to also build a fix for you, if you can provide more details on where it should live on the Schema API if not in custom attributes.

    For context I’ve spent the last month trying to fix UUID bugs in the Rust version of Iceberg, and the remainder of the work needs Avro 0.22. However this new regression blocks that. So I’m eager to help in anyway possible to get this resolved asap.

  4. martin-g commented on Sep 3, 2026

    @martin-g
    Member

    However this new regression blocks that

    Could you please explain more ?
    Why do you need the logicalType as a custom attribute ?

  5. JosephLenton commented on Sep 3, 2026

    @JosephLenton
    Author

    Cheers @martin-g for taking a look. I'll try to explain it. To be clear, it doesn't need to be a custom attribute. What I'm asking for is:

    • logicalType is accessible again in some way (on attributes or as pub logicalType: Option<String>),
    • When you serialise a Schema, the logicalType is preserved (matching the behaviour in Java Avro).

    The Issue

    The Iceberg spec has a map type which is implemented as an array. This is the example Json I posted above in the Rust test. A map schema is basically:

    • an array,
    • it holds a record with the fields key and value. i.e. It's an array of key / value pairs.
    • And it has logicalType: map.

    The example schema from the Iceberg spec is this:

    {
      "type": "array",
      "logicalType": "map", // <-- marks it as being a map.
      "items": {
        "type": "record",
        "name": "k12_v13",
        "fields": [
          {
            "name": "key",
            "type": "int",
            "field-id": 12
          },
          {
            "name": "value",
            "type": "string",
            "field-id": 13
          }
        ]
      }
    }

    Where it fails in Iceberg

    The failing test I have is here: https://github.com/JosephLenton/iceberg-rust/blob/main/crates/iceberg/src/avro/schema.rs#L922 (this is from main and it's the same on my own branch).

    What happens is:

    1. We parse the Json Schema,
    2. we receive an avro::Schema::Array,
    3. then we then check if it has logicalType: map here: https://github.com/JosephLenton/iceberg-rust/blob/main/crates/iceberg/src/avro/schema.rs#L365-L371
    4. Before: it has the logicalType, so we make it a map.
    5. Now: the type is missing!

    AFAIK because the logicalType is getting stripped out, I cannot solve this in Avro 0.22.0. I could look at the raw json but it gets hacky.

    ^ I'm aware what I wrote above is quite long. I can repeat it again in shorter comments if it's too much to go over. Let me know if I'm making sense or not, and I can try to clarify stuff.

  6. Kriskras99 commented on Sep 3, 2026

    @Kriskras99
    Contributor

    I'm working on a fix, should have something good this weekend (I'm not just fixing this bug, but making the parser more robust in general).
    I also want to temper your expectations about a quick release. Even if a patch is merged right now, getting a release out can take weeks.

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