Documentation
¶
Index ¶
- Constants
- Variables
- func AsChan(ctx context.Context, it NIter, n Node, concurrency int, recvC chan<- *N) error
- func AsUnaryArgUnaryRetNodeDataFunction(f func(*OP) (*OP, error)) func(ND) (ND, error)
- func AsVariadicArgUnaryRetNodeDataFunction(f func(...*OP) (*OP, error)) func(...ND) (ND, error)
- func MapNodeDataFunction(name string, f NodeDataMapper) func(*N) (*N, error)
- func NodeAsEnviron(n *N) []string
- func NodeAsStructuredMap(n *N) map[string]any
- func ValidateOnlyVariadicOrAllUnaryRet(fs ...NFunction) error
- type ExprGenTemplate
- type GenTemplate
- type Key
- type LuaGenTemplate
- type N
- type ND
- type NDFanoutFunction
- type NDFunction
- type NDIter
- type NDMapFunction
- type NDMultiMapFunction
- type NDReduceFunction
- type NFanoutFunction
- type NFunction
- type NIter
- type NMapFunction
- type NMultiMapFunction
- type NReduceFunction
- type NodeDataMapper
- type NodeOpMapper
- type OP
- type RegexpGenTemplate
- type ShellGenTemplate
- type StringGenTemplate
- type TreeVisitor
- func (v TreeVisitor) Visit(n Node) (NFunction, error)
- func (v TreeVisitor) VisitBetweenExpr(n *BetweenExpr) (NFunction, error)
- func (v TreeVisitor) VisitBinaryOperationExpr(n *BinaryOperationExpr) (NFunction, error)
- func (v TreeVisitor) VisitCaseExpr(n *CaseExpr) (NFunction, error)
- func (TreeVisitor) VisitColumnName(n *ColumnName) *Key
- func (v TreeVisitor) VisitColumnNameExpr(n *ColumnNameExpr) (NFunction, error)
- func (v TreeVisitor) VisitExpr(n ExprNode) (NFunction, error)
- func (v TreeVisitor) VisitFieldList(n *FieldList) (NFunction, error)
- func (v TreeVisitor) VisitFuncCallExpr(n *FuncCallExpr) (NFunction, error)
- func (v TreeVisitor) VisitIsNullExpr(n *IsNullExpr) (NFunction, error)
- func (v TreeVisitor) VisitIsTruthExpr(n *IsTruthExpr) (NFunction, error)
- func (v TreeVisitor) VisitJoin(n *Join) (NFunction, error)
- func (v TreeVisitor) VisitParenthesesExpr(n *ParenthesesExpr) (NFunction, error)
- func (v TreeVisitor) VisitParrernLikeExpr(n *PatternLikeOrIlikeExpr) (NFunction, error)
- func (v TreeVisitor) VisitPatternInExpr(n *PatternInExpr) (NFunction, error)
- func (v TreeVisitor) VisitPatternRegexpExpr(n *PatternRegexpExpr) (NFunction, error)
- func (v TreeVisitor) VisitSelectField(n *SelectField) (NFunction, error)
- func (v TreeVisitor) VisitSelectStmt(n *SelectStmt) (NFunction, error)
- func (v TreeVisitor) VisitTableRefsClause(n *TableRefsClause) (NFunction, error)
- func (v TreeVisitor) VisitTableSource(n *TableSource) (NFunction, error)
- func (v TreeVisitor) VisitUnaryOperationExpr(n *UnaryOperationExpr) (NFunction, error)
- func (v TreeVisitor) VisitValueExpr(n ValueExpr) (NFunction, error)
- func (v TreeVisitor) VisitValueExprDriver(n *driver.ValueExpr) (ND, error)
- func (v TreeVisitor) VisitWhere(n ExprNode) (NFunction, error)
- type ValueContainer
Constants ¶
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" FuncRegexpCount = "regexp_count" 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" FuncInstrCount = "instr_count" 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" )
const ( InputTableName = "input" TableKeySeparator = "___" NodeValueKey = "___value___" )
const (
FuncArgMaxLen = 100
)
Variables ¶
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 MapNodeDataFunction ¶
func MapNodeDataFunction(name string, f NodeDataMapper) func(*N) (*N, error)
func NodeAsEnviron ¶
func NodeAsStructuredMap ¶
Types ¶
type ExprGenTemplate ¶
type ExprGenTemplate struct {
// contains filtered or unexported fields
}
func NewExprGenTemplate ¶
func NewExprGenTemplate(expr string) *ExprGenTemplate
type GenTemplate ¶
type GenTemplate interface {
// @title Generator
// @path syntax.generator
// @document
// A function that generates a new node from a node is called a generator.
// It 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 LuaGenTemplate ¶
type LuaGenTemplate struct {
// contains filtered or unexported fields
}
func NewLuaGenTemplate ¶
func NewLuaGenTemplate(script, entrypoint string) *LuaGenTemplate
type NDFanoutFunction ¶
type NDFanoutFunction = iterx.FanoutFunction[ND]
type NDFunction ¶
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 NMapFunction ¶
type NMapFunction = iterx.MapFunction[*N]
type NMultiMapFunction ¶
type NMultiMapFunction = iterx.MultiMapFunction[*N]
type NReduceFunction ¶
type NReduceFunction = iterx.ReduceFunction[*N]
type NodeDataMapper ¶
func NodeOpMapperAsData ¶
func NodeOpMapperAsData(f NodeOpMapper) NodeDataMapper
type NodeOpMapper ¶
func NodeDataMapperAsOP ¶
func NodeDataMapperAsOP(f NodeDataMapper) NodeOpMapper
type RegexpGenTemplate ¶
type RegexpGenTemplate struct {
// contains filtered or unexported fields
}
func NewRegexpGenTemplate ¶
func NewRegexpGenTemplate(expr, tmpl string) *RegexpGenTemplate
type ShellGenTemplate ¶
type ShellGenTemplate struct {
// contains filtered or unexported fields
}
func NewShellGenTemplate ¶
func NewShellGenTemplate(text string) *ShellGenTemplate
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
type TreeVisitor ¶
type TreeVisitor struct {
// contains filtered or unexported fields
}
@title Syntax @path syntax @document `ndql` uses a SQL-based syntax.
## Implementation Status
- Statements: Currently, only the SELECT statement is implemented. - Clauses: FROM and WHERE clauses are available. Other clauses (e.g., GROUP BY, ORDER BY, JOIN) are not yet supported. - Operators, Functions: Some operators and functions are not yet implemented. Even if implemented, the behavior may differ from standard SQL specifications.
## Operators
- `AND` - `OR` - `XOR` - `+` (binary) - `-` (binary) - `*` - `/` - `%` - `<<` - `>>` - `<` - `<=` - `=` - `<>` - `>=` - `>` - `CASE` - `IS NULL` - `IS TRUE` - `IS FALSE` - `REGEXP` - `LIKE` - `BETWEEN` - `-` (unary) - `~`
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.
@title Functions @path syntax.functions @document - grep(pattern: String, template: String) -> []Node - tmpl(template: String) -> []Node - sh(script: String) -> []Node - lua(script: String, entrypoint: String) -> []Node - expr(expression: String) -> []Node - to_int(value) -> Int - to_float(value) -> Float - to_bool(value) -> Bool - to_string(value) -> String - to_time(value) -> Time - to_duration(value) -> Duration - least(value...) - greatest(value...) - coalesce(value...) - if(condition, then, else) - ifnull(expr1, expr2) - nullif(expr1, expr2) - abs(value: Float | Int) -> Float - sqrt(value: Float | Int) -> Float - degrees(value: Float | Int) -> Float - radians(value: Float | Int) -> Float - acos(value: Float | Int) -> Float - asin(value: Float | Int) -> Float - atan(value: Float | Int) -> Float - cos(value: Float | Int) -> Float - sin(value: Float | Int) -> Float - tan(value: Float | Int) -> Float - cot(value: Float | Int) -> Float - ln(value: Float | Int) -> Float - log2(value: Float | Int) -> Float - log10(value: Float | Int) -> Float - exp(value: Float | Int) -> Float - ceil(value: Float | Int) -> Float - floor(value: Float | Int) -> Float - round(value: Float | Int) -> Float - atan2(y: Float | Int, x: Float | Int) -> Float - pow(x: Float | Int, y: Float | Int) -> Float - e() -> Float - pi() -> Float - rand() -> Float - len(value: String) -> Int - size(value: String) -> Int - regexp_count(string: String, pattern: String) -> Int - regexp_instr(string: String, pattern: String) -> Int - regexp_substr(string: String, pattern: String) -> Int - regexp_replace(string: String, pattern: String, replacement: String) -> String - regexp_like(string: String, pattern: String) -> Bool - format(format: String, args...) -> String - lower(value: String) -> String - upper(value: String) -> String - sha2(value: String) -> String - concat_ws(separator: String, args...: []String) -> String - instr(string: String, sub: String) -> Int - instr_count(string: String, sub: String) -> Int - substr(string: String, position: Int) -> String - substr(string: String, position: Int, length: Int) -> String - replace(string: String, from: String, to: String) -> String - trim(string: String) -> String - trim(string: String, cutset: String) -> String - strtotime(string: String, format: String) -> Time - timeformat(t: Time, format: String) -> String - year(t: Time) -> int - month(t: Time) -> int - day(t: Time) -> int - hour(t: Time) -> int - minute(t: Time) -> int - second(t: Time) -> int - dayofweek(t: Time) -> int - dayofyear(t: Time) -> int - newtime(year: Int) -> Time - newtime(year: Int, month: Int) -> Time - newtime(year: Int, month: Int, day: Int) -> Time - newtime(year: Int, month: Int, day: Int, hour: Int) -> Time - newtime(year: Int, month: Int, day: Int, hour: Int, minute: Int) -> Time - newtime(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int) -> Time - sleep(second: Int | Float | Duration) -> Int - now() -> Time - dir(path: String) -> String - basename(path: String) -> String - extension(path: String) -> String - abspath(path: String) -> String - relpath(path: String, base: String) -> String - inverse(value: Float | Int) -> Float - inverse(value: String) -> String - env(name: String) -> String - envor(name: String, default: String) -> String
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)