tree

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FuncGrep = "grep"
	FuncTmpl = "tmpl"
	FuncSh   = "sh"
	FuncLua  = "lua"
	FuncExpr = "expr"

	FuncToInt      = "to_int"
	FuncToFloat    = "to_float"
	FuncToBool     = "to_bool"
	FuncToString   = "to_string"
	FuncToTime     = "to_time"
	FuncToDuration = "to_duration"

	FuncLeast    = "least"
	FuncGreatest = "greatest"
	FuncCoalesce = "coalesce"

	FuncIf     = "if"
	FuncIfNull = "ifnull"
	FuncNullIf = "nullif"

	FuncAbs     = "abs"
	FuncSqrt    = "sqrt"
	FuncDegrees = "degrees"
	FuncRadians = "radians"
	FuncAcos    = "acos"
	FuncAsin    = "asin"
	FuncAtan    = "atan"
	FuncCos     = "cos"
	FuncSin     = "sin"
	FuncTan     = "tan"
	FuncCot     = "cot"
	FuncLn      = "ln"
	FuncLog2    = "log2"
	FuncLog10   = "log10"
	FuncExp     = "exp"
	FuncCeil    = "ceil"
	FuncFloor   = "floor"
	FuncRound   = "round"
	FuncAtan2   = "atan2"
	FuncPow     = "pow"
	FuncE       = "e"
	FuncPi      = "pi"
	FuncRand    = "rand"

	FuncLen           = "len"
	FuncSize          = "size"
	FuncRegexpInstr   = "regexp_instr"
	FuncRegexpSubstr  = "regexp_substr"
	FuncRegexpReplace = "regexp_replace"
	FuncRegexpLike    = "regexp_like"
	FuncFormat        = "format"
	FuncLower         = "lower"
	FuncUpper         = "upper"
	FuncSha2          = "sha2"
	FuncConcatWs      = "concat_ws"
	FuncInstr         = "instr"
	FuncSubstr        = "substr"
	FuncSubstrIndex   = "substr_index"
	FuncReplace       = "replace"
	FuncTrim          = "trim"

	FuncStrToTime  = "strtotime"
	FuncTimeFormat = "timeformat"
	FuncYear       = "year"
	FuncMonth      = "month"
	FuncDay        = "day"
	FuncHour       = "hour"
	FuncMinute     = "minute"
	FuncSecond     = "second"
	FuncDayOfWeek  = "dayofweek"
	FuncDayOfYear  = "dayofyear"
	FuncNewTime    = "newtime"
	FuncSleep      = "sleep"
	FuncNow        = "now"

	FuncDir       = "dir"
	FuncBasename  = "basename"
	FuncExtension = "extension"
	FuncAbsPath   = "abspath"
	FuncRelPath   = "relpath"

	FuncInverse = "inverse"
	FuncEnvOr   = "envor"
	FuncEnv     = "env"
)
View Source
const (
	InputTableName    = "input"
	TableKeySeparator = "___"
	NodeValueKey      = "___value___"
)
View Source
const (
	FuncArgMaxLen = 100
)

Variables

View Source
var (
	ErrIgnore               = errors.New("Ignore")
	ErrNotImplmented        = errors.New("NotImplemented")
	ErrInvalidTree          = errors.New("InvalidTree")
	ErrInvalidKey           = errors.New("InvalidKey")
	ErrInvalidValue         = errors.New("InvalidValue")
	ErrInvalidArgument      = errors.New("InvalidArgument")
	ErrInvalidFunctionArity = errors.New("InvalidFunctionArity")
	ErrParseGenResult       = errors.New("ParseGenResult")
	ErrGenTemplate          = errors.New("GenTemplate")
)

Functions

func AsUnaryArgUnaryRetNodeDataFunction

func AsUnaryArgUnaryRetNodeDataFunction(f func(*OP) (*OP, error)) func(ND) (ND, error)

func AsVariadicArgUnaryRetNodeDataFunction

func AsVariadicArgUnaryRetNodeDataFunction(f func(...*OP) (*OP, error)) func(...ND) (ND, error)

func MapNodeDataFunction

func MapNodeDataFunction(name string, f NodeDataMapper) func(*N) (*N, error)

func NodeAsEnviron

func NodeAsEnviron(n *N) []string

func NodeAsStructuredMap

func NodeAsStructuredMap(n *N) map[string]any

func ValidateOnlyVariadicOrAllUnaryRet

func ValidateOnlyVariadicOrAllUnaryRet(fs ...NFunction) error

Types

type ExprGenTemplate

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

func NewExprGenTemplate

