tdtl

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: Apache-2.0 Imports: 19 Imported by: 10

README

TQL

TKeel Query Language (TQL) is language in tKeel, which solves the problem:

  • define the entity(Digital Object)
  • define the relationship(Digital Object)
  • data transmission between entities

Documentation

Overview

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 The tKeel Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	UNDEFINED_RESULT = &JSONNode{datatype: Undefined}
	NULL_RESULT      = &JSONNode{datatype: Undefined}
)
View Source
var DefaultValue = &value{
	functions: map[string]ContextFunc{
		"abs":    absFunc,
		"base64": base64Func,
	},
}

DefaultValue default eval context

View Source
var EmptyBytes = []byte("")
View Source
var EvalCallExpr = func(ctx Context, expr *CallExpr) Node {
	return UNDEFINED_RESULT
}
View Source
var (
	JSONRaw = struct {
		SimpleJSON string
		JSON       string
		EventJSON  string
		EmptyJSON  string
	}{
		SimpleJSON: `{
			"YX_0002":1, "YX_0003":2,
			"color":"red", "temperature":50, 
			"metadata": {"name": "Light1", "price": 11.05}
		}`,
		JSON: `{
  			"name": {"first": "Tom", "last": "Anderson"},
  			"age":37, "temperature":50, 
  			"children": ["Sara","Alex","Jack"],
  			"fav.movie": "Deer Hunter",
  			"movie": {"1111": [{"1111": "Tom", "last": "Anderson"},{"first": "Neo"}], "last": "Anderson"},
  			"friends": [
  				{"first": "Dale", "last": "Murphy", "age": 44},
  				{"first": "Roger", "last": "Craig", "age": 68},
  				{"first": "Jane", "last": "Murphy", "age": 47}
  			]
		}`,
		EventJSON: `{
  			"id": "10000000000000000000000000DF0EF6",
  			"version": "1.0",
  			"params": {
	    		"Power": {
    	  		  "id": "10000000000000000000000000000001", //32
      			  "type": "text",
      			  "value": "on",
      		  	"time": 1524448722000
    			},
    			"Color": {
  	    		  "id": "10000000000000000000000000000001", //32
    	  		  "type": "text",
      			  "value": "red",
      			  "time": 1524448722000
    			},
    			"Temperature": {
  	    		  "id": "10000000000000000000000000000002", //32
    	  		  "type": "float",
      			  "value": 50.1,
      			  "time": 1524448722000
    			}
  			}
    	}`,
		EmptyJSON: `{}`,
	}
)
View Source
var SymbolicNames []string

Functions

func Byte

func Byte(raw string) []byte

func Combine

func Combine(cKey *Collect, cValue *Collect) ([]byte, error)

func Dump

func Dump(x Expr) error

Print prints x to standard output, skipping nil fields. Print(fset, x) is the same as Fprint(os.Stdout, fset, x, NotNilFilter).

func DumpMore

func DumpMore(x ...Expr) error

func EvalFilter

func EvalFilter(ctx Context, expr Expr) bool

func Fprint

func Fprint(w io.Writer, x Expr) error

Fprint prints the (sub-)tree starting at AST node x to w. If fset != nil, position information is interpreted relative to that file set. Otherwise positions are printed as integer values (file set specific offsets).

A non-nil FieldFilter f may be provided to control the output: struct fields for which f(fieldname, fieldvalue) is true are printed; all others are filtered from the output. Unexported struct fields are never printed.

func GetTopic

func GetTopic(expr Expr) (string, bool)

func HasDimensions

func HasDimensions(expr Expr) bool

Types

type BinaryExpr

type BinaryExpr struct {
	Op  int
	LHS Expr
	RHS Expr
}

BinaryExpr

type BoolNode

type BoolNode bool

func (BoolNode) Error

func (r BoolNode) Error() error

func (BoolNode) Raw

func (r BoolNode) Raw() []byte

func (BoolNode) String

func (r BoolNode) String() string

func (BoolNode) To

func (r BoolNode) To(typ Type) Node

