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