ast

package
v2.0.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultStream = StreamName("$$default")
	AliasStream   = StreamName("$$alias")
)
View Source
const (
	StreamKindLookup = "lookup"
	StreamKindScan   = "scan"
)
View Source
const (
	RowkindInsert = "insert"
	RowkindUpdate = "update"
	RowkindUpsert = "upsert"
	RowkindDelete = "delete"
)
View Source
const (
	SELECT_LIT = "SELECT"
	CREATE     = "CREATE"
	DROP       = "DROP"
	EXPLAIN    = "EXPLAIN"
	DESCRIBE   = "DESCRIBE"
	SHOW       = "SHOW"
	STREAM     = "STREAM"
	TABLE      = "TABLE"
	STREAMS    = "STREAMS"
	TABLES     = "TABLES"
	WITH       = "WITH"

	DATASOURCE        = "DATASOURCE"
	KEY               = "KEY"
	FORMAT            = "FORMAT"
	CONF_KEY          = "CONF_KEY"
	TYPE              = "TYPE"
	STRICT_VALIDATION = "STRICT_VALIDATION"
	TIMESTAMP         = "TIMESTAMP"
	TIMESTAMP_FORMAT  = "TIMESTAMP_FORMAT"
	RETAIN_SIZE       = "RETAIN_SIZE"
	SHARED            = "SHARED"
	SCHEMAID          = "SCHEMAID"
	KIND              = "KIND"
	DELIMITER         = "DELIMITER"

	XBIGINT   = "BIGINT"
	XFLOAT    = "FLOAT"
	XSTRING   = "STRING"
	XBYTEA    = "BYTEA"
	XDATETIME = "DATETIME"
	XBOOLEAN  = "BOOLEAN"
	XARRAY    = "ARRAY"
	XSTRUCT   = "STRUCT"
)

Variables

View Source
var COLUMN_SEPARATOR = Tokens[COLSEP]
View Source
var StreamTokens = map[string]struct{}{
	DATASOURCE:        {},
	KEY:               {},
	FORMAT:            {},
	CONF_KEY:          {},
	TYPE:              {},
	STRICT_VALIDATION: {},
	TIMESTAMP:         {},
	TIMESTAMP_FORMAT:  {},
	RETAIN_SIZE:       {},
	SHARED:            {},
	SCHEMAID:          {},
	KIND:              {},
	DELIMITER:         {},
}
View Source
var StreamTypeMap = map[StreamType]string{
	TypeStream: "stream",
	TypeTable:  "table",
}
View Source
var Tokens = []string{
	ILLEGAL:     "ILLEGAL",
	EOF:         "EOF",
	AS:          "AS",
	WS:          "WS",
	IDENT:       "IDENT",
	INTEGER:     "INTEGER",
	NUMBER:      "NUMBER",
	STRING:      "STRING",
	SINGLEQUOTE: "SINGLEQUOTE",

	ADD:         "+",
	SUB:         "-",
	MUL:         "*",
	DIV:         "/",
	MOD:         "%",
	BITWISE_AND: "&",
	BITWISE_OR:  "|",
	BITWISE_XOR: "^",

	EQ:  "=",
	NEQ: "!=",
	LT:  "<",
	LTE: "<=",
	GT:  ">",
	GTE: ">=",

	SUBSET: "[]",
	ARROW:  "->",
	IN:     "IN",

	ASTERISK: "*",
	COMMA:    ",",

	LPAREN:    "(",
	RPAREN:    ")",
	LBRACKET:  "[",
	RBRACKET:  "]",
	HASH:      "#",
	DOT:       ".",
	SEMICOLON: ";",
	COLON:     ":",
	COLSEP:    "\007",

	SELECT:    "SELECT",
	FROM:      "FROM",
	JOIN:      "JOIN",
	LEFT:      "LEFT",
	INNER:     "INNER",
	ON:        "ON",
	WHERE:     "WHERE",
	LIMIT:     "LIMIT",
	GROUP:     "GROUP",
	ORDER:     "ORDER",
	HAVING:    "HAVING",
	BY:        "BY",
	ASC:       "ASC",
	DESC:      "DESC",
	FILTER:    "FILTER",
	CASE:      "CASE",
	WHEN:      "WHEN",
	THEN:      "THEN",
	ELSE:      "ELSE",
	END:       "END",
	OVER:      "OVER",
	PARTITION: "PARTITION",

	AND:        "AND",
	OR:         "OR",
	TRUE:       "TRUE",
	FALSE:      "FALSE",
	NOTIN:      "NOT IN",
	BETWEEN:    "BETWEEN",
	NOTBETWEEN: "NOT BETWEEN",
	LIKE:       "LIKE",
	NOTLIKE:    "NOT LIKE",
	REPLACE:    "REPLACE",
	EXCEPT:     "EXCEPT",

	DD: "DD",
	HH: "HH",
	MI: "MI",
	SS: "SS",
	MS: "MS",
}

