Repository navigation
Description
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
logicalTypeattribute. - You parse the Json into an Avro type.
- You then serialise the schema back to Json.
What do I expect?
- The
logicalTypeshould still be present. - The behaviour should match the Java implementation.
What happened?
- The
logicalTypeis missing. - The behaviour does not match the Java implementation.
- The
logicalTypeis entirely dropped, making it impossible to correctly identifymaptypes 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
[-]`logicalType` is dropped from custom attributes[/-][+]regression bug, `logicalType` is dropped from custom attributes[/+]Kriskras99 commentedon Sep 3, 2026
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.
JosephLenton commentedon Sep 3, 2026
@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.
martin-g commentedon Sep 3, 2026
Could you please explain more ?
Why do you need the
logicalTypeas a custom attribute ?JosephLenton commentedon Sep 3, 2026
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:
logicalTypeis accessible again in some way (onattributesor aspub logicalType: Option<String>),logicalTypeis preserved (matching the behaviour in Java Avro).The Issue
The Iceberg spec has a
maptype which is implemented as an array. This is the example Json I posted above in the Rust test. A map schema is basically:array,recordwith the fieldskeyandvalue. i.e. It's an array of key / value pairs.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:
avro::Schema::Array,logicalType: maphere: https://github.com/JosephLenton/iceberg-rust/blob/main/crates/iceberg/src/avro/schema.rs#L365-L371logicalType, so we make it a map.AFAIK because the
logicalTypeis 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.
Kriskras99 commentedon Sep 3, 2026
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.
feat!: Make schema parser reuse the JSON allocations
feat!: Make schema parser reuse the JSON allocations (#656)