Skip to content

feat: Allow to supply own names when using Value::resolve and Value::Validate - #579

Merged
Kriskras99 merged 3 commits into
mainfrom
feat/value_supply_own_name
Jul 14, 2026
Merged

Kriskras99 merged 3 commits into
mainfrom
feat/value_supply_own_name

Conversation

@Kriskras99

Copy link
Copy Markdown
Contributor

I ended up using the suggestion from @flxo instead of my own suggestion as it is not clear from a ResolvedSchema which schema needs to be resolved against.

This also optimizes Value::resolve_internal to take an Option<&JsonValue> instead of an &Option<JsonValue> which saves a memory load on every function call.

Closes #574

@flxo flxo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Thanks for the addition - this is really valuable for higher throughputs.

Comment thread avro/src/types.rs Resolved
Comment thread avro/src/types.rs
/// resolution.
/// in the Avro specification for the full set of rules of schema resolution.
pub fn resolve_schemata(self, schema: &Schema, schemata: Vec<&Schema>) -> AvroResult<Self> {
let enclosing_namespace = schema.namespace();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no enclosing namespace for schema. Either schema has it's own namespace (in which resolve_internal will use that) or schema has no namespace in which case this is None. So it is useless to set it here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not understand.
The idea of enclosing_namespace is to provide the namespace to any (grand)children schemas which do not have their own "namespace" attribute.
If we pass None to

enclosing_namespace: NamespaceRef,
then resolve_record() at
self.resolve_record(fields, names, enclosing_namespace)
will not know the namespace of the closest parent with a namespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only schemas for which schema.namespace() will return a namespace are:

  • Schema::Ref
  • Schema::Record
  • Schema::Enum
  • Schema::Fixed
  • Schema::Decimal(Fixed)
  • Schema::Uuid(Fixed)
  • Schema::Duration

resolve_internal will only use the enclosing_namespace parameter in the following situations:

  • schema == Schema::Ref to get the fqn of the reference. But if the reference has a namespace that will be used for the fqn
  • schema == Schema::Union, but directly from resolve_schemata the enclosing namespace will not exist
  • schema == Schema::Array, same as union
  • schema == Schema::Map, same as union
  • schema == Schema::Record, it should use the namespace from the record first but I see now that it doesn't.

I've updated the Schema::Record branch to use the namespace from the record first then the enclosing namespace if it does not have one.

@martin-g martin-g added this to the 0.22.0 milestone Jul 10, 2026
@Kriskras99
Kriskras99 force-pushed the feat/value_supply_own_name branch from 2362ee1 to 0d44d25 Compare July 14, 2026 10:29
Comment thread avro/src/types.rs Resolved
@Kriskras99
Kriskras99 merged commit 8155d08 into main Jul 14, 2026
16 checks passed
@Kriskras99
Kriskras99 deleted the feat/value_supply_own_name branch July 14, 2026 11:16
@Kriskras99 Kriskras99 mentioned this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Reuse a pre-built ResolvedSchema in Value resolution

3 participants