Functions

func IsBooleanArg

func IsBooleanArg(arg Expr) bool

func IsFieldRefArg

func IsFieldRefArg(arg Expr) bool

func IsFloatArg

func IsFloatArg(arg Expr) bool

func IsIntegerArg

func IsIntegerArg(arg Expr) bool

func IsNumericArg

func IsNumericArg(arg Expr) bool

func IsStreamOptionKeyword

func IsStreamOptionKeyword(_ Token, lit string) bool

func IsStringArg

func IsStringArg(arg Expr) bool

func IsTimeArg

func IsTimeArg(arg Expr) bool

func Walk

func Walk(v Visitor, node Node)

func WalkFunc

func WalkFunc(node Node, fn func(Node) bool)

WalkFunc traverses a node hierarchy in depth-first order.

Types

type AliasRef

type AliasRef struct {
	// MUST have, It is used for evaluation
	Expression Expr

	// optional, lazy set when calculating isAggregate
	IsAggregate *bool
	// contains filtered or unexported fields
}

func MockAliasRef

func MockAliasRef(e Expr, r []StreamName, a *bool) *AliasRef

MockAliasRef is for testing only.

func NewAliasRef

func NewAliasRef(e Expr) (*AliasRef, error)

func (*AliasRef) SetRefSource

func (a *AliasRef) SetRefSource(names []string)

SetRefSource only used for unit test

type ArrayType

type ArrayType struct {
	Type DataType
	FieldType
}

type ArrowExpr

type ArrowExpr struct {
	Expr Expr
}

func (*ArrowExpr) String

func (ae *ArrowExpr) String() string

type BasicType

type BasicType struct {
	Type DataType
	FieldType
}

type BetweenExpr

type BetweenExpr struct {
	Lower  Expr
	Higher Expr
}

func (*BetweenExpr) String

func (b *BetweenExpr) String() string

type BinaryExpr

type BinaryExpr struct {
	OP  Token
	LHS Expr
	RHS Expr
}

func (*BinaryExpr) String

func (be *BinaryExpr) String() string

func (*BinaryExpr) ValidateExpr

func (be *BinaryExpr) ValidateExpr() error

type BooleanLiteral

type BooleanLiteral struct {
	Val bool
}

func (*BooleanLiteral) String

func (bl *BooleanLiteral) String() string

type BracketExpr

type BracketExpr struct {
	Expr Expr
}

func (*BracketExpr) String

func (be *BracketExpr) String() string

type Call

type Call struct {
	Name     string
	FuncId   int
	FuncType FuncType
	Args     []Expr
	// This is used for analytic functions.
	// In planner, all analytic functions are planned to calculate in analytic_op which produce a new field.
	// This cachedField cached the new field name and when evaluating, just returned the field access evaluated value.
	CachedField string
	Cached      bool
	Partition   *PartitionExpr
	WhenExpr    Expr
}

func (*Call) String

func (c *Call) String() string

type CaseExpr

type CaseExpr struct {
	// The compare value Expression. It can be a value Expression or nil.
	// When it is nil, the WhenClause Expr must be a logical(comparison) Expression
	Value       Expr
	WhenClauses []*WhenClause
	ElseClause  Expr
}

func (*CaseExpr) String

func (c *CaseExpr) String() string

type ColFuncField

type ColFuncField struct {
	Name string
	Expr Expr
}

func (*ColFuncField) String

func (fr *ColFuncField) String() string

type ColonExpr

type ColonExpr struct {
	Start Expr
	End   Expr
}

func (*ColonExpr) String

func (be *ColonExpr) String() string

func (*ColonExpr) ValidateExpr

func (c *ColonExpr) ValidateExpr() error

type DataType

