Documentation
¶
Index ¶
- func Bind(n cclNode, colNameMap map[string]int) (cclNode, error)
- func Evaluate(n cclNode, ctx Context) (any, error)
- func GetAssignmentTarget(n cclNode) (string, bool)
- func GetExpressionNode(n cclNode) cclNode
- func GetNewColInfo(n cclNode) (string, cclNode, bool)
- func IsAssignmentNode(n cclNode) bool
- func IsNewColNode(n cclNode) bool
- func IsRowDependent(n cclNode) bool
- func IsSequenceFunction(name string) bool
- func RegisterAggregateFunction(name string, fn AggFunc)
- func RegisterFunction(name string, fn Func)
- func RegisterSequenceFunction(name string, fn SeqFunc)
- func RegisterStandardFunctions()
- func ResetEvalDepth()
- func ResetFuncCallDepth()
- type AggFunc
- type CCLNode
- type ColumnRange
- type Context
- type EvaluationResult
- type Func
- type MapContext
- func (c *MapContext) GetAllData() ([]any, error)
- func (c *MapContext) GetCell(colIndex, rowIndex int) (any, error)
- func (c *MapContext) GetCellByName(colName string, rowIndex int) (any, error)
- func (c *MapContext) GetCol(index int) any
- func (c *MapContext) GetColByName(name string) (any, error)
- func (c *MapContext) GetColCount() int
- func (c *MapContext) GetColData(index int) ([]any, error)
- func (c *MapContext) GetColDataByName(name string) ([]any, error)
- func (c *MapContext) GetColIndexByName(colName string) (int, error)
- func (c *MapContext) GetCurrentRow() any
- func (c *MapContext) GetRowAt(rowIndex int) (any, error)
- func (c *MapContext) GetRowCount() int
- func (c *MapContext) GetRowIndex() int
- func (c *MapContext) GetRowIndexByName(rowName string) (int, error)
- func (c *MapContext) SetRowIndex(index int) error
- type RowRange
- type SeqFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bind ¶ added in v0.2.11
Bind traverses the AST and resolves column references to indices. It returns a new AST with resolved nodes.
func GetAssignmentTarget ¶ added in v0.2.9
GetAssignmentTarget returns the target column name/index if the node is an assignment
func GetExpressionNode ¶ added in v0.2.11
func GetExpressionNode(n cclNode) cclNode
GetExpressionNode returns the underlying expression node
func GetNewColInfo ¶ added in v0.2.9
GetNewColInfo returns the new column info if the node is a NEW function
func IsAssignmentNode ¶ added in v0.2.9
func IsAssignmentNode(n cclNode) bool
IsAssignmentNode checks if the node is an assignment
func IsNewColNode ¶ added in v0.2.9
func IsNewColNode(n cclNode) bool
IsNewColNode checks if the node is a NEW column creation
func IsRowDependent ¶ added in v0.2.11
func IsRowDependent(n cclNode) bool
IsRowDependent checks if the expression depends on the current row.
func IsSequenceFunction ¶ added in v0.2.18
IsSequenceFunction reports whether name resolves to a registered sequence function. Exposed for the evaluator and IsRowDependent.
func RegisterAggregateFunction ¶ added in v0.2.14
RegisterAggregateFunction registers a custom aggregate function for CCL evaluation.
func RegisterFunction ¶
RegisterFunction registers a custom scalar function for CCL evaluation.
func RegisterSequenceFunction ¶ added in v0.2.18
RegisterSequenceFunction registers a custom sequence function (whole-column input, same-length-column output) for CCL evaluation.
func RegisterStandardFunctions ¶ added in v0.2.11
func RegisterStandardFunctions()
RegisterStandardFunctions registers the standard library of CCL functions. Categories:
- Logical: IF, AND, OR, CASE
- Null/NaN: ISNA, IFNA
- String concat / duration helpers (this file)
- Math (stdlib_math.go): ABS, ROUND, FLOOR, CEIL, TRUNC, MOD, POW, SQRT, LN, LOG, LOG10, EXP, SIGN
- String (stdlib_string.go): LEN, UPPER, LOWER, TRIM/L/RTRIM, LEFT, RIGHT, MID/SUBSTR, REPLACE, FIND, CONTAINS, STARTSWITH, ENDSWITH, REGEX_MATCH, REPEAT
- Type conversion (stdlib_typeconv.go): TONUM/VALUE, TOSTR/TEXT, TOBOOL, COALESCE, IFNULL
- Date components (stdlib_datetime.go): YEAR, MONTH, DAYOFMONTH, WEEKDAY, DATEDIFF, DATEADD, FORMAT_DATE
- Aggregates: SUM, AVG, COUNT, MAX, MIN (this file) and MEDIAN, STDEV/STDEVP, VAR/VARP (stdlib_aggregates.go)
func ResetFuncCallDepth ¶
func ResetFuncCallDepth()
Types ¶
type CCLNode ¶ added in v0.2.9
type CCLNode = cclNode
CCLNode is the exported type alias for compiled CCL AST nodes. This allows external packages to store and reuse compiled formulas.
func CompileExpression ¶ added in v0.2.11
CompileExpression compiles a CCL expression string into an AST. It checks for forbidden syntax (assignment, NEW) for expression mode.
func CompileMultiline ¶ added in v0.2.11
CompileMultiline compiles a multi-line CCL script into a list of AST nodes. It splits the script by ';' or newline and compiles each statement individually.
type ColumnRange ¶ added in v0.2.11
ColumnRange represents a range of column indices [Start, End]
type Context ¶ added in v0.2.11
type Context interface {
// GetCol returns the value of the column at the given index for the current row.
GetCol(index int) any
// GetColByName returns the value of the column with the given name for the current row.
GetColByName(name string) (any, error)
// GetRowIndex returns the index of the current row.
GetRowIndex() int
// GetCurrentRow returns the current row data (e.g., as []any or map).
// This is used for the @ operator.
GetCurrentRow() any
// GetCell returns the value at the specified column index and row index.
// Used for the . operator (e.g., A.prev).
GetCell(colIndex, rowIndex int) (any, error)
// GetCellByName returns the value at the specified column name and row index.
// Used for the . operator (e.g., 'Col'.prev).
GetCellByName(colName string, rowIndex int) (any, error)
// GetRowAt returns the row data at the specified row index.
// Used for @.prev.
GetRowAt(rowIndex int) (any, error)
// GetRowIndexByName returns the index of the row with the given name.
// Used for row name references in the . operator.
GetRowIndexByName(rowName string) (int, error)
// GetColData returns the entire data of the column at the given index.
// Used for aggregate functions.
GetColData(index int) ([]any, error)
// GetColDataByName returns the entire data of the column with the given name.
// Used for aggregate functions.
GetColDataByName(name string) ([]any, error)
// GetColIndexByName returns the index of the column with the given name.
GetColIndexByName(colName string) (int, error)
// GetColCount returns the total number of columns in the context.
GetColCount() int
// GetRowCount returns the total number of rows in the context.
GetRowCount() int
// SetRowIndex sets the current row index for the context.
// This is used for iterating over rows during aggregation of complex expressions.
SetRowIndex(index int) error
// GetAllData returns all data in the context as a single flattened slice.
// This is used for the @ operator in aggregate functions (e.g., SUM(@)).
GetAllData() ([]any, error)
}
Context defines the interface for data access in CCL. Implement this interface to allow CCL to operate on your custom data structures.
type EvaluationResult ¶ added in v0.2.9
type EvaluationResult struct {
Value any // The computed value (for expressions)
IsAssignment bool // Whether this was an assignment
Target string // Assignment target column (if IsAssignment)
IsNewCol bool // Whether this creates a new column
NewColName string // New column name (if IsNewCol)
}
EvaluationResult represents the result of evaluating a CCL statement
func EvaluateStatement ¶ added in v0.2.9
func EvaluateStatement(n cclNode, ctx Context) (*EvaluationResult, error)
EvaluateStatement evaluates a CCL statement and returns detailed result
type MapContext ¶ added in v0.2.11
type MapContext struct {
Data map[string][]any
Rows int
CurrentRowIdx int
ColNameMap map[string]int // Optional: if we want to support index access, we need an order
ColNames []string // To support index access
}
MapContext implements Context for a map of columns (map[string][]any). This allows using CCL with native Go maps and slices.
func NewMapContext ¶ added in v0.2.11
func NewMapContext(data map[string][]any) (*MapContext, error)
NewMapContext creates a new MapContext from a map of columns.
func (*MapContext) GetAllData ¶ added in v0.2.11
func (c *MapContext) GetAllData() ([]any, error)
func (*MapContext) GetCell ¶ added in v0.2.11
func (c *MapContext) GetCell(colIndex, rowIndex int) (any, error)
func (*MapContext) GetCellByName ¶ added in v0.2.11
func (c *MapContext) GetCellByName(colName string, rowIndex int) (any, error)
func (*MapContext) GetCol ¶ added in v0.2.11
func (c *MapContext) GetCol(index int) any
func (*MapContext) GetColByName ¶ added in v0.2.11
func (c *MapContext) GetColByName(name string) (any, error)
func (*MapContext) GetColCount ¶ added in v0.2.11
func (c *MapContext) GetColCount() int
func (*MapContext) GetColData ¶ added in v0.2.11
func (c *MapContext) GetColData(index int) ([]any, error)
func (*MapContext) GetColDataByName ¶ added in v0.2.11
func (c *MapContext) GetColDataByName(name string) ([]any, error)
func (*MapContext) GetColIndexByName ¶ added in v0.2.11
func (c *MapContext) GetColIndexByName(colName string) (int, error)
func (*MapContext) GetCurrentRow ¶ added in v0.2.11
func (c *MapContext) GetCurrentRow() any
func (*MapContext) GetRowAt ¶ added in v0.2.11
func (c *MapContext) GetRowAt(rowIndex int) (any, error)
func (*MapContext) GetRowCount ¶ added in v0.2.11
func (c *MapContext) GetRowCount() int
func (*MapContext) GetRowIndex ¶ added in v0.2.11
func (c *MapContext) GetRowIndex() int
func (*MapContext) GetRowIndexByName ¶ added in v0.2.11
func (c *MapContext) GetRowIndexByName(rowName string) (int, error)
func (*MapContext) SetRowIndex ¶ added in v0.2.11
func (c *MapContext) SetRowIndex(index int) error
type SeqFunc ¶ added in v0.2.18
SeqFunc is the signature for CCL sequence (window / lag / cumulative) functions. Unlike scalar functions (one row in, one value out) and aggregate functions (whole columns in, single value out broadcast back), sequence functions take whole columns and return a same-length column, enabling LAG, CUMSUM, ROLLING_MEAN, etc.