func (BoolNode) Type

func (r BoolNode) Type() Type

type By

type By func(p1, p2 *Collect) bool

By is the type of a "less" function that defines the ordering of its Planet arguments.

func (By) Sort

func (by By) Sort(collects []*Collect)

Sort is a method on the function type, By, that sorts the argument slice according to the function.

type CallExpr

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

CallExpr

func ParseFunc

func ParseFunc(x Expr) []*CallExpr

func (*CallExpr) Args

func (e *CallExpr) Args() []Expr

func (*CallExpr) FuncName

func (e *CallExpr) FuncName() string

func (*CallExpr) String

func (e *CallExpr) String() string

type CaseExpr

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

CaseExpr

type CaseListExpr

type CaseListExpr []*CaseExpr

CaseListExpr

type Collect

type Collect = JSONNode

func New

func New(raw interface{}) *Collect

func NewBool added in v0.1.4

func NewBool(raw bool) *Collect

func NewFloat64 added in v0.1.4

func NewFloat64(raw float64) *Collect

func NewInt64 added in v0.1.4

func NewInt64(raw int64) *Collect

func NewString added in v0.1.4

func NewString(raw string) *Collect

func (*Collect) Append

func (cc *Collect) Append(path string, value Node)

func (*Collect) Copy

func (cc *Collect) Copy() *JSONNode

func (*Collect) Del

func (cc *Collect) Del(path ...string)

func (*Collect) Foreach

func (cc *Collect) Foreach(fn ForeachHandle)

func (*Collect) Get

func (cc *Collect) Get(path ...string) *Collect

func (*Collect) GetError

func (cc *Collect) GetError() error

GetError returns collect error.

func (*Collect) GroupBy

func (cc *Collect) GroupBy(path string) *Collect

func (*Collect) KeyBy

func (c *Collect) KeyBy(path string) *Collect

func (*Collect) Map

func (cc *Collect) Map(handle MapHandle)

func (*Collect) Merge

func (cc *Collect) Merge(mc *Collect) *Collect

func (*Collect) MergeBy

func (c *Collect) MergeBy(paths ...string) *Collect

func (*Collect) Node

func (cc *Collect) Node() Node

func (*Collect) Set

func (cc *Collect) Set(path string, value Node)

func (*Collect) SortBy

func (cc *Collect) SortBy(fn func(p1 *Collect, p2 *Collect) bool)

type Context

type Context interface {
	ContextValuable
	ContextCallable
}

Context eval context

func NewJSONContext

func NewJSONContext(jsonRaw string) Context

NewJSONContext new context from json

func NewMapContext

func NewMapContext(values map[string]Node, functions map[string]ContextFunc) Context

NewMapContext new context from map

type ContextCallable

type ContextCallable interface {
	Call(expr *CallExpr, args []Node) Node
}

ContextCallable eval context function

type ContextCallable interface {
	Call(key string, args []Node) Node
}

type ContextCallableFunc

type ContextCallableFunc func(args ...Node) Node

type ContextFunc

type ContextFunc func(args ...Node) Node

ContextFunc eval context function

type ContextValuable

type ContextValuable interface {
	Value(key string) Node
}

ContextValuable eval context

type DimensionExpr

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

type DimensionsExpr

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

GroupExpr

type Expr

type Expr interface {
	// contains filtered or unexported methods
}

Expr

func Parse

func Parse(expr string) (Expr, error)

func ParseExpr

func ParseExpr(expr string) (Expr, error)

func ParseField

func ParseField(expr string) (Expr, error)

func ParseFilter

func ParseFilter(expr string) (Expr, error)

type FieldExpr

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

FieldExpr

func (*FieldExpr) String

func (r *FieldExpr) String() string

type FieldsExpr

type FieldsExpr []*FieldExpr

FieldExpr

func (FieldsExpr) String

func (r FieldsExpr) String() string

type FilterExpr

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

FilterExpr

func (*FilterExpr) String

func (r *FilterExpr) String() string

type FloatNode

type FloatNode float64

func (FloatNode) Error

