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 regex;
28mod time;
29mod uuid;
30
31pub use array_transform::{
32    argument_positions as array_transform_argument_positions,
33    argument_positions_with_control as array_transform_argument_positions_with_control,
34};
35pub use json::{validate_json_object_key_type, value_to_json_text};
36pub use json_strip::argument_positions as json_strip_nulls_argument_positions;
37pub use range::{
38    multirange_from_ranges, parse_multirange, parse_range, CanonicalMultirange, CanonicalRange,
39};
40use time::{
41    age_between, coerce_temporal, format_pg_number, format_temporal, hex_encode, make_timestamp,
42    parse_timestamp, pg_to_chrono_fmt,
43};
44pub use uuid::parse_uuid_bytes;
45use uuid::{generate_random_uuid, generate_uuid_v7};
46mod binary;
47mod casting;
48mod conversion;
49mod current_time;
50mod scalar_array;
51mod scalar_core;
52mod scalar_dispatch;
53mod scalar_geospatial;
54mod scalar_helpers;
55mod scalar_json;
56mod scalar_math;
57mod scalar_postgres;
58mod scalar_range;
59mod scalar_temporal;
60mod session_settings;
61
62#[cfg(test)]
63use binary::eval_comparison_op;
64pub use binary::{
65    compare_nullable_with_control, compare_typed_values_with_control, compare_with_control,
66    eval_binary_values, eval_binary_values_with_control, eval_binary_values_with_integer_width,
67    eval_binary_values_with_integer_width_with_control, eval_comparison_truth,
68    eval_comparison_truth_with_control, integer_width_for_literal, integer_width_for_type, truthy,
69    type_comparison_can_fail, validate_legacy_vector_comparison, value_comparison_can_fail,
70    values_equal_nullable_with_control, values_equal_with_control, IntegerWidth,
71};
72pub(crate) use binary::{division_by_zero, out_of_range};
73pub use casting::{
74    array_dimensions, cast_value, cast_value_from, cast_value_from_with_control, negate_value,
75    negate_value_with_control, parse_pg_array_literal, parse_pg_array_literal_with_control,
76};
77use conversion::{
78    allocation_error, coerce_i64, float_to_i64_rounded, float_to_i64_trunc, nonnegative_usize,
79    to_decimal, to_i64,
80};
81pub use conversion::{
82    array_value_to_string, value_to_string, value_to_string_with_control, vector_value_to_string,
83};
84pub(crate) use conversion::{tensor_items, vector_element, vector_items};
85pub use conversion::{
86    value_to_tensor, value_to_tensor_with_control, value_to_vector, value_to_vector_with_control,
87};
88pub use current_time::clock_timestamp_micros;
89pub use floating::{
90    eval_float_arithmetic, eval_float_arithmetic_with_control, format_real, FloatWidth,
91};
92#[cfg(test)]
93use scalar_dispatch::eval_scalar_function;
94use scalar_helpers::{point_xy, typeof_value};
95pub use scalar_helpers::{quote_ident, CompiledLikePattern};
96
97mod builtin;
98mod call_arguments;
99mod call_dispatch;
100mod context;
101mod diagnostics;
102mod evaluator;
103
104pub use builtin::{
105    bound_scalar_function_strictness, builtin_scalar_function_strictness,
106    eval_bound_builtin_function_call,
107};
108pub use call_arguments::{
109    call_argument_value, evaluate_call_args, validate_named_argument_order,
110    validate_named_argument_order_with_control, variadic_argument_value, wrap_variadic_argument,
111};
112pub use call_dispatch::{
113    eval_builtin_function_call, eval_function_call, eval_generated_function_call_with_control,
114};
115pub use context::{
116    cast_value_with_type_resolution, cast_value_with_type_resolution_with_control,
117    coercion_type_name, format_regtype_value, format_regtype_value_with_control, EngineHook,
118    EvalContext, RowLookup,
119};
120pub use diagnostics::{unknown_function_error, value_type_name};
121pub use evaluator::eval;
122mod numeric_operator;
123use evaluator::eval_between_with_control;
124pub use numeric_operator::{eval_numeric_operator, eval_numeric_operator_with_control};
125
126#[cfg(test)]
127mod tests;
128
129mod json_carrier;
130pub use json_carrier::{core_value_to_json, value_to_text, value_to_text_with_control};