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