func (r FloatNode) Error() error

func (FloatNode) Raw

func (r FloatNode) Raw() []byte

func (FloatNode) String

func (r FloatNode) String() string

func (FloatNode) To

func (r FloatNode) To(typ Type) Node

func (FloatNode) Type

func (r FloatNode) Type() Type

type ForeachHandle

type ForeachHandle func(key []byte, value *Collect)

type IntNode

type IntNode int64

func (IntNode) Error

func (r IntNode) Error() error

func (IntNode) Raw

func (r IntNode) Raw() []byte

func (IntNode) String

func (r IntNode) String() string

func (IntNode) To

func (r IntNode) To(typ Type) Node

func (IntNode) Type

func (r IntNode) Type() Type

type JSONNode

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

JSONNode maybe Object or Array

func (JSONNode) Error

func (r JSONNode) Error() error

func (JSONNode) Raw

func (r JSONNode) Raw() []byte

func (JSONNode) String

func (r JSONNode) String() string

func (JSONNode) To

func (cc JSONNode) To(typ Type) Node

func (JSONNode) Type

func (r JSONNode) Type() Type

type JSONPathExpr

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

JSONPathExpr xpath

type MapHandle

type MapHandle func(key []byte, value *Collect) Node

type MutilContext

type MutilContext []Context

MutilContext mutil-context

func (MutilContext) Call

func (mc MutilContext) Call(expr *CallExpr, args []Node) Node

Call call function from context

func (MutilContext) Value

func (mc MutilContext) Value(key string) Node

Value get value from context

type Node

type Node interface {
	Type() Type
	To(Type) Node
	Raw() []byte
	String() string
	Error() error
}

Node interface

func EvalRuleQL

func EvalRuleQL(ctx Context, expr Expr) Node

func EvalSelect

func EvalSelect(ctx Context, expr Expr) Node

type Result

type Result = gjson.Result

result represents a json value that is returned from Get().

type SelectStatementExpr

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

SelectStatementExpr

func (*SelectStatementExpr) String

func (r *SelectStatementExpr) String() string

type SortHandle

type SortHandle func(p1 *Collect, p2 *Collect) bool

type StringNode

type StringNode string

func (StringNode) Error

func (r StringNode) Error() error

func (StringNode) Raw

func (r StringNode) Raw() []byte

func (StringNode) String

func (r StringNode) String() string

func (StringNode) To

func (r StringNode) To(typ Type) Node

func (StringNode) Type

func (r StringNode) Type() Type

type SwitchExpr

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

SwitchExpr

type TDTL

type TDTL interface {
	Target() string
	Entities() map[string][]string
	Fields() map[string]string
	Exec(map[string]Node) (map[string]Node, error)
}

func NewTDTL

func NewTDTL(sql string, extFunc map[string]ContextFunc) (TDTL, error)

type TDTLListener

type TDTLListener struct {
	*parser.BaseTDTLListener
	// contains filtered or unexported fields
}

TDTLListener construct expr

func (*TDTLListener) ExitBinary

func (l *TDTLListener) ExitBinary(c *parser.BinaryContext)

func (*TDTLListener) ExitBoolean

func (l *TDTLListener) ExitBoolean(c *parser.BooleanContext)

func (*TDTLListener) ExitCall_expr

func (l *TDTLListener) ExitCall_expr(c *parser.Call_exprContext)

func (*TDTLListener) ExitDotnotation

func (l *TDTLListener) ExitDotnotation(c *parser.DotnotationContext)

func (*TDTLListener) ExitFieldElemAs

func (l *TDTLListener) ExitFieldElemAs(c *parser.FieldElemAsContext)

func (*TDTLListener) ExitFieldElemExpr

func (l *TDTLListener) ExitFieldElemExpr(c *parser.FieldElemExprContext)

ExitFieldElemExpr

func (*TDTLListener) ExitFieldElemSource

func (l *TDTLListener) ExitFieldElemSource(c *parser.FieldElemSourceContext)

func (*TDTLListener) ExitFields

