vantage-vista 2.1.0

Universal, schema-bearing data handle for the Vantage data framework
Documentation
//! The refusal of a dotted path a shell can't evaluate.

use vantage_core::{VantageError, error};

use crate::metadata::VistaMetadata;

/// The refusal of a condition on a dotted column (`root.leaf`, or an
/// imported `author.name`) a shell can't evaluate: an `Unimplemented`
/// error naming the column. It is not an [`unsupported`](crate::unsupported)
/// refusal, since no capability describes paths.
pub(crate) fn refuse_path(column: &str) -> VantageError {
    error!("this shell doesn't evaluate a dotted path", column = column).mark_unimplemented()
}

/// The error for a condition on `column`, which the shell doesn't take as
/// one of its own columns.
///
/// - A dotted column the shell can't evaluate is refused as
///   `Unimplemented`, for the caller to evaluate: a path whose root
///   `metadata` declares, a dotted column `metadata` declares whole (an
///   imported `author.name`), or any dotted column when `metadata` declares
///   no columns. Being a refusal,
///   [`Vista::with_query`](crate::Vista::with_query) hands the clause back
///   as residual, for the caller to evaluate over the rows it reads with
///   [`Condition::matches`](crate::Condition::matches);
///   [`Vista::with_condition`](crate::Vista::with_condition) returns it as
///   an error.
/// - Anything else: a plain unknown-column error, so an unknown column is
///   never evaluated locally.
pub fn condition_column_error(metadata: &VistaMetadata, column: &str) -> VantageError {
    let columns = &metadata.columns;
    let nested = column.split_once('.').is_some_and(|(root, _)| {
        columns.is_empty() || columns.contains_key(column) || columns.contains_key(root)
    });
    if nested {
        refuse_path(column)
    } else {
        error!("Unknown column for condition", field = column)
    }
}