type DataType int
const (
	UNKNOWN DataType = iota
	BIGINT
	FLOAT
	STRINGS
	BYTEA
	DATETIME
	BOOLEAN
	ARRAY
	STRUCT
)

func GetDataType

func GetDataType(lit string) DataType

func (DataType) IsSimpleType

func (d DataType) IsSimpleType() bool

func (DataType) String

func (d DataType) String() string

type DescribeStreamStatement

type DescribeStreamStatement struct {
	Name string

	Statement
}

func (*DescribeStreamStatement) GetName

func (dss *DescribeStreamStatement) GetName() string

type DescribeTableStatement

type DescribeTableStatement struct {
	Name string

	Statement
}

func (*DescribeTableStatement) GetName

func (dss *DescribeTableStatement) GetName() string

type Dimension

type Dimension struct {
	Expr Expr

	Node
}

type Dimensions

type Dimensions []Dimension

func (*Dimensions) GetGroups

func (d *Dimensions) GetGroups() Dimensions

func (*Dimensions) GetWindow

func (d *Dimensions) GetWindow() *Window

type DropStreamStatement

type DropStreamStatement struct {
	Name string

	Statement
}

func (*DropStreamStatement) GetName

func (dss *DropStreamStatement) GetName() string

type DropTableStatement

type DropTableStatement struct {
	Name string

	Statement
}

func (*DropTableStatement) GetName

func (dss *DropTableStatement) GetName() string

type ExplainStreamStatement

type ExplainStreamStatement struct {
	Name string

	Statement
}

func (*ExplainStreamStatement) GetName

func (ess *ExplainStreamStatement) GetName() string

type ExplainTableStatement

type ExplainTableStatement struct {
	Name string

	Statement
}

func (*ExplainTableStatement) GetName

func (ess *ExplainTableStatement) GetName() string

type Expr

type Expr interface {
	Node

	// String function for the explain grammar, convert Expr to String
	String() string
	// contains filtered or unexported methods
}

type Field

type Field struct {
	Name  string
	AName string
	Expr  Expr

	Node
}

func (*Field) GetName

func (f *Field) GetName() string

func (*Field) IsColumn

func (f *Field) IsColumn() bool

func (*Field) IsSelectionField

func (f *Field) IsSelectionField() bool

type FieldRef

type FieldRef struct {
	// optional, bind in analyzer, empty means alias, default means not set
	// MUST have after binding for SQL fields. For 1.2,1.3 and 1.4, use special constant as stream name
	StreamName StreamName
	// optional, set only once. For selections, empty name will be assigned a default name
	// MUST have after binding, assign a name for 1.4
	Name string
	// Only for alias
	*AliasRef
}

FieldRef could be

  1. SQL Field 1.1 Explicit field "stream.col" 1.2 Implicit field "col" -> only exist in schemaless stream. Otherwise, explicit stream name will be bound 1.3 Alias field "expr as c" -> refer to an Expression or column

func (*FieldRef) IsAlias

func (fr *FieldRef) IsAlias() bool

func (*FieldRef) IsColumn

func (fr *FieldRef) IsColumn() bool

func (*FieldRef) RefSelection

func (fr *FieldRef) RefSelection(a *AliasRef)

func (*FieldRef) RefSources

func (fr *FieldRef) RefSources() []StreamName

RefSources Must call after binding or will get empty

func (*FieldRef) SetRefSource

func (fr *FieldRef) SetRefSource(names []StreamName)

SetRefSource Only call this for alias field ref

func (*FieldRef) String

func (fr *FieldRef) String() string

type FieldType

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

type Fields

type Fields []Field

func (Fields) Len

func (f Fields) Len() int

func (Fields) Less

func (f Fields) Less(i int, j int) bool

func (Fields) Swap

func (f Fields) Swap(i, j int)

type FuncType

type FuncType int
const (
	FuncTypeUnknown FuncType = iota - 1
	FuncTypeScalar
	FuncTypeAgg
	FuncTypeCols
	FuncTypeSrf
	FuncTypeWindow
	FuncTypeTrigger
)

type IndexExpr

type IndexExpr struct {
	Index Expr
}

func (*IndexExpr) String

func (be *IndexExpr) String() string

type IntegerLiteral

type IntegerLiteral struct {
	Val int64
}

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

type Join

type Join struct {
	Name     string
	Alias    string
	JoinType JoinType
	Expr     Expr

	Node
}

type JoinType

