SchemaStore

结构体 SchemaStore 

源代码
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

源代码

pub fn new() -> Self

使用默认的指纹算法(64 位 Rabin)创建一个空的 SchemaStore

源代码

pub fn new_with_type(fingerprint_algorithm: FingerprintAlgorithm) -> Self

使用默认的指纹算法(64 位 Rabin)创建一个空的 SchemaStore

源代码

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

使用提供的指纹在存储中注册模式。注意:Confluent 线格式实现应该利用此方法。

使用提供的指纹在存储中设置模式。如果存储中不存在相同指纹的模式,则插入新模式。如果指纹已存在,则不会覆盖现有模式。

§参数
  • fingerprint - 要注册的模式的 Fingerprint 的引用。
  • schema - 要注册的 AvroSchema
§返回

一个 Result,如果成功,返回模式的提供的 Fingerprint,如果失败,返回 ArrowError

源代码

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

在存储中注册模式并返回其指纹。

使用存储配置的哈希类型为给定模式计算指纹。如果存储中不存在相同指纹的模式,则插入新模式。如果指纹已存在,则不会覆盖现有模式。如果 FingerprintAlgorithm 设置为 Id 或 Id64,此方法将返回错误。Confluent 线格式实现应改为利用 set 方法。

§参数
  • schema - 要注册的 AvroSchema
§返回

一个 Result,如果成功,包含模式的 Fingerprint,如果失败,返回 ArrowError

源代码

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

通过其 Fingerprint 查找模式。

§参数
  • fingerprint - 要查找的模式的 Fingerprint 的引用。
§返回

一个 Option,如果找到,包含 AvroSchema 的克隆,否则为 None

源代码

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

返回一个 Vec,包含此 SchemaStore 当前持有的所有唯一 Fingerprint

返回指纹的顺序未指定,不应依赖。

源代码

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

返回 SchemaStore 用于指纹识别的 FingerprintAlgorithm

Trait 实现§

源代码§

impl Clone for SchemaStore

源代码§

fn clone(&self) -> SchemaStore

返回值的副本。 阅读更多
1.0.0 · §

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

执行从 source 的复制赋值。 阅读更多
源代码§

impl Debug for SchemaStore

源代码§

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

使用给定的格式化程序格式化值。 阅读更多
源代码§

impl Default for SchemaStore

源代码§

fn default() -> SchemaStore

返回某个类型的“默认值”。阅读更多
源代码§

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

源代码§

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

从模式的 HashMap 创建 SchemaStore。HashMap 中的每个模式都在新存储中注册。

源代码§

type Error = ArrowError

转换错误时返回的类型。

自动 Trait 实现§

通用实现§

§

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

§

fn type_id(&self) -> TypeId

获取 selfTypeId阅读更多
§

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

§

fn borrow(&self) -> &T

从拥有的值进行不可变借用。 阅读更多
§

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

§

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

从拥有的值进行可变借用。 阅读更多
§

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

§

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

🔬这是一个仅限 nightly 的实验性 API。(clone_to_uninit
执行从 selfdest 的复制赋值。 阅读更多
§

impl<T> From<T> for T

§

fn from(t: T) -> T

返回未更改的参数。

§

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

§

fn into(self) -> U

调用 U::from(self)

也就是说,此转换是 From<T> for U 的实现选择执行的任何操作。

§

impl<T> Same for T

§

type Output = T

应该总是 Self
§

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

§

type Owned = T

获取所有权后的结果类型。
§

fn to_owned(&self) -> T

从借用的数据创建拥有的数据,通常通过克隆。 阅读更多
§

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

使用借用的数据替换拥有的数据,通常通过克隆。 阅读更多
§

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

§

type Error = Infallible

转换错误时返回的类型。
§

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

执行转换。
§

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

§

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

转换错误时返回的类型。
§

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

执行转换。
§

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,