Skip to main content

lance_core/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright The Lance Authors
3#![cfg_attr(coverage, feature(coverage_attribute))]
4
5// Allow the derive macro to reference `lance_core::deepsize` from within this crate.
6extern crate self as lance_core;
7
8use arrow_schema::{DataType, Field as ArrowField};
9use std::sync::LazyLock;
10
11pub mod cache;
12pub mod container;
13pub mod datatypes;
14pub mod deepsize;
15pub mod error;
16pub mod levenshtein;
17pub mod traits;
18pub mod utils;
19
20pub use error::{ArrowResult, Error, Result, box_error};
21
22/// Wildcard to indicate all non-system columns
23pub const WILDCARD: &str = "*";
24/// Column name for the meta row ID.
25pub const ROW_ID: &str = "_rowid";
26/// Column name for the meta row address.
27pub const ROW_ADDR: &str = "_rowaddr";
28/// Column name for the meta row offset.
29pub const ROW_OFFSET: &str = "_rowoffset";
30/// Column name for the row's last updated at dataset version.
31pub const ROW_LAST_UPDATED_AT_VERSION: &str = "_row_last_updated_at_version";
32/// Column name for the row's created at dataset version.
33pub const ROW_CREATED_AT_VERSION: &str = "_row_created_at_version";
34
35/// Row ID field. This is nullable because its validity bitmap is sometimes used
36/// as a selection vector.
37pub static ROW_ID_FIELD: LazyLock<ArrowField> =
38    LazyLock::new(|| ArrowField::new(ROW_ID, DataType::UInt64, true));
39/// Row address field. This is nullable because its validity bitmap is sometimes used
40/// as a selection vector.
41pub static ROW_ADDR_FIELD: LazyLock<ArrowField> =
42    LazyLock::new(|| ArrowField::new(ROW_ADDR, DataType::UInt64, true));
43/// Row offset field. This is nullable merely for compatibility with the other
44/// fields.
45pub static ROW_OFFSET_FIELD: LazyLock<ArrowField> =
46    LazyLock::new(|| ArrowField::new(ROW_OFFSET, DataType::UInt64, true));
47/// Row last updated at version field.
48pub static ROW_LAST_UPDATED_AT_VERSION_FIELD: LazyLock<ArrowField> =
49    LazyLock::new(|| ArrowField::new(ROW_LAST_UPDATED_AT_VERSION, DataType::UInt64, true));
50/// Row created at version field.
51pub static ROW_CREATED_AT_VERSION_FIELD: LazyLock<ArrowField> =
52    LazyLock::new(|| ArrowField::new(ROW_CREATED_AT_VERSION, DataType::UInt64, true));
53
54/// Check if a column name is a system column.
55///
56/// System columns are virtual columns that are computed at read time and don't
57/// exist in the physical data files. They include:
58/// - `_rowid`: The row ID
59/// - `_rowaddr`: The row address
60/// - `_rowoffset`: The row offset
61/// - `_row_last_updated_at_version`: The version when the row was last updated
62/// - `_row_created_at_version`: The version when the row was created
63pub fn is_system_column(column_name: &str) -> bool {
64    matches!(
65        column_name,
66        ROW_ID | ROW_ADDR | ROW_OFFSET | ROW_LAST_UPDATED_AT_VERSION | ROW_CREATED_AT_VERSION
67    )
68}