lance_table/
format.rs

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