expr

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(n ExprNode, fn func(ExprNode) error) error

Walk performs a post-order, read-only traversal of n. Children are visited before the node itself, and the first error returned by fn aborts the walk. fn is never called on a nil node.

Types

type AggNode

type AggNode struct {
	Op    AggOp
	Inner Expr
	Alias string
}

AggNode is a column-level aggregation used by GroupBy().Agg. It is a concrete public struct rather than an ExprNode: Agg accepts only AggNode values, so passing a non-aggregate expression is a compile-time error. Op is the reduction, Inner is the expression being reduced, and Alias is the output column name (empty means "derive a default").

func (AggNode) As

func (a AggNode) As(name string) AggNode

As sets the output column name for the aggregation.

func (AggNode) String

func (a AggNode) String() string

type AggOp

type AggOp uint8
const (
	AggOpInvalid AggOp = iota

	AggOpCount
	AggOpSum
	AggOpMean
	AggOpMin
	AggOpMax
)

func (AggOp) String

func (op AggOp) String() string

type AliasNode

type AliasNode struct {
	Name  string
	Inner ExprNode
}

AliasNode renames the result of Inner. The output type and value are passed through unchanged; project operators are responsible for using Name when assembling the output schema.

func (AliasNode) Children

func (a AliasNode) Children() []ExprNode

func (AliasNode) DataType

func (a AliasNode) DataType(s *schema.Schema) (arrow.DataType, error)

func (AliasNode) String

func (a AliasNode) String() string

type BinaryNode

type BinaryNode struct {
	Op    BinaryOp
	Left  ExprNode
	Right ExprNode
}

BinaryNode is the canonical comparison/logical/arithmetic node. The Op determines result-type rules: comparisons and logical ops produce bool; arithmetic ops use promoteNumeric on the operand types.

func (BinaryNode) Children

func (b BinaryNode) Children() []ExprNode

func (BinaryNode) DataType

func (b BinaryNode) DataType(s *schema.Schema) (arrow.DataType, error)

func (BinaryNode) String

func (b BinaryNode) String() string

type BinaryOp

type BinaryOp uint8
const (
	BinaryOpInvalid BinaryOp = iota

	BinaryOpEq
	BinaryOpNeq
	BinaryOpLt
	BinaryOpLte
	BinaryOpGt
	BinaryOpGte

	BinaryOpAnd
	BinaryOpOr

	BinaryOpAdd
	BinaryOpSub
	BinaryOpMul
	BinaryOpDiv
)

func (BinaryOp) String

func (op BinaryOp) String() string

type CastNode

type CastNode struct {
	Inner ExprNode
	Type  arrow.DataType
}

CastNode forces the output type of Inner to Type. Bind-time validation only checks that the inner expression resolves; runtime evaluation must verify the cast is supported and report failures.

func (CastNode) Children

func (c CastNode) Children() []ExprNode

func (CastNode) DataType

func (c CastNode) DataType(s *schema.Schema) (arrow.DataType, error)

func (CastNode) String

func (c CastNode) String() string

type ColumnNode

type ColumnNode struct {
	Name string
}

ColumnNode references an input column by name. Its output type is resolved against the schema at bind time.

func (ColumnNode) Children

func (c ColumnNode) Children() []ExprNode

func (ColumnNode) DataType

func (c ColumnNode) DataType(s *schema.Schema) (arrow.DataType, error)

func (ColumnNode) String

func (c ColumnNode) String() string

type Expr

type Expr struct {
	Node ExprNode
}

Expr is the public, transparent wrapper around an expression tree node. The exported Node field holds the root ExprNode, so the tree is fully inspectable, serializable, and pattern-matchable by external callers. Fluent methods compose new Expr values left-to-right without mutating the receiver.

func Col

func Col(name string) Expr

Col references an input column by name.

func Float32

func Float32(v float32) Expr

func Float64

func Float64(v float64) Expr

func Int8

func Int8(v int8) Expr

func Int16

func Int16(v int16) Expr

func Int32

func Int32(v int32) Expr

func Int64

func Int64(v int64) Expr

func Lit

func Lit(v any) Expr

Lit wraps a Go scalar as a literal. The Arrow type is inferred from the value (untyped ints → int64, untyped floats → float64). Use the typed constructors below when you need a specific Arrow width.

func LitTimestamp

func LitTimestamp(t time.Time, tz string) Expr

LitTimestamp returns an Expr wrapping a LiteralNode of type Timestamp(nanosecond, tz). The instant t is stored as nanoseconds since the Unix epoch (UTC), matching the canonical type inferLiteralType assigns to a bare time.Time literal. tz is the IANA timezone string carried on the Arrow type; pass "" for a timezone-naive timestamp.

func Uint8

func Uint8(v uint8) Expr

func Uint16

func Uint16(v uint16) Expr

func Uint32

