Skip to main content

uqa_sql/expr/
mod.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Scalar expression evaluator: turns an [`Expr`] into a [`Value`] under
8//! a row context (column -> value) and a parameter binding.
9
10use uqa_core::{ArrayValue, DecimalValue, TemporalValue, Value};
11
12use crate::ast::{BinaryOp, Expr};
13#[cfg(test)]
14use crate::ast::{ColumnType, FunctionBinding, FunctionDispatch};
15use crate::error::{Result, SQLError};
16use crate::params::SQLParam;
17#[cfg(test)]
18use crate::result::ResultRow;
19
20mod array_transform;
21mod encoding;
22mod json;
23mod json_strip;
24mod random;
25mod range;
26mod time;
27mod uuid;
28
29pub use array_transform::argument_positions as array_transform_argument_positions;
30use encoding::{base64_decode, base64_encode, md5_hex};
31pub use json::value_to_json_text;
32use json::{
33    format_jsonb_pretty, json_build_array_value, json_build_object_value, json_concat,
34    json_contained_by, json_contains, json_delete, json_delete_path, json_extract_path,
35    json_has_key, json_has_keys, json_typeof, jsonb_insert, jsonb_set, jsonpath_exists,
36    jsonpath_match, parse_json, strip_nulls, typed_json_value, value_to_json,
37};
38pub use json_strip::argument_positions as json_strip_nulls_argument_positions;
39use json_strip::strip_json_nulls_text;
40pub use range::{
41    multirange_from_ranges, parse_multirange, parse_range, CanonicalMultirange, CanonicalRange,
42};
43use time::{
44    age_between, coerce_temporal, date_trunc_value, extract_from_value, format_pg_number,
45    format_temporal, hex_encode, make_timestamp, parse_timestamp, pg_to_chrono_fmt,
46};
47pub use uuid::parse_uuid_bytes;
48use uuid::{extract_uuid_timestamp, extract_uuid_version, generate_random_uuid, generate_uuid_v7};
49mod binary;
50mod casting;
51mod conversion;
52mod scalar_array;
53mod scalar_core;
54mod scalar_dispatch;
55mod scalar_geospatial;
56mod scalar_helpers;
57mod scalar_json;
58mod scalar_math;
59mod scalar_postgres;
60mod scalar_range;
61mod scalar_temporal;
62
63use binary::{compare, eval_comparison_op, values_equal};
64pub(crate) use binary::{division_by_zero, out_of_range};
65pub use binary::{
66    eval_binary_values, eval_binary_values_with_integer_width, eval_comparison_truth,
67    integer_width_for_literal, integer_width_for_type, truthy, IntegerWidth,
68};
69pub use casting::{
70    array_dimensions, cast_value, cast_value_from, negate_value, parse_pg_array_literal,
71};
72pub(crate) use conversion::to_f64;
73use conversion::{
74    allocation_error, coerce_i64, expect_str, float1, float_to_i64_rounded, float_to_i64_trunc,
75    gcd_i64, initcap_str, nonnegative_usize, string1, to_decimal, to_i64,
76};
77pub use conversion::{array_value_to_string, value_to_string, vector_value_to_string};
78pub use conversion::{value_to_tensor, value_to_vector};
79#[cfg(test)]
80use scalar_dispatch::eval_scalar_function;
81use scalar_helpers::{
82    compile_pg_regex, point_xy, quote_literal, similar_to_regex, trim_chars, typeof_value,
83};
84pub use scalar_helpers::{quote_ident, CompiledLikePattern};
85
86mod builtin;
87mod call_arguments;
88mod call_dispatch;
89mod context;
90mod diagnostics;
91mod evaluator;
92
93pub use builtin::{
94    bound_scalar_function_strictness, builtin_scalar_function_strictness,
95    eval_bound_builtin_function_call,
96};
97pub use call_arguments::{
98    call_argument_value, evaluate_call_args, validate_named_argument_order,
99    variadic_argument_value, wrap_variadic_argument,
100};
101pub use call_dispatch::{eval_builtin_function_call, eval_function_call};
102pub use context::{
103    cast_value_with_type_resolution, coercion_type_name, format_regtype_value, EngineHook,
104    EvalContext, RowLookup,
105};
106pub use diagnostics::{unknown_function_error, value_type_name};
107pub use evaluator::eval;
108use evaluator::eval_between;
109
110#[cfg(test)]
111mod tests;