Skip to main content

lance_table/
format.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright The Lance Authors
3
4use arrow_buffer::ToByteSlice;
5use uuid::Uuid;
6
7mod fragment;
8mod index;
9mod manifest;
10mod transaction;
11
12pub use crate::rowids::version::{
13    RowDatasetVersionMeta, RowDatasetVersionRun, RowDatasetVersionSequence,
14};
15pub use fragment::*;
16pub use index::IndexMetadata;
17
18pub use manifest::{
19    BasePath, DETACHED_VERSION_MASK, DataStorageFormat, Manifest, SelfDescribingFileReader,
20    WriterVersion, is_detached_version,
21};
22pub use transaction::Transaction;
23
24use lance_core::{Error, Result};
25
26// In 0.36.1 we renamed Index to IndexMetadata because Index conflicted too much with the
27// Index trait.  This is left in for backward compatibility.
28#[deprecated(since = "0.36.1", note = "Use IndexMetadata instead")]
29pub type Index = IndexMetadata;
30
31/// Protobuf definitions for Lance Format
32pub mod pb {
33    #![allow(clippy::all)]
34    #![allow(non_upper_case_globals)]
35    #![allow(non_camel_case_types)]
36    #![allow(non_snake_case)]
37    #![allow(unused)]
38    #![allow(improper_ctypes)]
39    #![allow(clippy::upper_case_acronyms)]
40    #![allow(clippy::use_self)]
41    include!(concat!(env!("OUT_DIR"), "/lance.table.rs"));
42}
43
44/// These version/magic values are written at the end of manifest files (e.g. versions/1.version)
45pub const MAJOR_VERSION: i16 = 0;
46pub const MINOR_VERSION: i16 = 1;
47pub const MAGIC: &[u8; 4] = b"LANC";
48
49impl TryFrom<&pb::Uuid> for Uuid {
50    type Error = Error;
51
52    fn try_from(p: &pb::Uuid) -> Result<Self> {
53        if p.uuid.len() != 16 {
54            return Err(Error::invalid_input(
55                "Protobuf UUID is malformed".to_string(),
56            ));
57        }
58        let mut buf: [u8; 16] = [0; 16];
59        buf.copy_from_slice(p.uuid.to_byte_slice());
60        Ok(Self::from_bytes(buf))
61    }
62}
63
64impl From<&Uuid> for pb::Uuid {
65    fn from(value: &Uuid) -> Self {
66        Self {
67            uuid: value.into_bytes().to_vec(),
68        }
69    }
70}