fix(avro): support maps, nullable fields and recursive schemas - #693
Merged
Conversation
The Avro extension emitted code that did not compile — or schemas Avro refused to parse — for several shapes the language allows: - maps hit `TODO()` while flattening the schema, and had no conversion at all in `to`/`from` - nullable fields were dereferenced unconditionally, so a null field threw instead of staying null - arrays of primitives converted per element as though they held records - values Avro hands back as `Utf8` were cast straight to `String` - `bytes` round-tripped through `String(...)` rather than the ByteArray the model holds - a type referring back to itself, directly or through a nested record, spliced its own `SCHEMA` in and recursed forever Each schema is now emitted per definition and self-contained: names are tracked while flattening, so a record or enum is written out in full the first time it appears and referred to by name after that — which is both how Avro deduplicates and the only way to express a recursive type. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
The Avro extension emitted code that did not compile — or schemas Avro refused to parse — for several shapes the Wirespec language allows. This fixes the emitter for those shapes and adds tests covering each one.
What was broken
Map<String, T>TODO()while flattening the schema; noto/fromconversion at allList<primitive>String, but Avro hands them back asUtf8bytesString(...)rather than theByteArraythe model holdsSCHEMAin and recursed forever (directly or via a nested record)Approach
Each schema is now emitted per definition and self-contained, rather than picked out of the whole module. Names are tracked while flattening: a record or enum is written out in full the first time it appears and referred to by bare name after that — which is both how Avro deduplicates and the only way to express a recursive type.
to/fromconversions were reworked to be driven by the reference shape: collections of primitives pass through untouched, record-valued ones convert per entry, and nullable slots keep their null under?.instead of being dereferenced.Test plan
emitKotlinCollections— maps, arrays of primitives, nullable collections and nullable records, asserting both the emitted conversions and the map schemaemitKotlinRecursiveSchema— a self-referencing node type, asserting the self reference is a bare name, a nested record appears in full once then by name, andSCHEMAnever references itself./gradlew :src:integration:avro:jvmTest— passing🤖 Generated with Claude Code