icydb-core 0.144.10

IcyDB — A schema-first typed query engine and persistence runtime for Internet Computer canisters
Documentation
//! Module: predicate
//! Responsibility: predicate AST, normalization, validation, and runtime semantics.
//! Does not own: query routing, index key encoding, or executor commit behavior.
//! Boundary: query/executor/index consume this as predicate authority.

mod capability;
mod coercion;
mod encoding;
mod fingerprint;
mod membership;
mod model;
mod normalize;
mod parser;
mod resolved;
mod row_policy;
mod runtime;
mod semantics;
mod simplify;
#[cfg(test)]
mod tests;

use crate::{
    db::{
        query::predicate::{reject_unsupported_query_features, validate_predicate},
        schema::SchemaInfo,
    },
    model::field::FieldModel,
};

pub use coercion::CoercionId;
pub use model::{
    CompareFieldsPredicate, CompareOp, ComparePredicate, Predicate, UnsupportedQueryFeature,
};
pub use row_policy::MissingRowPolicy;

pub(in crate::db) use capability::{
    IndexCompileTarget, IndexPredicateCapability, PredicateCapabilityContext,
    PredicateCapabilityProfile, ScalarPredicateCapability, classify_index_compare_component,
    classify_index_compare_target, classify_predicate_capabilities,
    classify_predicate_capabilities_for_targets, lower_index_compare_literal_for_target,
    lower_index_starts_with_prefix_for_target,
};
pub(crate) use coercion::CoercionSpec;
pub(in crate::db) use coercion::supports_coercion;
pub(in crate::db) use normalize::{normalize, normalize_enum_literals};
pub(crate) use parser::parse_sql_predicate;

#[cfg(test)]
pub(in crate::db) use fingerprint::predicate_fingerprint;
pub(in crate::db) use fingerprint::{hash_predicate, predicate_fingerprint_normalized};
pub(in crate::db) use membership::{MembershipCompareLeaf, collapse_membership_compare_leaves};
pub(in crate::db) use resolved::{
    ExecutableCompareOperand, ExecutableComparePredicate, ExecutablePredicate,
};
pub(in crate::db) use runtime::PredicateProgram;
pub(in crate::db) use semantics::{TextOp, canonical_cmp, compare_eq, compare_order, compare_text};
pub(in crate::db::predicate) use semantics::{
    casefold_text, eval_equality_compare_result, eval_list_membership_compare_result,
    eval_ordered_compare_result,
};

/// Parse one generated filtered-index predicate at macro/build time.
#[doc(hidden)]
pub fn parse_generated_index_predicate_sql(predicate_sql: &str) -> Result<Predicate, String> {
    parse_sql_predicate(predicate_sql).map_err(|error| error.to_string())
}

/// Validate one generated filtered-index predicate against trusted field metadata.
#[doc(hidden)]
pub fn validate_generated_index_predicate_fields(
    fields: &[FieldModel],
    predicate: &Predicate,
) -> Result<(), String> {
    let schema = SchemaInfo::from_field_models(fields);
    reject_unsupported_query_features(predicate).map_err(|error| error.to_string())?;
    validate_predicate(&schema, predicate).map_err(|error| error.to_string())
}