Documentation
¶
Overview ¶
Package aggrt holds the aggregator-runtime types and helpers shared between the internal Aggregator wrapper, the window sub-package, and per-aggregate function implementations. It is a leaf package: it depends on internal/value but is depended upon by internal/ and by internal/function/window/.
Index ¶
- Variables
- func AddMonth(t time.Time, m int) time.Time
- func AddYear(t time.Time, y int) time.Time
- func BucketFloor(target, origin time.Time, iv *value.IntervalValue) (time.Time, error)
- func DISTINCT() (value.Value, error)
- func ExistsNull(args []value.Value) bool
- func FormatTime(formatStr string, t *time.Time, typ TimeFormatType) (string, error)
- func IGNORE_NULLS() (value.Value, error)
- func LIMIT(limit int64) (value.Value, error)
- func ORDER_BY(v value.Value, isAsc bool) (value.Value, error)
- func ParseTimeFormat(formatStr, targetStr string, typ TimeFormatType) (*time.Time, error)
- func SafeByte(v int64) (byte, error)
- func SafeInt(v int64) (int, error)
- func SafeInt32(v int64) (int32, error)
- func SafeUint32(v int64) (uint32, error)
- type Aggregator
- type BindFunction
- func Scalar1(fn func(value.Value) (value.Value, error)) BindFunction
- func Scalar1KeepNull(fn func(value.Value) (value.Value, error)) BindFunction
- func Scalar2(fn func(a, b value.Value) (value.Value, error)) BindFunction
- func Scalar2KeepNull(fn func(a, b value.Value) (value.Value, error)) BindFunction
- func Scalar3(fn func(a, b, c value.Value) (value.Value, error)) BindFunction
- func ScalarN(fn func(...value.Value) (value.Value, error)) BindFunction
- func ScalarNKeepNull(fn func(...value.Value) (value.Value, error)) BindFunction
- type CombinationFormatTimeInfo
- type DayOfWeek
- type FormatTimeInfo
- type FuncOption
- type FuncOptionType
- type Month
- type Option
- type OrderBy
- type OrderedValue
- type ParseFunction
- type TimeFormatType
- type TimeParserPostProcessor
Constants ¶
This section is empty.
Variables ¶
var QuarterStartMonths = []time.Month{time.January, time.April, time.July, time.October}
var WeekPartToOffset = map[string]int{
"WEEK": 0,
"WEEK_MONDAY": 1,
"WEEK_TUESDAY": 2,
"WEEK_WEDNESDAY": 3,
"WEEK_THURSDAY": 4,
"WEEK_FRIDAY": 5,
"WEEK_SATURDAY": 6,
}
Functions ¶
func BucketFloor ¶
BucketFloor computes the inclusive lower bound of the fixed-width bucket — anchored at origin — that contains target. Used by DATE_BUCKET / DATETIME_BUCKET / TIMESTAMP_BUCKET.
The interval must be a single-part value (any of YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, NANOSECOND, or a single calendar- week of 7 days). Mixed month + sub-month parts are rejected because month width is calendar-dependent and would change per-bucket.
func DISTINCT ¶
DISTINCT, IGNORE_NULLS, LIMIT, ORDER_BY emit the encoded marker values that the analyzer-rewritten SQL passes alongside the real aggregate arguments.
func ExistsNull ¶
ExistsNull reports whether any of the args is the runtime NULL (a nil value.Value). Per-spec helpers that handle their own arity can use this to short-circuit NULL propagation.
func FormatTime ¶
func IGNORE_NULLS ¶
func ParseTimeFormat ¶
func ParseTimeFormat(formatStr, targetStr string, typ TimeFormatType) (*time.Time, error)
func SafeByte ¶ added in v0.2.0
SafeByte converts a 64-bit integer to byte, returning an error when v falls outside the [0, 255] range.
func SafeInt ¶ added in v0.2.0
SafeInt converts a 64-bit integer to int. It returns an error when v falls outside the 32-bit range, which is the minimum width the Go specification guarantees for int. Callers use the result as a slice index, length, count, or a date/time component; none of those can legitimately exceed that range, so an out-of-range value is a genuine error rather than a silently truncated conversion.
func SafeInt32 ¶ added in v0.2.0
SafeInt32 converts a 64-bit integer to int32, returning an error when v overflows the INT32 range.
func SafeUint32 ¶ added in v0.2.0
SafeUint32 converts a 64-bit integer to uint32, returning an error when v falls outside the [0, 4294967295] range.
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator is the SQLite-side wrapper that drives a per-spec aggregate (Step / Done shape) over a single GROUP. SQLite hands each row's args to Step; we strip the encoded option markers (DISTINCT / IGNORE_NULLS / LIMIT / ORDER_BY), thread the resulting Option through to the per-spec step function, and finally encode the Done result back into the over-the-wire form.
Living in the leaf aggrt package alongside Option keeps it importable by every aggregate-family sub-package (aggregate, approx_aggregate, stat_aggregate, hll) without going through internal.
func NewAggregator ¶
func NewAggregator( step func([]value.Value, *Option) error, done func() (value.Value, error), ) *Aggregator
NewAggregator wires up a fresh Aggregator with the given per-spec step / done callbacks. Returns the wrapper SQLite drives.
func (*Aggregator) Done ¶
func (a *Aggregator) Done() (any, error)
func (*Aggregator) Step ¶
func (a *Aggregator) Step(stepArgs ...any) error
type BindFunction ¶
BindFunction is the signature ncruces' adapter expects from us: take an arg list of (possibly NULL) googlesqlite Values and return either a Value or an error.
func Scalar1 ¶
Scalar1 wraps a 1-arg semantic function. Returns NULL when the single argument is NULL.
func Scalar1KeepNull ¶
Scalar1KeepNull wraps a 1-arg semantic function that needs to observe NULL itself (e.g. IS_NULL).
func Scalar2KeepNull ¶
Scalar2KeepNull wraps a 2-arg semantic function that needs to observe NULL itself (e.g. IS_DISTINCT_FROM).
func ScalarN ¶
ScalarN wraps an arbitrary-arity semantic function that should short-circuit when any argument is NULL.
func ScalarNKeepNull ¶
ScalarNKeepNull wraps a variadic semantic function that needs to observe NULLs itself (e.g. COALESCE).
type CombinationFormatTimeInfo ¶
type CombinationFormatTimeInfo struct {
AvailableTypes []TimeFormatType
Parse func([]rune, *time.Time) (int, error)
Format func(*time.Time) ([]rune, error)
}
func (*CombinationFormatTimeInfo) Available ¶
func (i *CombinationFormatTimeInfo) Available(typ TimeFormatType) bool
type FormatTimeInfo ¶
type FormatTimeInfo struct {
AvailableTypes []TimeFormatType
Parse ParseFunction
Format func(*time.Time) ([]rune, error)
}
func (*FormatTimeInfo) Available ¶
func (i *FormatTimeInfo) Available(typ TimeFormatType) bool
type FuncOption ¶
type FuncOption struct {
Type FuncOptionType `json:"type"`
Value any `json:"value"`
}
FuncOption is one of the encoded option markers (DISTINCT / IGNORE_NULLS / LIMIT / ORDER_BY) that the analyzer wraps around aggregate / window argument lists. parseAggregateOptions strips them from the runtime arg list and merges them into an AggregatorOption.
func (*FuncOption) UnmarshalJSON ¶
func (o *FuncOption) UnmarshalJSON(b []byte) error
type FuncOptionType ¶
type FuncOptionType string
const ( OptionUnknown FuncOptionType = "aggregate_unknown" OptionDistinct FuncOptionType = "aggregate_distinct" OptionLimit FuncOptionType = "aggregate_limit" OptionOrderBy FuncOptionType = "aggregate_order_by" OptionIgnoreNulls FuncOptionType = "aggregate_ignore_nulls" )
type Month ¶
type Month string
const ( January Month = "January" February Month = "February" March Month = "March" April Month = "April" May Month = "May" June Month = "June" July Month = "July" August Month = "August" September Month = "September" October Month = "October" November Month = "November" December Month = "December" )
type Option ¶
Option holds the aggregate-call-level flags parsed out of the FuncOption markers in a step's argument list.
type OrderBy ¶
OrderBy is the per-arg ordering directive packed into an ORDER_BY(<value>, <isAsc>) marker. The Value field is decoded from its over-the-wire form by UnmarshalJSON below using the canonical value codec.
func (*OrderBy) UnmarshalJSON ¶
type OrderedValue ¶
OrderedValue captures a single value plus the ORDER BY decoration that arrived with it. Aggregators that observe ORDER BY semantics (ARRAY_AGG, STRING_AGG, ARRAY_CONCAT_AGG, ...) buffer rows as OrderedValues and call SortAggregatedValues during Done.
func SortAggregatedValues ¶
func SortAggregatedValues(values []*OrderedValue, opt *Option) []*OrderedValue
SortAggregatedValues stable-sorts the captured values per the ORDER BY directives carried inside each OrderedValue. The caller passes the surrounding Option so SortAggregatedValues can short- circuit when no ORDER BY was attached.
type TimeFormatType ¶
type TimeFormatType int
const ( FormatTypeDate TimeFormatType = 0 FormatTypeDatetime TimeFormatType = 1 FormatTypeTime TimeFormatType = 2 FormatTypeTimestamp TimeFormatType = 3 )
func (TimeFormatType) String ¶
func (t TimeFormatType) String() string