lance_io/
encodings.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright The Lance Authors
3
4//! Data encodings
5//!
6
7use arrow_array::{Array, ArrayRef, UInt32Array};
8use async_trait::async_trait;
9
10pub mod binary;
11pub mod dictionary;
12pub mod plain;
13
14use crate::ReadBatchParams;
15use lance_core::Result;
16
17/// Encoder - Write an arrow array to the file.
18#[async_trait]
19pub trait Encoder {
20    /// Write an slice of Arrays, and returns the file offset of the beginning of the batch.
21    async fn encode(&mut self, array: &[&dyn Array]) -> Result<usize>;
22}
23
24/// Decoder - Read Arrow Data.
25#[async_trait]
26pub trait Decoder: Send + AsyncIndex<ReadBatchParams> {
27    async fn decode(&self) -> Result<ArrayRef>;
28
29    /// Take by indices.
30    async fn take(&self, indices: &UInt32Array) -> Result<ArrayRef>;
31}
32
33#[async_trait]
34pub trait AsyncIndex<IndexType> {
35    type Output: Send + Sync;
36
37    async fn get(&self, index: IndexType) -> Self::Output;
38}