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