pub struct SchemaStore {
fingerprint_algorithm: FingerprintAlgorithm,
schemas: HashMap<Fingerprint, AvroSchema>,
}展开描述
一个 Avro 模式的内存缓存,通过指纹索引。
SchemaStore 提供了一种有效存储和检索 Avro 模式的机制。每个模式都与一个唯一的 Fingerprint 相关联,该指纹是根据模式的规范形式和特定的哈希算法生成的。
SchemaStore 实例配置为对其所有操作使用单一的 FingerprintAlgorithm,例如 Rabin、MD5(暂不支持)或 SHA256(暂不支持)。这确保了在生成指纹和查找模式时的一致性。所有注册的模式都将使用此算法计算其指纹,并且查找必须使用匹配的指纹。
§示例
// 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));字段§
§fingerprint_algorithm: FingerprintAlgorithm用于生成指纹的哈希算法。
schemas: HashMap<Fingerprint, AvroSchema>从模式指纹到模式本身的映射。
实现§
源代码§impl SchemaStore
impl SchemaStore
源代码pub fn new_with_type(fingerprint_algorithm: FingerprintAlgorithm) -> Self
pub fn new_with_type(fingerprint_algorithm: FingerprintAlgorithm) -> Self
使用默认的指纹算法(64 位 Rabin)创建一个空的 SchemaStore。
源代码pub fn set( &mut self, fingerprint: Fingerprint, schema: AvroSchema, ) -> Result<Fingerprint, ArrowError>
pub fn set( &mut self, fingerprint: Fingerprint, schema: AvroSchema, ) -> Result<Fingerprint, ArrowError>
源代码pub fn register( &mut self, schema: AvroSchema, ) -> Result<Fingerprint, ArrowError>
pub fn register( &mut self, schema: AvroSchema, ) -> Result<Fingerprint, ArrowError>
源代码pub fn lookup(&self, fingerprint: &Fingerprint) -> Option<&AvroSchema>
pub fn lookup(&self, fingerprint: &Fingerprint) -> Option<&AvroSchema>
源代码pub fn fingerprints(&self) -> Vec<Fingerprint>
pub fn fingerprints(&self) -> Vec<Fingerprint>
返回一个 Vec,包含此 SchemaStore 当前持有的所有唯一 Fingerprint。
返回指纹的顺序未指定,不应依赖。
源代码pub(crate) fn fingerprint_algorithm(&self) -> FingerprintAlgorithm
pub(crate) fn fingerprint_algorithm(&self) -> FingerprintAlgorithm
返回 SchemaStore 用于指纹识别的 FingerprintAlgorithm。
Trait 实现§
源代码§impl Clone for SchemaStore
impl Clone for SchemaStore
源代码§fn clone(&self) -> SchemaStore
fn clone(&self) -> SchemaStore
返回值的副本。 阅读更多
1.0.0 · 源§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
执行从
source 的复制赋值。 阅读更多源代码§impl Debug for SchemaStore
impl Debug for SchemaStore
源代码§impl Default for SchemaStore
impl Default for SchemaStore
源代码§fn default() -> SchemaStore
fn default() -> SchemaStore
返回某个类型的“默认值”。阅读更多