type JoinType int
const (
	LEFT_JOIN JoinType = iota
	INNER_JOIN
	RIGHT_JOIN
	FULL_JOIN
	CROSS_JOIN
)

func (JoinType) String

func (j JoinType) String() string

type Joins

type Joins []Join

type JsonFieldRef

type JsonFieldRef struct {
	Name string
}

func (*JsonFieldRef) String

func (fr *JsonFieldRef) String() string

type JsonStreamField

type JsonStreamField struct {
	Type       string                      `json:"type"`
	Items      *JsonStreamField            `json:"items,omitempty"`
	Properties map[string]*JsonStreamField `json:"properties,omitempty"`

	Selected bool
}

type LikePattern

type LikePattern struct {
	Expr    Expr
	Pattern *regexp.Regexp
}

func (*LikePattern) Compile

func (l *LikePattern) Compile(likestr string) (*regexp.Regexp, error)

func (*LikePattern) String

func (l *LikePattern) String() string

type LimitExpr

type LimitExpr struct {
	LimitCount *IntegerLiteral
}

func (*LimitExpr) String

func (l *LimitExpr) String() string

type Literal

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

type MetaRef

type MetaRef struct {
	StreamName StreamName
	Name       string
}

func (*MetaRef) String

func (fr *MetaRef) String() string

type NameNode

type NameNode interface {
	Node
	GetName() string
}

type Node

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

type NumberLiteral

type NumberLiteral struct {
	Val float64
}

func (*NumberLiteral) String

func (nl *NumberLiteral) String() string

type Options

type Options struct {
	DATASOURCE        string `json:"datasource,omitempty"`
	KEY               string `json:"key,omitempty"`
	FORMAT            string `json:"format,omitempty"`
	CONF_KEY          string `json:"confKey,omitempty"`
	TYPE              string `json:"type,omitempty"`
	STRICT_VALIDATION bool   `json:"strictValidation,omitempty"`
	TIMESTAMP         string `json:"timestamp,omitempty"`
	TIMESTAMP_FORMAT  string `json:"timestampFormat,omitempty"`
	SHARED            bool   `json:"shared,omitempty"`
	SCHEMAID          string `json:"schemaid,omitempty"`
	// for scan table only
	RETAIN_SIZE int `json:"retainSize,omitempty"`
	// for table only, to distinguish lookup & scan
	KIND string `json:"kind,omitempty"`
	// for delimited format only
	DELIMITER string `json:"delimiter,omitempty"`

	RuleID       string                      `json:"-"`
	Schema       map[string]*JsonStreamField `json:"-"`
	IsWildCard   bool                        `json:"-"`
	IsSchemaLess bool                        `json:"-"`
	StreamName   string                      `json:"-"`
}

Options The stream AST tree

type ParenExpr

type ParenExpr struct {
	Expr Expr
}

func (*ParenExpr) String

func (pe *ParenExpr) String() string

type PartitionExpr

type PartitionExpr struct {
	Exprs []Expr
}

func (*PartitionExpr) String

func (pe *PartitionExpr) String() string

type RecType

type RecType struct {
	StreamFields StreamFields
	FieldType
}

type SelectStatement

type SelectStatement struct {
	Fields     Fields
	Sources    Sources
	Joins      Joins
	Condition  Expr
	Limit      Expr
	Dimensions Dimensions
	Having     Expr
	SortFields SortFields

	Statement
}

type ShowStreamsStatement

type ShowStreamsStatement struct {
	Statement
}

type ShowTablesStatement

type ShowTablesStatement struct {
	Statement
}

type SortField

type SortField struct {
	Name       string
	StreamName StreamName
	Uname      string // unique name of a field
	Ascending  bool
	FieldExpr  Expr

	Expr
}

func (*SortField) String

func (sf *SortField) String() string

type SortFields

type SortFields []SortField

type Source

type Source interface {
	Node
	// contains filtered or unexported methods
}

type Sources

type Sources []Source

type Statement

type Statement interface {
	Node
	// contains filtered or unexported methods
}

type StreamField

type StreamField struct {
	Name string
	FieldType
}

func (*StreamField) MarshalJSON

func (u *StreamField) MarshalJSON() ([]byte, error)

type StreamFields

type StreamFields []StreamField

func (*StreamFields) ToJsonSchema

func (sf *StreamFields) ToJsonSchema() map[string]*JsonStreamField

func (*StreamFields) UnmarshalFromMap

