Skip to main content

Crate kevy_scalar

Crate kevy_scalar 

Source
Expand description

kevy-scalar — PG-canonical scalar function evaluation.

The function library behind kevy’s sql face (the V1 scalar surface): SELECT lower('X')-shaped constant folding and the query-card projection epilogue both call eval. Nothing here ever runs inside a serving engine process — evaluation stays in the sql face by design (Law 3), which is why this crate knows nothing about kevy: it maps a function name and Scalar arguments to a Scalar result, PG 18 semantics, and that is the whole contract.

Semantics ground truth: the pg_regress-derived probe corpus (bench/funcgate-corpus/). The tests in this crate are transcribed from those files — where PG is surprising (floor toward −infinity, trim strips a character SET not a substring, NULL propagates through almost everything), the probe line is cited.

use kevy_scalar::{eval, Scalar};
let out = eval("lower", &[Scalar::Text("HeLLo".into())])?;
assert_eq!(out, Scalar::Text("hello".into()));

Enums§

Scalar
A typed scalar value — the closed set the function library speaks.
ScalarError
Why a call could not be evaluated.

Functions§

binop
Apply a <op> b where op is one of + - * /.
cmp_op
A comparison operator (=, <>, <, <=, >, >=) with strict NULL propagation. Same-type comparisons only, plus the int↔float numeric promotion; PG orders false < true, text compares bytewise (C collation — the corpus subset’s semantics).
eval
Evaluate func(args…) with PG 18 semantics.
logic_and
Three-valued AND: false dominates, otherwise NULL if either side is unknown (PG: NULL AND false = false).
logic_not
Three-valued NOT: NOT NULL is NULL.
logic_or
Three-valued OR: true dominates (PG: NULL OR true = true).
parse_date
Parse YYYY-MM-DD into days since the epoch.
parse_interval
Parse a PG interval literal: whitespace-separated <n> <unit> pairs (1 year 2 months, -3 days, 90 minutes) into the three-component (months, days, micros).
parse_pg_bool
PG’s boolean input vocabulary (boolin): case-insensitive, whitespace-trimmed t/f true/false y/n yes/no on/off 1/0. Anything else is a cast error (the caller reports it by name).
parse_timestamp
Parse YYYY-MM-DD[ HH:MM:SS[.ffffff]] (a T separator is accepted too) into epoch microseconds. None on anything malformed — the sql face refuses by name, this module never guesses.
render_date
YYYY-MM-DD.
render_interval
PG’s interval output: N year(s) N mon(s) N day(s) HH:MM:SS, each piece only when non-zero, 00:00:00 alone when everything is. The components render independently — 1 day -12:00:00 stays exactly that (probe 10).
render_timestamp
YYYY-MM-DD HH:MM:SS[.ffffff] — fraction only when non-zero.