SchemaStore

Struct SchemaStore 

Source
pub struct SchemaStore {
    fingerprint_algorithm: FingerprintAlgorithm,
    schemas: HashMap<Fingerprint, AvroSchema>,
}
Expand description

An in-memory cache of Avro schemas, indexed by their fingerprint.

SchemaStore provides a mechanism to store and retrieve Avro schemas efficiently. Each schema is associated with a unique Fingerprint, which is generated based on the schema’s canonical form and a specific hashing algorithm.

A SchemaStore instance is configured to use a single FingerprintAlgorithm such as Rabin, MD5 (not yet supported), or SHA256 (not yet supported) for all its operations. This ensures consistency when generating fingerprints and looking up schemas. All schemas registered will have their fingerprint computed with this algorithm, and lookups must use a matching fingerprint.

§Examples

// Create a new store with the default Rabin fingerprinting.
use arrow_avro::schema::{AvroSchema, SchemaStore};

let mut store = SchemaStore::new();
let schema = AvroSchema::new("\"string\"".to_string());
// Register the schema to get its fingerprint.
let fingerprint = store.register(schema.clone()).unwrap();
// Use the fingerprint to look up the schema.
let retrieved_schema = store.lookup(&fingerprint).cloned();
assert_eq!(retrieved_schema, Some(schema));

Fields§

§fingerprint_algorithm: FingerprintAlgorithm

The hashing algorithm used for generating fingerprints.

§schemas: HashMap<Fingerprint, AvroSchema>

A map from a schema’s fingerprint to the schema itself.

Implementations§

Source§

impl SchemaStore

Source

pub fn new() -> Self

Creates an empty SchemaStore using the default fingerprinting algorithm (64-bit Rabin).

Source

pub fn new_with_type(fingerprint_algorithm: FingerprintAlgorithm) -> Self

Creates an empty SchemaStore using the default fingerprinting algorithm (64-bit Rabin).

Source

pub fn set( &mut self, fingerprint: Fingerprint, schema: AvroSchema, ) -> Result<Fingerprint, ArrowError>

Registers a schema with the store and the provided fingerprint. Note: Confluent wire format implementations should leverage this method.

A schema is set in the store, using the provided fingerprint. If a schema with the same fingerprint does not already exist in the store, the new schema is inserted. If the fingerprint already exists, the existing schema is not overwritten.

§Arguments
  • fingerprint - A reference to the Fingerprint of the schema to register.
  • schema - The AvroSchema to register.
§Returns

A Result returning the provided Fingerprint of the schema if successful, or an ArrowError on failure.

Source

pub fn register( &mut self, schema: AvroSchema, ) -> Result<Fingerprint, ArrowError>

Registers a schema with the store and returns its fingerprint.

A fingerprint is calculated for the given schema using the store’s configured hash type. If a schema with the same fingerprint does not already exist in the store, the new schema is inserted. If the fingerprint already exists, the existing schema is not overwritten. If FingerprintAlgorithm is set to None, this method will return an error. Confluent wire format implementations should leverage the set method instead.

§Arguments
  • schema - The AvroSchema to register.
§Returns

A Result containing the Fingerprint of the schema if successful, or an ArrowError on failure.

Source

pub fn lookup(&self, fingerprint: &Fingerprint) -> Option<&AvroSchema>

Looks up a schema by its Fingerprint.

§Arguments
  • fingerprint - A reference to the Fingerprint of the schema to look up.
§Returns

An Option containing a clone of the AvroSchema if found, otherwise None.

Source

pub fn fingerprints(&self) -> Vec<Fingerprint>

Returns a Vec containing all unique Fingerprints currently held by this SchemaStore.

The order of the returned fingerprints is unspecified and should not be relied upon.

Source

pub(crate) fn fingerprint_algorithm(&self) -> FingerprintAlgorithm

Returns the FingerprintAlgorithm used by the SchemaStore for fingerprinting.

Trait Implementations§

Source§

impl Clone for SchemaStore

Source§

fn clone(&self) -> SchemaStore

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SchemaStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SchemaStore

Source§

fn default() -> SchemaStore

Returns the “default value” for a type. Read more
Source§

impl TryFrom<HashMap<Fingerprint, AvroSchema>> for SchemaStore

Source§

fn try_from( schemas: HashMap<Fingerprint, AvroSchema>, ) -> Result<Self, Self::Error>

Creates a SchemaStore from a HashMap of schemas. Each schema in the HashMap is registered with the new store.

Source§

type Error = ArrowError

The type returned in the event of a conversion error.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,