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
type.enum is valid while it should fail, good is type.type.enum according to spec #476
I couldn't find any example in the specification of type.enum, and given that avro-tools fails to generate the java code, I assume type.enum is wrong. Let me know if that's not the case.
I think you're correct. As far as I'm aware only primitive types and references are allowed to be declared directly, complex types need an extra object.
The problem is the most pressing for enum and fixed as they currently always share their type name with the field name. @martin-g what do you think? I think this is the right thing to do.
Both ways are supported for backwards compatibility. The "flat" way was there since the donation of the original avro-rs crate to ASF.
I'll have to check with the spec to verify that it is not supported. But I guess there are users of the flat way in the wild.
The two Java tests you linked, don't actually use the flattened layout.
But it does indeed seem we need to accept flattened types (but not accept logical type).
this is interpreted not as an attempt to have a flattened type definition, but is instead interpreted as saying that the field "wrong_enum" is an instance of a named type that has the literal name "enum". I believe the extra JSON field (in this case "symbols" ) is effectively ignored.
This stems from one of the unfortunate aspects (in my opinion) of the current avro specification, which is that it allows you to have a named type that has a name equal to that of a complex built-in type (but at least mandates that you cannot "redefine" primitive names in this way). Quoting the spec:
Primitive type names (null, boolean, int, long, float, double, bytes, string) have no namespace and their names may not be defined in any namespace.
Complex types (record, enum, array, map, fixed) have no namespace, but their names (as well as union) are permitted to be reused as type names. This can be confusing to the human reader, but is always unambiguous for binary serialization. Due to the limitations of JSON encoding, it is a best practice to use a namespace when using these names.
A schema or protocol may not contain multiple definitions of a fullname. Further, a name must be defined before it is used (“before” in the depth-first, left-to-right traversal of the JSON parse
For instance, we can make @Kriskras99's example work with the python tooling by defining a named type with name "fixed" earlier in the walk the parser takes. That is, instead of:
In my testing, python does not reject this schema and treats the second field "FixedType" as the enum we defined in "FixedTypeDef". The java build tool that generates classes based on avro schema also seems to work the exact same way. Here is how I tested the python tooling:
So I think the issue in the original python example is not that it rejects the schema because it sees it as an attempt to "flatten" the definition, it rejects it because it can not find a named schema with the name "fixed".
To avoid ambiguity of what we should do on the schema field "type", we have to know where we are in the parsing tree. If we are directly inside a schema, a "type" value equal to any of the complex type names indicates that we are defining a a type of that form. Inside "fields" for a record type; "type" indicates that we are looking for a named type with that name, a primitive type with that name, or is a new nested type definition.
Activity
Kriskras99 commentedon Feb 20, 2026
I think you're correct. As far as I'm aware only primitive types and references are allowed to be declared directly, complex types need an extra object.
Kriskras99 commentedon Feb 20, 2026
The patch for this is trivial:
But this breaks 26 tests, all because they use a complex type directly in a field:
{ "type": "record", "fields": [ { "name": "this_issue", "type": "enum", "symbols": ["INSERT", "UPDATE"] }, { "name": "direct_map", "type": "map", "values": "long" }, { "name": "direct_array", "type": "array", "items": "long" }, { "name": "direct_fixed", "type": "fixed", "size": 16 } ] }The problem is the most pressing for
enumandfixedas they currently always share their type name with the field name.@martin-g what do you think? I think this is the right thing to do.
martin-g commentedon Feb 20, 2026
Both ways are supported for backwards compatibility. The "flat" way was there since the donation of the original avro-rs crate to ASF.
I'll have to check with the spec to verify that it is not supported. But I guess there are users of the flat way in the wild.
Kriskras99 commentedon Feb 20, 2026
One more issue with this change:
{ "type": "record", "name": "test", "fields": [ {"name": "a", "type": {"type": "long", "logicalType": "timestamp-micros"}} ] }vs
{ "type": "record", "name": "test", "fields": [ {"name": "a", "type": "long", "logicalType": "timestamp-micros"} ] }This does not parse the logical type with the patch provided above. We should probably check what the Java implementation does in these cases
woile commentedon Feb 20, 2026
avro-toolsthrows a warning for this case:martin-g commentedon Feb 23, 2026
Here are some IT tests in the Java SDK which also use the flatten layout:
Here is a simple Java app that confirms that it supports the flatten way:
I cannot tell what avro-tools.jar does differently than SchemaParser.
martin-g commentedon Feb 23, 2026
And here is a Python script that confirms the same:
Kriskras99 commentedon Feb 23, 2026
The two Java tests you linked, don't actually use the flattened layout.
But it does indeed seem we need to accept flattened types (but not accept logical type).
martin-g commentedon Feb 23, 2026
The second variant in the union schemas look flattened to me:
https://github.com/apache/avro/blob/999b36feadf76ff9eb7535a66a00dbffba8b0b75/lang/java/integration-test/codegen-test/src/test/resources/avro/nested_logical_types_union_fixed.avsc#L9-L15
Kriskras99 commentedon Feb 23, 2026
A type can only be flattened in a record field right?
This is a type definition:
{ "namespace": "org.apache.avro.codegentest.testdata", "name": "FixedType", "type": "fixed", "size": 12, "logicalType": "decimal", "precision": 28, "scale": 15 }If we would add that to a record the correct way:
{ "namespace": "org.apache.avro.codegentest.testdata", "type": "record", "name": "NestedLogicalTypesUnionFixedDecimal", "doc" : "Test nested types with logical types in generated Java classes", "fields": [ { "name": "unionOfFixedDecimal", "type": { "namespace": "org.apache.avro.codegentest.testdata", "name": "FixedType", "type": "fixed", "size": 12, "logicalType": "decimal", "precision": 28, "scale": 15 } }] }And flattened would look like this:
{ "namespace": "org.apache.avro.codegentest.testdata", "type": "record", "name": "NestedLogicalTypesUnionFixedDecimal", "doc" : "Test nested types with logical types in generated Java classes", "fields": [ { "namespace": "org.apache.avro.codegentest.testdata", "name": "FixedType", "type": "fixed", "size": 12, "logicalType": "decimal", "precision": 28, "scale": 15 }] }In the flattened case there are a few possible confusions:
logicalTypeis ignored in the Python (and probably Java) implementationsIn the test you linked, the type is a union which contains a fixed type. Which is correct.
woile commentedon Feb 23, 2026
Would you say this is a bug in avro-tools then?
martin-g commentedon Feb 23, 2026
No. I misunderstood the problem.
@Kriskras99 explained it at #476 (comment)
Kriskras99 commentedon Feb 23, 2026
I just double checked with the python tooling and this fails:
So #479 is correct.
KitFieldhouse commentedon Mar 6, 2026
I think there might be a misunderstanding here on what the issue is.
My understanding of how the java and python tools work is that for the example in the original post:
this is interpreted not as an attempt to have a flattened type definition, but is instead interpreted as saying that the field "wrong_enum" is an instance of a named type that has the literal name "enum". I believe the extra JSON field (in this case "symbols" ) is effectively ignored.
This stems from one of the unfortunate aspects (in my opinion) of the current avro specification, which is that it allows you to have a named type that has a name equal to that of a complex built-in type (but at least mandates that you cannot "redefine" primitive names in this way). Quoting the spec:
For instance, we can make @Kriskras99's example work with the python tooling by defining a named type with name
"fixed"earlier in the walk the parser takes. That is, instead of:we add another field where we have "defined"
"fixed"like this:In my testing, python does not reject this schema and treats the second field
"FixedType"as the enum we defined in"FixedTypeDef". The java build tool that generates classes based on avro schema also seems to work the exact same way. Here is how I tested the python tooling:So I think the issue in the original python example is not that it rejects the schema because it sees it as an attempt to "flatten" the definition, it rejects it because it can not find a named schema with the name
"fixed".To avoid ambiguity of what we should do on the schema field
"type", we have to know where we are in the parsing tree. If we are directly inside a schema, a"type"value equal to any of the complex type names indicates that we are defining a a type of that form. Inside"fields"for a record type;"type"indicates that we are looking for a named type with that name, a primitive type with that name, or is a new nested type definition.