qs

package
v0.30.38 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package qs provides query-system utilities shared by the OQL and Sulpher subsystems. Functions here must remain free of subsystem-specific dependencies — no tsqlparser AST types, no sulpher AST types, no storage interfaces. Both subsystems import this package; optimising or changing any function here affects both.

Index

Constants

This section is empty.

Variables

View Source
var AggregateFunctions = map[string]AggFunc{
	"COUNT": AggCount,
	"SUM":   AggSum,
	"AVG":   AggAvg,
	"MIN":   AggMin,
	"MAX":   AggMax,
}

AggregateFunctions is the canonical map of aggregate function name (upper-case) to implementation.

View Source
var ScalarFunctions = wrapFinite(rawScalarFunctions)

ScalarFunctions is the canonical map of function name (upper-case) to implementation. OQL and Sulpher build their own registries from this map, adding subsystem-specific aliases or overrides as needed. All entries are wrapped in finiteResult so callers can rely on the no-NaN-no-Inf invariant.

Functions

func AggAvg

func AggAvg(values []interface{}) interface{}

AggAvg returns the mean of all numeric non-nil values. Returns nil when no numeric values are present.

func AggCollect

func AggCollect(values []interface{}) interface{}

AggCollect accumulates all non-nil values into a []interface{} slice. This is the Cypher collect() aggregate; it has no T-SQL equivalent.

func AggCount

func AggCount(values []interface{}) interface{}

AggCount counts non-nil values. When all values are nil (COUNT(*) semantics where the caller passes a slice of non-nil sentinels), it counts all of them.

func AggMax

func AggMax(values []interface{}) interface{}

AggMax returns the maximum value. Numeric types (including string-encoded numerics) are compared numerically; other types use CompareValues ordering. Returns nil when values is empty or all nil.

func AggMin

func AggMin(values []interface{}) interface{}

AggMin returns the minimum value. Numeric types (including string-encoded numerics) are compared numerically; other types use CompareValues ordering. Returns nil when values is empty or all nil.

func AggSum

func AggSum(values []interface{}) interface{}

AggSum sums all numeric non-nil values. Returns nil when no numeric values are present (SQL standard: SUM of empty set is NULL). Handles string-encoded numerics (e.g. SQLite decimal columns returned as text).

func ApplyDistinct

func ApplyDistinct(results []map[string]interface{}) []map[string]interface{}

ApplyDistinct removes duplicate rows from a result set. Equality is determined by JSON serialisation of the full row map. Rows that cannot be serialised are included without deduplication.

func CompareValues

func CompareValues(a, b interface{}) int

CompareValues compares two interface{} values and returns -1, 0, or 1. Numeric types are compared numerically. All other types are compared as their fmt.Sprintf("%v") string representation. Nil sorts before any non-nil value.

func GetNestedValue

func GetNestedValue(m map[string]interface{}, path string) interface{}

GetNestedValue retrieves a value from a map using dot notation. "name" returns m["name"]; "address.city" returns m["address"].(map)["city"]. Returns nil when any segment is absent or the intermediate value is not a map.

func IsBareIdentRune

func IsBareIdentRune(r rune) bool

IsBareIdentRune reports whether r may appear *within* a bare SQL identifier: an ASCII letter, an ASCII digit, or underscore. It does not enforce the leading-character rule (see IsValidIdentifier).

ASCII-only is deliberate. Permitting Unicode letters would open a homoglyph/confusable attack surface (e.g. a Cyrillic "а" U+0430 is visually identical to Latin "a" U+0061), letting one tenant register an entity that is indistinguishable from another's in logs, tooling, and policy. xolu has no use case for non-ASCII identifiers — they would also be hard to type in queries — so the safe, friction-free policy is ASCII only. (Free-text search content is a separate concern handled by the FTS sanitiser, not this function.)

This is the rune-level predicate used by the parse-time AST gates to detect delimiter-smuggled identifiers: any identifier value containing a rune for which this returns false could only have entered through a delimited form ([..], "..", or `..`) and is therefore rejected before SQL generation.

func IsValidFieldPath

func IsValidFieldPath(s string) bool

IsValidFieldPath reports whether s is a dot-separated path of valid bare identifiers (e.g. "title" or "a.title"). Each segment must independently satisfy IsValidIdentifier; empty segments (leading, trailing, or doubled dots) are rejected. This is the qualified-field variant used by the OQL field resolver, which legitimately needs the dot separator that a plain identifier disallows.

func IsValidIdentifier

func IsValidIdentifier(s string) bool

IsValidIdentifier reports whether s is a valid bare SQL identifier: it must be non-empty, start with a letter or underscore, and otherwise contain only letters, digits, and underscores. This is the canonical rule previously duplicated as adaptedFieldNameRe, identifierRe, isSimpleIdent, etc.

func IsValidStrictFieldPath

func IsValidStrictFieldPath(s string) bool

IsValidStrictFieldPath reports whether s is a dot-separated path of valid leading-letter bare identifiers.

func IsValidStrictIdentifier

func IsValidStrictIdentifier(s string) bool

IsValidStrictIdentifier reports whether s is a non-empty bare identifier that starts with an ASCII letter (not underscore) and otherwise contains only letters, digits, and underscores.

func ParseTime