func Uint32(v uint32) Expr

func Uint64

func Uint64(v uint64) Expr

func (Expr) Add

func (e Expr) Add(other Expr) Expr

func (Expr) And

func (e Expr) And(other Expr) Expr

func (Expr) As

func (e Expr) As(name string) Expr

As renames the expression's result via an AliasNode.

func (Expr) Cast

func (e Expr) Cast(t arrow.DataType) Expr

Cast forces the expression's output type.

func (Expr) Count

func (e Expr) Count() AggNode

Count/Sum/Mean/Min/Max build an AggNode over the expression. They return the concrete AggNode type (not Expr) so that GroupBy().Agg only accepts aggregates at compile time.

func (Expr) Div

func (e Expr) Div(other Expr) Expr

func (Expr) Eq

func (e Expr) Eq(other Expr) Expr

func (Expr) Gt

func (e Expr) Gt(other Expr) Expr

func (Expr) Gte

func (e Expr) Gte(other Expr) Expr

func (Expr) IsNotNull

func (e Expr) IsNotNull() Expr

func (Expr) IsNull

func (e Expr) IsNull() Expr

func (Expr) Lt

func (e Expr) Lt(other Expr) Expr

func (Expr) Lte

func (e Expr) Lte(other Expr) Expr

func (Expr) Max

func (e Expr) Max() AggNode

func (Expr) Mean

func (e Expr) Mean() AggNode

func (Expr) Min

func (e Expr) Min() AggNode

func (Expr) Mul

func (e Expr) Mul(other Expr) Expr

func (Expr) Neg

func (e Expr) Neg() Expr

func (Expr) Neq

func (e Expr) Neq(other Expr) Expr

func (Expr) Not

func (e Expr) Not() Expr

func (Expr) Or

func (e Expr) Or(other Expr) Expr

func (Expr) String

func (e Expr) String() string

func (Expr) Sub

func (e Expr) Sub(other Expr) Expr

func (Expr) Sum

func (e Expr) Sum() AggNode

type ExprNode

type ExprNode interface {
	String() string
	Children() []ExprNode
	DataType(s *schema.Schema) (arrow.DataType, error)
}

ExprNode is the interface implemented by every node in the public expression tree. Unlike the previous internal design it carries no unexported marker: the node types are a public, inspectable, serializable contract, so external optimizer passes and deserializers may introduce their own implementations.

Children returns this node's direct child nodes in evaluation order and may return nil for leaves. DataType resolves the node's Arrow output type against the input schema without evaluating it.

func Rewrite

func Rewrite(n ExprNode, fn func(ExprNode) ExprNode) ExprNode

Rewrite performs a post-order rewrite of n. Each child is rewritten first, the parent is rebuilt with the new children via withChildren, and finally fn is invoked on the (possibly rebuilt) parent to produce its replacement. Rewrite does not recurse into the replacement, so callers wanting a fixed point should loop until no node changes.

type LiteralNode

type LiteralNode struct {
	Value any
	Type  arrow.DataType
}

LiteralNode is a scalar constant. Type is resolved at construction so that later DataType() calls do not need to re-infer from the Go value.

func (LiteralNode) Children

func (l LiteralNode) Children() []ExprNode

func (LiteralNode) DataType

func (l LiteralNode) DataType(_ *schema.Schema) (arrow.DataType, error)

func (LiteralNode) String

func (l LiteralNode) String() string

type SortKey

type SortKey struct {
	Column     string
	Descending bool
	NullsFirst bool
}

SortKey describes one column of a multi-column sort: which column, ascending vs descending, and where nulls land. Build one with By and refine it with the fluent Desc / WithNullsFirst methods.

func By

func By(column string) SortKey

By starts an ascending, nulls-last sort key over the named column.

func (SortKey) Desc

func (k SortKey) Desc() SortKey

Desc flips the key to descending order.

func (SortKey) WithNullsFirst

func (k SortKey) WithNullsFirst() SortKey

WithNullsFirst orders nulls before non-null values for this key.

type UnaryNode

type UnaryNode struct {
	Op    UnaryOp
	Inner ExprNode
}

UnaryNode applies a single-operand operator. Logical and null-test ops return bool; arithmetic negation preserves the operand type.

func (UnaryNode) Children

func (u UnaryNode) Children() []ExprNode

func (UnaryNode) DataType

func (u UnaryNode) DataType(s *schema.Schema) (arrow.DataType, error)

func (UnaryNode) String

func (u UnaryNode) String() string

type UnaryOp

type UnaryOp uint8
const (
	UnaryOpInvalid UnaryOp = iota

	UnaryOpNot
	UnaryOpNeg
	UnaryOpIsNull
	UnaryOpIsNotNull
)

func (UnaryOp) String

func (op UnaryOp) String() string

Jump to

Keyboard shortcuts

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