sqlval

package
v0.65.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sqlval holds the small, self-contained value-semantics helpers that both the SQL engine and its retrieval subpackage need.

It exists to break an import cycle. internal/engine imports internal/engine/search for the FTS/vector/RAG algorithms, so search must not import engine back — yet the algorithms need a handful of leaf helpers (stringify a scalar, compare two raw values, coerce to int, check context cancellation, bound a cache map) that engine also uses in hundreds of places. Duplicating them into search would risk the two copies drifting apart, and valueText in particular has behaviour pinned by a test (TestValueTextMatchesSprintfFloatSweep), so a silent divergence there would change query results rather than fail loudly.

Every function here is a leaf: it depends only on the standard library, never on engine types or state. Anything that fans out into engine's coercion, planning, or evaluation machinery deliberately does NOT belong here.

engine keeps unexported forwarders (valueText, rawEqual, toInt, checkCtx, evictOverCap) so its existing call sites are unchanged and this package stays an implementation detail rather than a new vocabulary every caller must learn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCtx

func CheckCtx(ctx context.Context) error

CheckCtx returns ctx's error if it has been cancelled, and nil otherwise. A nil context is treated as never cancelled, so callers with no context to thread need no special case.

func EvictOverCap

func EvictOverCap[K comparable, V any](m map[K]V, maxEntries int)

EvictOverCap removes arbitrary entries until the map is below the cap, making room for one more. Go's random map iteration order makes this a cheap pseudo-random eviction policy — deliberately not LRU, since every cache using it re-derives an evicted entry lazily on the next miss.

func RawEqual

func RawEqual(a, b any) bool

RawEqual reports whether two raw storage values are equal, treating the numeric kinds as mutually comparable (int/int64/float64) so a value read back as one kind still matches a literal written as another.

func ToInt

func ToInt(v any) (int, error)

ToInt coerces a numeric SQL value to int, erroring on anything else.

func ValueText

func ValueText(v any) string

ValueText renders a scalar exactly like fmt.Sprintf("%v", v) but without entering fmt for the types SQL values actually take. Scalar functions coerce arguments to text with this on every call of every row; fmt's reflection walk — and, for strings, its needless copy — dominated their profiles. Types without a fast case (e.g. plain []byte, whose %v form is the decimal byte list) fall back to fmt to keep output byte-identical.

json.RawMessage gets its own case rather than falling to fmt: whether fmt's %v renders a named byte-slice type as its decimal byte list or as text is not stable across Go versions (observed: go1.26.6 gives the former, go1.27.1 the latter, for the exact same json.RawMessage value), and GEOMETRY/JSON columns store their value as json.RawMessage. Converting it directly to a string is also what "render the JSON text" actually means, so this is a correctness fix as well as a fast path.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL