Skip to main content

Module eval

Module eval 

Source
Expand description

Expression evaluator. Given a parsed Expr, a Row, and the row’s column schema, produce a Value. v0.4 implements:

  • literals
  • column lookups (bare and qualified t.col)
  • unary minus / NOT
  • binary arithmetic, comparison, AND, OR
  • numeric widening (Int → BigInt → Float) at evaluation time
  • SQL three-valued logic for NULL:
    • any arithmetic / comparison op with a NULL operand → NULL
    • TRUE OR NULL → TRUE, FALSE OR NULL → NULL,
    • FALSE AND NULL → FALSE, TRUE AND NULL → NULL,
    • NOT NULL → NULL

v0.4 deliberately does not implement: function calls, string concatenation, IS NULL / IS NOT NULL, BETWEEN, IN, etc. Those come later.

Structs§

EvalContext
Resolution context for evaluating a single row. table_alias is the alias (or table name) callers should accept as the qualifier on a column ref — e.g. FROM users AS u makes u.name valid and rejects other.name.

Enums§

EvalError

Functions§

cast_to_vector
Parse a Value::Text("[1.0, 2.0, 3.0]") into a Value::Vector(..). Mirrors pgvector’s '[..]'::vector cast. NULL casts as NULL.
cast_value
PG-style expr::TYPE coercion. NULL always casts as NULL.
days_from_civil
Inverse of civil_from_days — converts (year, month, day) to days since 1970-01-01. Out-of-range months / days saturate.
eval_expr
format_bytea_hex
v7.10.4 — render a BYTEA payload in PG’s hex output format (\x prefix, lowercase hex pairs). Public so the wire layer can emit the canonical bytea-as-text representation.
format_date
Render a Date (days since epoch) as YYYY-MM-DD. Negative values for pre-1970 dates render with a leading - on the year.
format_interval
Render an Interval { months, micros } in a PG-ish shape. The output mirrors psql’s text format: years/months from the months part, days/HH:MM:SS[.frac] from the microsecond part. Empty parts are omitted; an all-zero interval renders as 0.
format_numeric
Render a Numeric { scaled, scale } as its decimal text form. Negative scaled prepends - to the absolute value’s digits; the integer / fractional split is by character count, padding the fractional side with leading zeros to exactly scale chars.
format_text_array
v7.10.9 — render a TEXT[] in PG’s external array form ({a,b,NULL}). Elements containing whitespace, commas, quotes, or braces get double-quoted with \\ / \" escapes. NULL elements use the literal token NULL. Public so the wire layer can produce the canonical text-mode encoding.
format_timestamp
Render a Timestamp (microseconds since epoch) as YYYY-MM-DD HH:MM:SS[.fff...]. Trailing-zero fractional digits are dropped; a whole-second value has no fractional part.
parse_date_literal
Parse YYYY-MM-DD into a Date (days since Unix epoch). Returns None on shape / numeric failure; the engine surfaces that as a TypeMismatch with the original text included.
parse_timestamp_literal
Parse YYYY-MM-DD[ HH:MM:SS[.ffffff]] into a Timestamp (microseconds since Unix epoch). The time portion is optional; missing → midnight. The fractional portion accepts 1–6 digits and pads with zeros to microseconds.