CORE-16246 schema_registry/avro: collapse primitive type objects#30565
Open
pgellert wants to merge 1 commit into
Open
CORE-16246 schema_registry/avro: collapse primitive type objects#30565pgellert wants to merge 1 commit into
pgellert wants to merge 1 commit into
Conversation
Avro's parsing canonical form treats a primitive object schema like
`{"type":"string"}` as equivalent to the simple string form. Redpanda
previously kept the object form, so equivalent schemas could be stored
under different canonical definitions.
Keep the existing sanitize traversal unchanged. After sanitization, walk
only the parts of the Avro JSON that are schemas: record field types,
array items, map values, and union branches. This leaves
primitive-looking custom metadata as-is.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Avro schema canonicalization in Redpanda Schema Registry by treating primitive object-form schemas (e.g. {"type":"string"}) as equivalent to the simple form ("string") when they appear at the top level and in nested schema positions, preventing false-negative schema lookups.
Changes:
- Added a post-sanitization pass that collapses primitive object-form schemas into their simple string form, but only in Avro schema-bearing positions (record field types, array items, map values, union branches, and top-level schemas).
- Added targeted regression tests for CORE-16246/CORE-16247, including idempotence and “do not touch metadata / logicalType / non-primitive refs” cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/v/pandaproxy/schema_registry/avro.cc | Adds a schema-tree walker to collapse primitive {"type":"<primitive>"} objects into "primitive" only in schema-bearing positions, and wires it into sanitize_avro_schema_definition. |
| src/v/pandaproxy/schema_registry/test/sanitize_avro.cc | Adds comprehensive tests covering top-level and nested primitive collapsing, equivalence between verbose/bare forms, and preservation of non-equivalent forms (logicalType, named refs, and metadata). |
Collaborator
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.
Redpanda Schema Registry did not treat Avro primitive object schemas like
{"type":"string"}as equivalent to the simple primitive form"string"when they appeared inside nested schemas. This caused schema lookup to
return
40403 Schema not foundwhen a stored schema used the verbose formbut the lookup payload used the equivalent simple form.
This PR collapses primitive object schemas to the simple form while walking
actual Avro schema values: record field types, array items, map values,
union branches, and top-level primitive schemas. Custom metadata that happens
to look like a primitive schema is left unchanged.
Fixes https://redpandadata.atlassian.net/browse/CORE-16246
Fixes https://redpandadata.atlassian.net/browse/CORE-16247
Backports Required
Release Notes
Bug Fixes
"string", and object form, such as{"type":"string"}.