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 ¶
- Variables
- func AggAvg(values []interface{}) interface{}
- func AggCollect(values []interface{}) interface{}
- func AggCount(values []interface{}) interface{}
- func AggMax(values []interface{}) interface{}
- func AggMin(values []interface{}) interface{}
- func AggSum(values []interface{}) interface{}
- func ApplyDistinct(results []map[string]interface{}) []map[string]interface{}
- func CompareValues(a, b interface{}) int
- func GetNestedValue(m map[string]interface{}, path string) interface{}
- func IsBareIdentRune(r rune) bool
- func IsValidFieldPath(s string) bool
- func IsValidIdentifier(s string) bool
- func IsValidStrictFieldPath(s string) bool
- func IsValidStrictIdentifier(s string) bool
- func ParseTime(v interface{}) (time.Time, bool)
- func ScalarAbs(args []interface{}) interface{}
- func ScalarCast(args []interface{}) interface{}
- func ScalarCeiling(args []interface{}) interface{}
- func ScalarCharIndex(args []interface{}) interface{}
- func ScalarCoalesce(args []interface{}) interface{}
- func ScalarConcat(args []interface{}) interface{}
- func ScalarDateDiff(args []interface{}) interface{}
- func ScalarDatePart(args []interface{}) interface{}
- func ScalarDateTrunc(args []interface{}) interface{}
- func ScalarDay(args []interface{}) interface{}
- func ScalarFloor(args []interface{}) interface{}
- func ScalarGetDate(args []interface{}) interface{}
- func ScalarGetUTCDate(args []interface{}) interface{}
- func ScalarLTrim(args []interface{}) interface{}
- func ScalarLabels(args []interface{}) interface{}
- func ScalarLeft(args []interface{}) interface{}
- func ScalarLen(args []interface{}) interface{}
- func ScalarLower(args []interface{}) interface{}
- func ScalarMonth(args []interface{}) interface{}
- func ScalarNewID(args []interface{}) interface{}
- func ScalarPower(args []interface{}) interface{}
- func ScalarRTrim(args []interface{}) interface{}
- func ScalarReplace(args []interface{}) interface{}
- func ScalarReverse(args []interface{}) interface{}
- func ScalarRight(args []interface{}) interface{}
- func ScalarRound(args []interface{}) interface{}
- func ScalarSign(args []interface{}) interface{}
- func ScalarSize(args []interface{}) interface{}
- func ScalarSqrt(args []interface{}) interface{}
- func ScalarSubstring(args []interface{}) interface{}
- func ScalarToFloat(args []interface{}) interface{}
- func ScalarToInt(args []interface{}) interface{}
- func ScalarTrim(args []interface{}) interface{}
- func ScalarType(args []interface{}) interface{}
- func ScalarUpper(args []interface{}) interface{}
- func ScalarYear(args []interface{}) interface{}
- func ToFloat(v interface{}) float64
- func ToFloatSafe(v interface{}) (float64, bool)
- func ValidateFieldPath(s string) error
- func ValidateIdentifier(s string) error
- func ValidateStrictFieldPath(s string) error
- func ValidateStrictIdentifier(s string) error
- type AggFunc
- type ScalarFunc
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
IsValidStrictFieldPath reports whether s is a dot-separated path of valid leading-letter bare identifiers.
func IsValidStrictIdentifier ¶
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 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 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 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 ¶
ToFloatSafe converts a value to float64. Returns (value, true) on success and (0, false) when the type cannot be converted.
func ValidateFieldPath ¶
ValidateFieldPath returns a descriptive error if s is not a valid dotted field path, or nil if it is.
func ValidateIdentifier ¶
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 ¶
ValidateStrictFieldPath returns a descriptive error if s is not a valid dotted path of leading-letter identifiers, or nil if it is.
func ValidateStrictIdentifier ¶
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.