lance_core/
lib.rs

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