eval

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package eval contains functions and classes used for evaluating Go expressions used in Capillaries scripts

Index

Constants

This section is empty.

Variables

View Source
var GolangConstants = map[string]any{
	"time.January":   time.January,
	"time.February":  time.February,
	"time.March":     time.March,
	"time.April":     time.April,
	"time.May":       time.May,
	"time.June":      time.June,
	"time.July":      time.July,
	"time.August":    time.August,
	"time.September": time.September,
	"time.October":   time.October,
	"time.November":  time.November,
	"time.December":  time.December,
	"time.UTC":       time.UTC}

Functions

func DetectRootAggFunc added in v1.1.4

func DetectRootAggFunc(exp ast.Expr) (AggEnabledType, AggFuncType, []ast.Expr)

func GetAggStringSeparator added in v1.1.4

func GetAggStringSeparator(aggFuncArgs []ast.Expr) (string, error)

Types

type AggDataType

type AggDataType string
const (
	AggTypeUnknown AggDataType = "unknown"
	AggTypeInt     AggDataType = "int"
	AggTypeFloat   AggDataType = "float"
	AggTypeDec     AggDataType = "decimal"
	AggTypeString  AggDataType = "string"
)

type AggEnabledType

type AggEnabledType int
const (
	AggFuncDisabled AggEnabledType = iota
	AggFuncEnabled
)

type AggFuncType

type AggFuncType string
const (
	AggStringAgg AggFuncType = "string_agg"
	AggSum       AggFuncType = "sum"
	AggCount     AggFuncType = "count"
	AggAvg       AggFuncType = "avg"
	AggMin       AggFuncType = "min"
	AggMax       AggFuncType = "max"
	AggUnknown   AggFuncType = "unknown"
)

func StringToAggFunc

func StringToAggFunc(testString string) AggFuncType

type AvgCollector

type AvgCollector struct {
	Int   int64
	Float float64
	Dec   decimal.Decimal
	Count int64
}

type EvalCtx

type EvalCtx struct {
	Vars       *VarValuesMap
	AggFunc    AggFuncType
	AggType    AggDataType
	AggCallExp *ast.CallExpr
	Count      int64
	StringAgg  StringAggCollector
	Sum        SumCollector
	Avg        AvgCollector
	Min        MinCollector
	Max        MaxCollector
	Value      any
	AggEnabled AggEnabledType
}

func NewPlainEvalCtx

func NewPlainEvalCtx(aggEnabled AggEnabledType) EvalCtx

func NewPlainEvalCtxAndInitializedAgg added in v1.1.4

func NewPlainEvalCtxAndInitializedAgg(aggEnabled AggEnabledType, aggFuncType AggFuncType, aggFuncArgs []ast.Expr) (*EvalCtx, error)

func NewPlainEvalCtxWithVars

func NewPlainEvalCtxWithVars(aggEnabled AggEnabledType, vars *VarValuesMap) EvalCtx

func NewPlainEvalCtxWithVarsAndInitializedAgg added in v1.1.4

func NewPlainEvalCtxWithVarsAndInitializedAgg(aggEnabled AggEnabledType, vars *VarValuesMap, aggFuncType AggFuncType, aggFuncArgs []ast.Expr) (*EvalCtx, error)

func (*EvalCtx) CallAggAvg

func (eCtx *EvalCtx) CallAggAvg(callExp *ast.CallExpr, args []any) (any, error)

func (*EvalCtx) CallAggCount

func (eCtx *EvalCtx) CallAggCount(callExp *ast.CallExpr, args []any) (any, error)

func (*EvalCtx) CallAggMax

func (eCtx *EvalCtx) CallAggMax(callExp *ast.CallExpr, args []any) (any, error)

func (*EvalCtx) CallAggMin

func (eCtx *EvalCtx) CallAggMin(callExp *ast.CallExpr, args []any) (any, error)

func (*EvalCtx) CallAggStringAgg added in v1.1.4

func (eCtx *EvalCtx) CallAggStringAgg(callExp *ast.CallExpr, args []any) (any, error)

func (*EvalCtx) CallAggSum

func (eCtx *EvalCtx) CallAggSum(callExp *ast.CallExpr, args []any) (any, error)

func (*EvalCtx) Eval

func (eCtx *EvalCtx) Eval(exp ast.Expr) (any, error)

func (*EvalCtx) EvalBinaryBool

func (eCtx *EvalCtx) EvalBinaryBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalBinaryBoolToBool

func (eCtx *EvalCtx) EvalBinaryBoolToBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalBinaryDecimal2

func (eCtx *EvalCtx) EvalBinaryDecimal2(valLeftVolatile any, op token.Token, valRightVolatile any) (result decimal.Decimal, err error)

func (*EvalCtx) EvalBinaryDecimal2ToBool

func (eCtx *EvalCtx) EvalBinaryDecimal2ToBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalBinaryFloat64

func (eCtx *EvalCtx) EvalBinaryFloat64(valLeftVolatile any, op token.Token, valRightVolatile any) (float64, error)

func (*EvalCtx) EvalBinaryFloat64ToBool

func (eCtx *EvalCtx) EvalBinaryFloat64ToBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalBinaryInt

func (eCtx *EvalCtx) EvalBinaryInt(valLeftVolatile any, op token.Token, valRightVolatile any) (result int64, finalErr error)

func (*EvalCtx) EvalBinaryIntToBool

func (eCtx *EvalCtx) EvalBinaryIntToBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalBinaryString

func (eCtx *EvalCtx) EvalBinaryString(valLeftVolatile any, op token.Token, valRightVolatile any) (string, error)

func (*EvalCtx) EvalBinaryStringToBool

func (eCtx *EvalCtx) EvalBinaryStringToBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalBinaryTimeToBool

func (eCtx *EvalCtx) EvalBinaryTimeToBool(valLeftVolatile any, op token.Token, valRightVolatile any) (bool, error)

func (*EvalCtx) EvalFunc

func (eCtx *EvalCtx) EvalFunc(callExp *ast.CallExpr, funcName string, args []any) (any, error)

func (*EvalCtx) EvalUnaryBoolNot

func (eCtx *EvalCtx) EvalUnaryBoolNot(exp ast.Expr) (bool, error)

func (*EvalCtx) EvalUnaryMinus

func (eCtx *EvalCtx) EvalUnaryMinus(exp ast.Expr) (any, error)

type MaxCollector

type MaxCollector struct {
	Int   int64
	Float float64
	Dec   decimal.Decimal
	Str   string
	Count int64
}

type MinCollector

type MinCollector struct {
	Int   int64
	Float float64
	Dec   decimal.Decimal
	Str   string
	Count int64
}

type StringAggCollector added in v1.1.4

type StringAggCollector struct {
	Sb        strings.Builder
	Separator string
}

type SumCollector

type SumCollector struct {
	Int   int64
	Float float64
	Dec   decimal.Decimal
}

type VarValuesMap

type VarValuesMap map[string]map[string]any

func (*VarValuesMap) Names

func (vars *VarValuesMap) Names() string

func (*VarValuesMap) Tables

func (vars *VarValuesMap) Tables() string

Jump to

Keyboard shortcuts

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