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