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
impl SchemaStore
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty SchemaStore
using the default fingerprinting algorithm (64-bit Rabin).
Sourcepub fn new_with_type(fingerprint_algorithm: FingerprintAlgorithm) -> Self
pub fn new_with_type(fingerprint_algorithm: FingerprintAlgorithm) -> Self
Creates an empty SchemaStore
using the default fingerprinting algorithm (64-bit Rabin).
Sourcepub fn set(
&mut self,
fingerprint: Fingerprint,
schema: AvroSchema,
) -> Result<Fingerprint, ArrowError>
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 theFingerprint
of the schema to register.schema
- TheAvroSchema
to register.
§Returns
A Result
returning the provided Fingerprint
of the schema if successful,
or an ArrowError
on failure.
Sourcepub fn register(
&mut self,
schema: AvroSchema,
) -> Result<Fingerprint, ArrowError>
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
- TheAvroSchema
to register.
§Returns
A Result
containing the Fingerprint
of the schema if successful,
or an ArrowError
on failure.
Sourcepub fn lookup(&self, fingerprint: &Fingerprint) -> Option<&AvroSchema>
pub fn lookup(&self, fingerprint: &Fingerprint) -> Option<&AvroSchema>
Sourcepub fn fingerprints(&self) -> Vec<Fingerprint>
pub fn fingerprints(&self) -> Vec<Fingerprint>
Returns a Vec
containing all unique Fingerprint
s currently
held by this SchemaStore
.
The order of the returned fingerprints is unspecified and should not be relied upon.
Sourcepub(crate) fn fingerprint_algorithm(&self) -> FingerprintAlgorithm
pub(crate) fn fingerprint_algorithm(&self) -> FingerprintAlgorithm
Returns the FingerprintAlgorithm
used by the SchemaStore
for fingerprinting.
Trait Implementations§
Source§impl Clone for SchemaStore
impl Clone for SchemaStore
Source§fn clone(&self) -> SchemaStore
fn clone(&self) -> SchemaStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more