func NewExprGenTemplate(expr string) *ExprGenTemplate

func (ExprGenTemplate) Generate

func (g ExprGenTemplate) Generate(_ context.Context, n *N) ([]byte, error)

type GenTemplate

type GenTemplate interface {
	// Generate attributes for new nodes from an existing node.
	// The function must return a string in one of the following formats:
	//
	//   - An array of JSON objects
	//   - A single JSON object
	//   - An "equal pair" list
	//
	// The "equal pair" format is as follows:
	//
	//      key1=value11,key2=value12,...
	//      key1=value21,key2=value22,...
	//      ...
	//
	// This is equivalent to the following JSON structure:
	//
	//      [
	//        {"key1":"value11","key2":"value12",...},
	//        {"key1":"value21","key2":"value22",...},
	//        ...
	//      ]
	//
	// Each JSON object corresponds to a single node.
	// Note that nodes are not required to have the same set of keys.
	Generate(ctx context.Context, n *N) ([]byte, error)
}

type Key

type Key struct {
	Table  string
	Column string
}

func KeyFromName

func KeyFromName(s string) *Key

func KeyFromString

func KeyFromString(s string) *Key

func NewKey

func NewKey(table, column string) *Key

func (Key) Get

func (k Key) Get(n *N) (*N, bool)

func (Key) NFunction

func (k Key) NFunction() NFunction

func (Key) Name

func (k Key) Name() string

func (Key) String

func (k Key) String() string

type LuaGenTemplate

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

func NewLuaGenTemplate

func NewLuaGenTemplate(script, entrypoint string) *LuaGenTemplate

func (LuaGenTemplate) Generate

func (g LuaGenTemplate) Generate(ctx context.Context, n *N) ([]byte, error)

type N

type N = node.Node

func GenerateAndParse

func GenerateAndParse(ctx context.Context, n *N, g GenTemplate) ([]*N, error)

func ParseGenResult

func ParseGenResult(b []byte) ([]*N, error)

Parse the result of GenTemplate.Generate.

type ND

type ND = node.Data

type NDFanoutFunction

type NDFanoutFunction = iterx.FanoutFunction[ND]

type NDFunction

type NDFunction = iterx.Function[ND]

type NDIter

type NDIter = iter.Seq[ND]

type NDMapFunction

type NDMapFunction = iterx.MapFunction[ND]

type NDMultiMapFunction

type NDMultiMapFunction = iterx.MultiMapFunction[ND]

type NDReduceFunction

type NDReduceFunction = iterx.ReduceFunction[ND]

type NFanoutFunction

type NFanoutFunction = iterx.FanoutFunction[*N]

type NFunction

type NFunction = iterx.Function[*N]

func ReturnContainerValue

func ReturnContainerValue(name string, f func(ND) (ND, error)) NFunction

Create a function that converts a ValueContainer.

type NIter

type NIter = iter.Seq[*N]

func AsIter

func AsIter(ctx context.Context, it NIter, n Node) (NIter, error)

AsIter converts AST into a function and applies to the iterator.

type NMapFunction

type NMapFunction = iterx.MapFunction[*N]

type NMultiMapFunction

type NMultiMapFunction = iterx.MultiMapFunction[*N]

type NReduceFunction

type NReduceFunction = iterx.ReduceFunction[*N]

type NodeDataMapper

type NodeDataMapper = func(string, ND) (string, ND, error)

func NodeOpMapperAsData

func NodeOpMapperAsData(f NodeOpMapper) NodeDataMapper

type NodeOpMapper

type NodeOpMapper = func(string, *OP) (string, *OP, error)

func NodeDataMapperAsOP

func NodeDataMapperAsOP(f NodeDataMapper) NodeOpMapper

type OP

type OP = node.Op

type RegexpGenTemplate

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

func NewRegexpGenTemplate

func NewRegexpGenTemplate(expr, tmpl string) *RegexpGenTemplate

func (RegexpGenTemplate) Generate

func (g RegexpGenTemplate) Generate(_ context.Context, n *N) ([]byte, error)

type ShellGenTemplate

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

func NewShellGenTemplate

func NewShellGenTemplate(text string) *ShellGenTemplate

func (ShellGenTemplate) Generate

func (g ShellGenTemplate) Generate(ctx context.Context, n *N) ([]byte, error)

type StringGenTemplate

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

### envor os.Getenv with default value, like 'envor "KEY" "default_value"'.

func NewStringGenTemplate

func NewStringGenTemplate(text string) *StringGenTemplate

func (StringGenTemplate) Generate

