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 floating;
23mod json;
24mod json_strip;
25mod random;
26mod range;
27mod time;
28mod uuid;
29
30pub use array_transform::argument_positions as array_transform_argument_positions;
31use encoding::{base64_decode, base64_encode, md5_hex};
32pub use json::value_to_json_text;
33use json::{
34    format_jsonb_pretty, json_build_array_value, json_build_object_value, json_concat,
35    json_contained_by, json_contains, json_delete, json_delete_path, json_extract_path,
36    json_has_key, json_has_keys, json_typeof, jsonb_insert, jsonb_set, jsonpath_exists,
37    jsonpath_match, parse_json, strip_nulls, typed_json_value, value_to_json,
38};
39pub use json_strip::argument_positions as json_strip_nulls_argument_positions;
40use json_strip::strip_json_nulls_text;
41pub use range::{
42    multirange_from_ranges, parse_multirange, parse_range, CanonicalMultirange, CanonicalRange,
43};
44use time::{
45    age_between, coerce_temporal, date_trunc_value, extract_from_value, format_pg_number,
46    format_temporal, hex_encode, make_timestamp, parse_timestamp, pg_to_chrono_fmt,
47};
48pub use uuid::parse_uuid_bytes;
49use uuid::{extract_uuid_timestamp, extract_uuid_version, generate_random_uuid, generate_uuid_v7};
50mod binary;
51mod casting;
52mod conversion;
53mod current_time;
54mod scalar_array;
55mod scalar_core;
56mod scalar_dispatch;
57mod scalar_geospatial;
58mod scalar_helpers;
59mod scalar_json;
60mod scalar_math;
61mod scalar_postgres;
62mod scalar_range;
63mod scalar_temporal;
64
65use binary::{compare, eval_comparison_op, values_equal};
66pub(crate) use binary::{division_by_zero, out_of_range};
67pub use binary::{
68    eval_binary_values, eval_binary_values_with_integer_width, eval_comparison_truth,
69    integer_width_for_literal, integer_width_for_type, truthy, IntegerWidth,
70};
71pub use casting::{
72    array_dimensions, cast_value, cast_value_from, negate_value, parse_pg_array_literal,
73};
74pub(crate) use conversion::to_f64;
75use conversion::{
76    allocation_error, coerce_i64, expect_str, float1, float_to_i64_rounded, float_to_i64_trunc,
77    gcd_i64, initcap_str, nonnegative_usize, string1, to_decimal, to_i64,
78};
79pub use conversion::{array_value_to_string, value_to_string, vector_value_to_string};
80pub use conversion::{value_to_tensor, value_to_vector};
81pub use current_time::clock_timestamp_micros;
82pub use floating::{eval_float_arithmetic, format_real, FloatWidth};
83#[cfg(test)]
84use scalar_dispatch::eval_scalar_function;
85use scalar_helpers::{
86    compile_pg_regex, point_xy, quote_literal, similar_to_regex, trim_chars, typeof_value,
87};
88pub use scalar_helpers::{quote_ident, CompiledLikePattern};
89
90mod builtin;
91mod call_arguments;
92mod call_dispatch;
93mod context;
94mod diagnostics;
95mod evaluator;
96
97pub use builtin::{
98    bound_scalar_function_strictness, builtin_scalar_function_strictness,
99    eval_bound_builtin_function_call,
100};
101pub use call_arguments::{
102    call_argument_value, evaluate_call_args, validate_named_argument_order,
103    variadic_argument_value, wrap_variadic_argument,
104};
105pub use call_dispatch::{eval_builtin_function_call, eval_function_call};
106pub use context::{
107    cast_value_with_type_resolution, coercion_type_name, format_regtype_value, EngineHook,
108    EvalContext, RowLookup,
109};
110pub use diagnostics::{unknown_function_error, value_type_name};
111pub use evaluator::eval;
112use evaluator::eval_between;
113
114#[cfg(test)]
115mod tests;
116
117mod json_carrier;
118pub use json_carrier::{core_value_to_json, value_to_text};