func ParseTime(v interface{}) (time.Time, bool)

func ScalarAbs

func ScalarAbs(args []interface{}) interface{}

func ScalarCast

func ScalarCast(args []interface{}) interface{}

func ScalarCeiling

func ScalarCeiling(args []interface{}) interface{}

func ScalarCharIndex

func ScalarCharIndex(args []interface{}) interface{}

func ScalarCoalesce

func ScalarCoalesce(args []interface{}) interface{}

func ScalarConcat

func ScalarConcat(args []interface{}) interface{}

func ScalarDateDiff

func ScalarDateDiff(args []interface{}) interface{}

func ScalarDatePart

func ScalarDatePart(args []interface{}) interface{}

func ScalarDateTrunc

func ScalarDateTrunc(args []interface{}) interface{}

func ScalarDay

func ScalarDay(args []interface{}) interface{}

func ScalarFloor

func ScalarFloor(args []interface{}) interface{}

func ScalarGetDate

func ScalarGetDate(args []interface{}) interface{}

func ScalarGetUTCDate

func ScalarGetUTCDate(args []interface{}) interface{}

func ScalarLTrim

func ScalarLTrim(args []interface{}) interface{}

func ScalarLabels

func ScalarLabels(args []interface{}) interface{}

ScalarLabels returns the label slice from a node map that has a "labels" key, or a single-element slice containing the "type" key value. Returns nil when the argument is not a recognised node map.

func ScalarLeft

func ScalarLeft(args []interface{}) interface{}

func ScalarLen

func ScalarLen(args []interface{}) interface{}

func ScalarLower

func ScalarLower(args []interface{}) interface{}

func ScalarMonth

func ScalarMonth(args []interface{}) interface{}

func ScalarNewID

func ScalarNewID(args []interface{}) interface{}

ScalarNewID implements T-SQL NEWID(): it returns a random (version 4) UUID string. It takes no arguments. This is the OQL-surface counterpart of the FSM eval NEWID()/UUID_V4(); both produce a real, unique, unpredictable UUID via the same generator (uuid.NewRandom). On the rare generator error it returns nil (SQL NULL) rather than a malformed value.

func ScalarPower

func ScalarPower(args []interface{}) interface{}

func ScalarRTrim

func ScalarRTrim(args []interface{}) interface{}

func ScalarReplace

func ScalarReplace(args []interface{}) interface{}

func ScalarReverse

func ScalarReverse(args []interface{}) interface{}

func ScalarRight

func ScalarRight(args []interface{}) interface{}

func ScalarRound

func ScalarRound(args []interface{}) interface{}

func ScalarSign

func ScalarSign(args []interface{}) interface{}

func ScalarSize

func ScalarSize(args []interface{}) interface{}

ScalarSize returns the length of a string or the number of elements in a slice. Returns nil for other types.

func ScalarSqrt

func ScalarSqrt(args []interface{}) interface{}

func ScalarSubstring

func ScalarSubstring(args []interface{}) interface{}

func ScalarToFloat

func ScalarToFloat(args []interface{}) interface{}

func ScalarToInt

func ScalarToInt(args []interface{}) interface{}

func ScalarTrim

func ScalarTrim(args []interface{}) interface{}

func ScalarType

func ScalarType(args []interface{}) interface{}

ScalarType returns the relationship type string from a map that has a "relationship" or "type" key — matching xolu's GraphEdge representation. Returns nil when the argument is not a recognised edge map.

func ScalarUpper

func ScalarUpper(args []interface{}) interface{}

func ScalarYear

func ScalarYear(args []interface{}) interface{}

func ToFloat

func ToFloat(v interface{}) float64

ToFloat converts a value to float64, returning 0 for unrecognised types. Use ToFloatSafe when you need to distinguish a genuine zero from a conversion failure.

func ToFloatSafe

func ToFloatSafe(v interface{}) (float64, bool)

ToFloatSafe converts a value to float64. Returns (value, true) on success and (0, false) when the type cannot be converted.

func ValidateFieldPath

func ValidateFieldPath(s string) error

ValidateFieldPath returns a descriptive error if s is not a valid dotted field path, or nil if it is.

func ValidateIdentifier

func ValidateIdentifier(s string) error

ValidateIdentifier returns a descriptive error if s is not a valid bare SQL identifier, or nil if it is. Use this where the caller wants to surface the reason (registration, schema derivation, the load trust boundary).

func ValidateStrictFieldPath

func ValidateStrictFieldPath(s string) error

ValidateStrictFieldPath returns a descriptive error if s is not a valid dotted path of leading-letter identifiers, or nil if it is.

func ValidateStrictIdentifier

func ValidateStrictIdentifier(s string) error

ValidateStrictIdentifier returns a descriptive error if s is not a valid leading-letter bare identifier, or nil if it is.

Types

type AggFunc

type AggFunc func(values []interface{}) interface{}

AggFunc is a function that reduces a slice of values to a single value. Both OQL and Sulpher use this type; dispatch is handled by each subsystem's own aggregator.

type ScalarFunc

type ScalarFunc func(args []interface{}) interface{}

ScalarFunc is a function that takes a list of evaluated arguments and returns a single value. Both OQL and Sulpher use this type; dispatch is handled by each subsystem's own function registry.

Jump to

Keyboard shortcuts

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