resultops

package
v0.74.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package resultops applies deterministic local operations to captured result snapshots. It has no executor or network dependency; indexes in its output always refer to the original captured row order.

Index

Constants

View Source
const (
	AggregateSum   = "SUM"
	AggregateCount = "COUNT"
	AggregateMin   = "MIN"
	AggregateMax   = "MAX"
	AggregateAvg   = "AVG"
)

Variables

View Source
var ErrNoGroupColumns = errors.New("grouping requires at least one column")

Functions

This section is empty.

Types

type AggregateTerm

type AggregateTerm struct {
	Column   string
	Function string
	Alias    string
}

AggregateTerm requests one explicitly named aggregate over a captured column. Function is one of AggregateSum, AggregateCount, AggregateMin, or AggregateMax. AVG is intentionally unsupported because this package does not infer an output precision or rounding policy.

type Cell

type Cell struct {
	Present bool
	Value   any
}

Cell distinguishes a missing value from SQL/JSON null. A present cell with Value == nil is null; Present == false is unavailable/missing.

type Column

type Column struct {
	Name string
	Type string
}

Column is metadata supplied by the result's authoritative declared type.

type Group

type Group struct {
	Keys       []Cell
	RowIndices []int
	Count      int
	Aggregates []Cell
}

Group is one first-occurrence ordered group. Keys retain missing/null/value distinctions and RowIndices map to the source snapshot, in original order. Count is the number of source rows in the group, independent of whether the caller requests COUNT(*) as an output column.

type Row

type Row struct {
	Cells []Cell
}

Row is input data for Capture. Its captured identity is its original zero- based row index, which remains stable through grouping and sorting.

type Snapshot

type Snapshot struct {
	// contains filtered or unexported fields
}

Snapshot owns deep copies of its columns and cells. Its fields are private, and every result mapping points into this immutable captured row order.

func Capture

func Capture(columns []Column, rows []Row) (Snapshot, error)

Capture validates the row shape and deep-copies all data so later page loads or caller mutation cannot change the local operation's scope.

func (Snapshot) Columns

func (s Snapshot) Columns() []Column

Columns returns a copy of the captured metadata.

func (Snapshot) GroupBy

func (s Snapshot) GroupBy(columnNames []string) ([]Group, error)

GroupBy groups selected columns by typed ordered tuples. Group order follows first occurrence, and rows within each group preserve their original order.

func (Snapshot) GroupByAggregates

func (s Snapshot) GroupByAggregates(columnNames []string, count bool, terms []AggregateTerm) ([]Group, error)

GroupByAggregates groups captured rows and computes only the explicitly requested aggregates. count marks whether the caller will emit the reserved COUNT(*) output; Group.Count always retains the actual row count. COUNT(column) ignores null values. Missing cells are refused because they do not have SQL aggregate semantics. Integer and decimal sums remain exact; floating sums use sequential IEEE-754 addition and reject non-finite results. Group order and RowIndices retain GroupBy's first-occurrence and source-order behavior.

func (Snapshot) OriginalOrder

func (s Snapshot) OriginalOrder() []int

OriginalOrder returns the mapping that restores the captured row order.

func (Snapshot) RowCount

func (s Snapshot) RowCount() int

RowCount returns the number of rows in the captured loaded scope.

func (Snapshot) Sort

func (s Snapshot) Sort(keys []SortKey) ([]int, error)

Sort returns a stable display-to-original row-index mapping. Missing and null values precede ordinary values ascending; descending reverses each selected key's complete order. Equal keys retain original row order.

type SortKey

type SortKey struct {
	Column     string
	Descending bool
}

SortKey declares one sort priority. Earlier entries have higher priority.

Jump to

Keyboard shortcuts

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