func (sf *StreamFields) UnmarshalFromMap(data map[string]*JsonStreamField) error

func (*StreamFields) UnmarshalJSON

func (sf *StreamFields) UnmarshalJSON(data []byte) error

UnmarshalJSON The json format follows json schema

type StreamName

type StreamName string

type StreamStmt

type StreamStmt struct {
	Name         StreamName
	StreamFields StreamFields
	Options      *Options
	StreamType   StreamType // default to TypeStream

	Statement
}

type StreamType

type StreamType int
const (
	TypeStream StreamType = iota
	TypeTable
)

type StringLiteral

type StringLiteral struct {
	Val string
}

func (*StringLiteral) String

func (sl *StringLiteral) String() string

type Table

type Table struct {
	Name  string
	Alias string
	Source
}

type TimeLiteral

type TimeLiteral struct {
	Val Token
}

func (*TimeLiteral) String

func (tl *TimeLiteral) String() string

type Token

type Token int
const (
	// Special Tokens
	ILLEGAL Token = iota
	EOF
	WS
	COMMENT

	AS
	// Literals
	IDENT // main

	INTEGER     // 12345
	NUMBER      // 12345.67
	STRING      // "abc"
	SINGLEQUOTE // 'abc'
	BADSTRING   // "abc

	// ADD and the following are InfluxQL Operators
	ADD         // +
	SUB         // -
	MUL         // *
	DIV         // /
	MOD         // %
	BITWISE_AND // &
	BITWISE_OR  // |
	BITWISE_XOR // ^

	AND // AND
	OR  // OR

	EQ  // =
	NEQ // !=
	LT  // <
	LTE // <=
	GT  // >
	GTE // >=

	SUBSET //[
	ARROW  //->
	IN     // IN
	NOT    // NOT
	NOTIN  // NOT
	BETWEEN
	NOTBETWEEN
	LIKE
	NOTLIKE
	REPLACE
	EXCEPT

	// Misc characters
	ASTERISK  // *
	COMMA     // ,
	LPAREN    // (
	RPAREN    // )
	LBRACKET  //[
	RBRACKET  //]
	HASH      // #
	DOT       // .
	COLON     //:
	SEMICOLON //;
	COLSEP    //\007

	// Keywords
	SELECT
	FROM
	JOIN
	INNER
	LEFT
	RIGHT
	FULL
	CROSS
	ON
	WHERE
	LIMIT
	GROUP
	ORDER
	HAVING
	BY
	ASC
	DESC
	FILTER
	CASE
	WHEN
	THEN
	ELSE
	END
	OVER
	PARTITION

	TRUE
	FALSE

	DD
	HH
	MI
	SS
	MS
)

func (Token) AllowedSFNToken

func (tok Token) AllowedSFNToken() bool

Allowed special field name token

func (Token) AllowedSourceToken

func (tok Token) AllowedSourceToken() bool

func (Token) IsOperator

func (tok Token) IsOperator() bool

func (Token) IsTimeLiteral

func (tok Token) IsTimeLiteral() bool

func (Token) Precedence

func (tok Token) Precedence() int

func (Token) String

func (tok Token) String() string

type ValidateAbleExpr

type ValidateAbleExpr interface {
	ValidateExpr() error
}

type ValueSetExpr

type ValueSetExpr struct {
	LiteralExprs []Expr // ("A", "B", "C") or (1, 2, 3)
	ArrayExpr    Expr
}

func (*ValueSetExpr) String

func (c *ValueSetExpr) String() string

type Visitor

type Visitor interface {
	Visit(Node) bool
}

type WhenClause

type WhenClause struct {
	// The condition Expression
	Expr   Expr
	Result Expr
}

func (*WhenClause) String

func (w *WhenClause) String() string

type Wildcard

type Wildcard struct {
	Token   Token
	Replace []Field
	Except  []string
}

func (*Wildcard) String

func (w *Wildcard) String() string

type Window

type Window struct {
	TriggerCondition Expr
	WindowType       WindowType
	Delay            *IntegerLiteral
	Length           *IntegerLiteral
	Interval         *IntegerLiteral
	TimeUnit         *TimeLiteral
	Filter           Expr
	Expr
}

func (*Window) String

func (wd *Window) String() string

type WindowType

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

func (WindowType) String

func (w WindowType) String() string

Jump to

Keyboard shortcuts

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