func (g StringGenTemplate) Generate(_ context.Context, n *N) ([]byte, error)

type TreeVisitor

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

func NewTreeVisitor

func NewTreeVisitor(ctx context.Context) *TreeVisitor

func (TreeVisitor) Visit

func (v TreeVisitor) Visit(n Node) (NFunction, error)

func (TreeVisitor) VisitBetweenExpr

func (v TreeVisitor) VisitBetweenExpr(n *BetweenExpr) (NFunction, error)

func (TreeVisitor) VisitBinaryOperationExpr

func (v TreeVisitor) VisitBinaryOperationExpr(n *BinaryOperationExpr) (NFunction, error)

func (TreeVisitor) VisitCaseExpr

func (v TreeVisitor) VisitCaseExpr(n *CaseExpr) (NFunction, error)

func (TreeVisitor) VisitColumnName

func (TreeVisitor) VisitColumnName(n *ColumnName) *Key

func (TreeVisitor) VisitColumnNameExpr

func (v TreeVisitor) VisitColumnNameExpr(n *ColumnNameExpr) (NFunction, error)

func (TreeVisitor) VisitExpr

func (v TreeVisitor) VisitExpr(n ExprNode) (NFunction, error)

func (TreeVisitor) VisitFieldList

func (v TreeVisitor) VisitFieldList(n *FieldList) (NFunction, error)

func (TreeVisitor) VisitFuncCallExpr

func (v TreeVisitor) VisitFuncCallExpr(n *FuncCallExpr) (NFunction, error)

Function calls except aggregations.

func (TreeVisitor) VisitIsNullExpr

func (v TreeVisitor) VisitIsNullExpr(n *IsNullExpr) (NFunction, error)

IS NULL, IS NOT NULL

func (TreeVisitor) VisitIsTruthExpr

func (v TreeVisitor) VisitIsTruthExpr(n *IsTruthExpr) (NFunction, error)

IS TRUE, IS FALSE

func (TreeVisitor) VisitJoin

func (v TreeVisitor) VisitJoin(n *Join) (NFunction, error)

func (TreeVisitor) VisitParenthesesExpr

func (v TreeVisitor) VisitParenthesesExpr(n *ParenthesesExpr) (NFunction, error)

(EXPR)

func (TreeVisitor) VisitParrernLikeExpr

func (v TreeVisitor) VisitParrernLikeExpr(n *PatternLikeOrIlikeExpr) (NFunction, error)

LIKE

func (TreeVisitor) VisitPatternInExpr

func (v TreeVisitor) VisitPatternInExpr(n *PatternInExpr) (NFunction, error)

BETWEEN ... AND ...

func (TreeVisitor) VisitPatternRegexpExpr

func (v TreeVisitor) VisitPatternRegexpExpr(n *PatternRegexpExpr) (NFunction, error)

REGEXP

func (TreeVisitor) VisitSelectField

func (v TreeVisitor) VisitSelectField(n *SelectField) (NFunction, error)

func (TreeVisitor) VisitSelectStmt

func (v TreeVisitor) VisitSelectStmt(n *SelectStmt) (NFunction, error)

func (TreeVisitor) VisitTableRefsClause

func (v TreeVisitor) VisitTableRefsClause(n *TableRefsClause) (NFunction, error)

func (TreeVisitor) VisitTableSource

func (v TreeVisitor) VisitTableSource(n *TableSource) (NFunction, error)

func (TreeVisitor) VisitUnaryOperationExpr

func (v TreeVisitor) VisitUnaryOperationExpr(n *UnaryOperationExpr) (NFunction, error)

func (TreeVisitor) VisitValueExpr

func (v TreeVisitor) VisitValueExpr(n ValueExpr) (NFunction, error)

func (TreeVisitor) VisitValueExprDriver

func (v TreeVisitor) VisitValueExprDriver(n *driver.ValueExpr) (ND, error)

func (TreeVisitor) VisitWhere

func (v TreeVisitor) VisitWhere(n ExprNode) (NFunction, error)

type ValueContainer

type ValueContainer struct {
	*N
}

A single value as a Node.

func AsValueContainer

func AsValueContainer(n *N) *ValueContainer

func (*ValueContainer) GetContainerValue

func (c *ValueContainer) GetContainerValue() (ND, bool)

func (*ValueContainer) GetFirstValue

func (c *ValueContainer) GetFirstValue() (string, ND, bool)

GetFirstValue unwraps the value. Returns the key, value and exists value or not.

func (*ValueContainer) SetContainerValue

func (c *ValueContainer) SetContainerValue(v ND)

Jump to

Keyboard shortcuts

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