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_access;
21pub use array_access::eval_array_access_with_control;
22mod array_transform;
23pub mod bit_string;
24pub mod datums;
25mod encoding;
26mod floating;
27mod in_range;
28pub(crate) mod integer_input;
29mod json;
30mod json_strip;
31mod random;
32mod range;
33pub(crate) use range::datum as range_datum;
34mod regex;
35pub use regex::{check_constant_similar_translation, RegexMatches, RegexSplit};
36mod time;
37mod uuid;
38
39pub use array_transform::{
40    argument_positions as array_transform_argument_positions,
41    argument_positions_with_control as array_transform_argument_positions_with_control,
42};
43pub(crate) use json::{decode_jsonb_datum_with_control, encode_jsonb_datum};
44pub use json::{validate_json_object_key_type, value_to_json_text};
45pub use json_strip::argument_positions as json_strip_nulls_argument_positions;
46pub use range::{
47    declared_multirange_datum_with_control, declared_range_datum_with_control,
48    multirange_from_ranges, multirange_from_ranges_with_operations, parse_multirange,
49    parse_multirange_with_operations, parse_range, parse_range_with_operations, range_bound_flags,
50    range_from_bounds_with_operations, CanonicalMultirange, CanonicalRange, RangeComparisonValue,
51    RangeConstruction, RangeValueDescriptor,
52};
53pub use time::IntervalFields;
54use time::{
55    age_between, coerce_temporal, format_pg_number, format_temporal, hex_encode, make_timestamp,
56    parse_timestamp, pg_to_chrono_fmt,
57};
58pub(crate) use uuid::format_uuid;
59use uuid::generate_random_uuid;
60pub use uuid::parse_uuid_bytes;
61mod binary;
62mod casting;
63mod collation;
64pub use collation::compare_unicode_with_control;
65mod collation_for;
66pub mod composites;
67mod concatenation;
68mod conversion;
69mod current_time;
70pub mod enums;
71pub(crate) mod hashing;
72pub(crate) mod internal_char;
73pub(crate) mod interval_style;
74mod pattern;
75mod scalar_array;
76mod scalar_core;
77pub(crate) use scalar_core::binds_input_collation_by_name;
78mod scalar_dispatch;
79mod scalar_geospatial;
80mod scalar_helpers;
81mod scalar_json;
82mod scalar_math;
83mod scalar_postgres;
84pub use scalar_postgres::eval_distinct_boolean;
85mod scalar_range;
86mod scalar_temporal;
87mod session_settings;
88mod session_sleep;
89mod statement_cancellation;
90mod temporal_input;
91mod value_catalog;
92pub mod variadic_any;
93pub use value_catalog::{EngineValueCatalog, SQLRecordFields, SQLValueCatalog};
94
95#[cfg(test)]
96use binary::eval_comparison_op;
97pub use binary::{
98    compare_btree_inputs_with_catalog_and_control, compare_btree_inputs_with_invocation_state,
99    compare_grouping_values_with_enum_catalog, compare_nullable_with_control,
100    compare_record_images_with_catalog, compare_selected_grouping_values_with_catalog,
101    compare_selected_values_with_catalog, compare_typed_values_with_catalog_and_collation,
102    compare_typed_values_with_control, compare_typed_values_with_enum_catalog,
103    compare_with_control, equal_selected_values_with_catalog,
104    equal_typed_values_with_catalog_and_collation, equal_typed_values_with_enum_catalog,
105    eval_binary_values, eval_binary_values_with_control, eval_binary_values_with_engine,
106    eval_binary_values_with_integer_width, eval_binary_values_with_integer_width_with_control,
107    eval_comparison_truth, eval_comparison_truth_with_control,
108    eval_comparison_truth_with_deferred_state, eval_comparison_truth_with_engine,
109    eval_comparison_truth_with_enum_catalog, eval_record_comparison_truth_with_engine,
110    eval_value_comparison_truth_with_engine, integer_width_for_literal, integer_width_for_type,
111    truthy, type_comparison_can_fail, validate_legacy_vector_comparison, value_comparison_can_fail,
112    values_equal_nullable_with_control, values_equal_with_control,
113    visit_record_image_fields_with_catalog, with_btree_input, BTreeInput, IntegerWidth,
114};
115pub(crate) use binary::{datetime_out_of_range, division_by_zero, out_of_range};
116pub use casting::{
117    array_dimensions, cast_value, cast_value_from, cast_value_from_with_control,
118    invalid_boolean_input, negate_value, negate_value_with_control, parse_boolean_input,
119    parse_pg_array_literal, parse_pg_array_literal_with_control,
120};
121use conversion::{
122    allocation_error, float_to_i64_rounded, float_to_i64_trunc, nonnegative_usize, to_decimal,
123    to_i64,
124};
125pub use conversion::{
126    array_value_to_string, catalog_output_required, invalid_numeric_input, value_to_string,
127    value_to_string_with_control, vector_value_to_string,
128};
129pub(crate) use conversion::{
130    bytea_to_string_with_control, tensor_items, vector_element, vector_items,
131    vector_value_to_string_with_control,
132};
133pub use conversion::{
134    value_to_tensor, value_to_tensor_with_control, value_to_vector, value_to_vector_with_control,
135};
136pub(crate) use current_time::transaction_timestamp_or_clock;
137pub use current_time::{clock_timestamp_micros, transaction_clock_micros, TransactionClockScope};
138pub(crate) use floating::format_real_with_control;
139pub use floating::{
140    eval_float_arithmetic, eval_float_arithmetic_with_control, format_real, FloatWidth,
141};
142pub use in_range::{in_range, in_range_with_engine};
143#[cfg(test)]
144use scalar_dispatch::eval_scalar_function;
145pub(crate) use scalar_helpers::{append_sql_literal, quote_ident_with_control};
146use scalar_helpers::{point_xy, typeof_value};
147pub use scalar_helpers::{quote_ident, CompiledLikePattern};
148pub use statement_cancellation::{
149    check_statement_cancellation, statement_cancellation, StatementCancellationScope,
150};
151pub use temporal_input::{
152    temporal_date_order, temporal_interval_style, DateOrderScope, IntervalStyleScope,
153    TemporalInputContext, TemporalInputScope,
154};
155
156mod builtin;
157mod call_arguments;
158mod call_dispatch;
159mod context;
160mod diagnostics;
161mod evaluator;
162
163pub use builtin::{
164    bound_scalar_function_strictness, builtin_scalar_function_strictness,
165    eval_bound_builtin_function_call,
166};
167pub use call_arguments::{
168    call_argument_name, call_argument_value, evaluate_call_args, validate_named_argument_order,
169    validate_named_argument_order_with_control, variadic_argument_value, wrap_variadic_argument,
170};
171pub use call_dispatch::{
172    builtin_named_args, eval_builtin_function_call, eval_builtin_function_call_with_control,
173    eval_function_call, eval_generated_function_call_with_control,
174};
175pub use context::{
176    cast_value_with_type_resolution, cast_value_with_type_resolution_with_control,
177    coercion_type_name, format_regtype_value, format_regtype_value_with_control,
178    read_catalog_array_input, read_catalog_input, CatalogInputFunctions, EngineHook, EvalContext,
179    RowLookup,
180};
181pub(crate) use context::{
182    format_regtype_value_with_catalog_and_control, requires_catalog_constant_input,
183    requires_domain_array_input,
184};
185pub use diagnostics::{unknown_function_error, value_type_name};
186pub use evaluator::eval;
187mod numeric_operator;
188pub use numeric_operator::{eval_numeric_operator, eval_numeric_operator_with_control};
189
190#[cfg(test)]
191mod tests;
192
193mod json_carrier;
194pub use json_carrier::{core_value_to_json, value_to_text, value_to_text_with_control};