func (l *TDTLListener) ExitFields(c *parser.FieldsContext)

ExitFields construct fields from select statement

func (*TDTLListener) ExitFilter_condition

func (l *TDTLListener) ExitFilter_condition(c *parser.Filter_conditionContext)

func (*TDTLListener) ExitFilter_condition_not

func (l *TDTLListener) ExitFilter_condition_not(c *parser.Filter_condition_notContext)

func (*TDTLListener) ExitFilter_condition_or

func (l *TDTLListener) ExitFilter_condition_or(c *parser.Filter_condition_orContext)

func (*TDTLListener) ExitFloat

func (l *TDTLListener) ExitFloat(c *parser.FloatContext)

func (*TDTLListener) ExitIdentifierWithQualifier

func (l *TDTLListener) ExitIdentifierWithQualifier(c *parser.IdentifierWithQualifierContext)

func (*TDTLListener) ExitIdentifierWithTOPICITEM

func (l *TDTLListener) ExitIdentifierWithTOPICITEM(c *parser.IdentifierWithTOPICITEMContext)

func (*TDTLListener) ExitInteger

func (l *TDTLListener) ExitInteger(c *parser.IntegerContext)

func (*TDTLListener) ExitRoot

func (l *TDTLListener) ExitRoot(c *parser.RootContext)

func (*TDTLListener) ExitString

func (l *TDTLListener) ExitString(c *parser.StringContext)

func (*TDTLListener) ExitSwitch_stmt

func (l *TDTLListener) ExitSwitch_stmt(c *parser.Switch_stmtContext)

func (*TDTLListener) ExitTarget

func (l *TDTLListener) ExitTarget(c *parser.TargetContext)

ExitTarget construct target entity from select statement

func (*TDTLListener) ExitTargetAsElem

func (l *TDTLListener) ExitTargetAsElem(c *parser.TargetAsElemContext)

func (*TDTLListener) ExitXpath_name

func (l *TDTLListener) ExitXpath_name(c *parser.Xpath_nameContext)

func (*TDTLListener) Expr

func (l *TDTLListener) Expr() Expr

Expr expr

func (*TDTLListener) ReportAmbiguity

func (l *TDTLListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs antlr.ATNConfigSet)

func (*TDTLListener) ReportAttemptingFullContext

func (l *TDTLListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs antlr.ATNConfigSet)

func (*TDTLListener) ReportContextSensitivity

func (l *TDTLListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs antlr.ATNConfigSet)

func (*TDTLListener) SyntaxError

func (l *TDTLListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException)

type TopicExpr

type TopicExpr []string

TopicExpr

func (TopicExpr) String

func (r TopicExpr) String() string

type Type

type Type int

Type node type

const (
	// Undefine is Not a value
	// This isn't explicitly representable in JSON except by omitting the value.
	Undefined Type = iota
	// Null is a null json value
	Null
	// Bool is a json boolean
	Bool
	// Number is json number, include Int and Float
	Number
	// Int is json number, a discrete Int
	Int
	// Float is json number
	Float
	// String is a json string
	String
	// JSON is a raw block of JSON
	JSON
	// Object is a type of JSON
	Object
	// Array is a type of JSON
	Array
)

func (Type) String

func (t Type) String() string

String returns a string representation of the type.

type WindowExpr

type WindowExpr struct {
	WindowType WindowType
	Length     WindowLength
	Interval   WindowInterval
}

func GetWindow

func GetWindow(expr Expr) *WindowExpr

type WindowInterval

type WindowInterval int

type WindowLength

type WindowLength int

type WindowType

type WindowType int
const (
	NOT_WINDOW WindowType = iota
	TUMBLING_WINDOW
	HOPPING_WINDOW
	SLIDING_WINDOW
	SESSION_WINDOW
)

Directories

Path Synopsis
pkg
json/gjson
Package gjson provides searching for json strings.
Package gjson provides searching for json strings.
json/sjson
Package sjson provides setting json values.
Package sjson provides setting json values.

Jump to

Keyboard shortcuts

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