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