xsql

package
v0.0.0-...-7b16d43 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AsteriskExpr = StringLiteral{Val: "*"}
View Source
var COLUMN_SEPARATOR = tokens[COLSEP]
View Source
var Language = &ParseTree{}

Functions

func Eval

func Eval(expr Expr, m Valuer) interface{}

Eval evaluates expr against a map.

func GetStreams

func GetStreams(stmt *SelectStatement) (result []string)

func HasAggFuncs

func HasAggFuncs(node Node) bool

func HasNoAggFuncs

func HasNoAggFuncs(node Node) bool

func IsAggStatement

func IsAggStatement(stmt *SelectStatement) bool

func LowercaseKeyMap

func LowercaseKeyMap(m map[string]interface{}) map[string]interface{}

func NewAggregateFunctionValuers

func NewAggregateFunctionValuers(p *funcPlugins) (*FunctionValuer, *AggregateFunctionValuer)

Should only be called by stream to make sure a single instance for an operation

func NewFuncPlugins

func NewFuncPlugins(ctx api.StreamContext) *funcPlugins

func PrintFieldType

func PrintFieldType(ft FieldType) (result string)

func PrintFieldTypeForJson

func PrintFieldTypeForJson(ft FieldType) (result interface{})

func Validate

func Validate(stmt *SelectStatement) error

func Walk

func Walk(v Visitor, node Node)

func WalkFunc

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

WalkFunc traverses a node hierarchy in depth-first order.

Types

type AggregateCallValuer

type AggregateCallValuer interface {
	CallValuer
	GetAllTuples() AggregateData
	GetSingleCallValuer() CallValuer
}

type AggregateData

type AggregateData interface {
	AggregateEval(expr Expr, v CallValuer) []interface{}
}

type AggregateFunctionValuer

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

func (*AggregateFunctionValuer) Call

func (v *AggregateFunctionValuer) Call(name string, args []interface{}) (interface{}, bool)

func (*AggregateFunctionValuer) GetAllTuples

func (v *AggregateFunctionValuer) GetAllTuples() AggregateData

func (*AggregateFunctionValuer) GetSingleCallValuer

func (v *AggregateFunctionValuer) GetSingleCallValuer() CallValuer

func (*AggregateFunctionValuer) Meta

func (v *AggregateFunctionValuer) Meta(key string) (interface{}, bool)

func (*AggregateFunctionValuer) SetData

func (v *AggregateFunctionValuer) SetData(data AggregateData)

func (*AggregateFunctionValuer) Value

func (v *AggregateFunctionValuer) Value(key string) (interface{}, bool)

type AllowTypes

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

type ArrayType

type ArrayType struct {
	Type DataType
	FieldType
}

type ArrowExpr

type ArrowExpr struct {
	Expr Expr
}

type BasicType

type BasicType struct {
	Type DataType
}

type BinaryExpr

type BinaryExpr struct {
	OP  Token
	LHS Expr
	RHS Expr
}

type BooleanLiteral

type BooleanLiteral struct {
	Val bool
}

type BracketEvalResult

type BracketEvalResult struct {
	Start, End int
}

type BracketExpr

type BracketExpr struct {
	Expr Expr
}

type Call

type Call struct {
	Name string
	Args []Expr
}

type CallValuer

type CallValuer interface {
	Valuer

	// Call is invoked to evaluate a function call (if possible).
	Call(name string, args []interface{}) (interface{}, bool)
}

CallValuer implements the Call method for evaluating function calls.

type ColonExpr

type ColonExpr struct {
	Start int
	End   int
}

type DataType

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

func (DataType) String

func (d DataType) String() string

type DataValuer

type DataValuer interface {
	Valuer
	Wildcarder
}

type DescribeStreamStatement

type DescribeStreamStatement struct {
	Name string
}

func (*DescribeStreamStatement) Stmt

func (dss *DescribeStreamStatement) Stmt()

type Dimension

type Dimension struct {
	Expr Expr
}

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
}

func (*DropStreamStatement) Stmt

func (dss *DropStreamStatement) Stmt()

type EvalResultMessage

type EvalResultMessage struct {
	Emitter string
	Result  interface{}
	Message Message
}

type Event

type Event interface {
	GetTimestamp() int64
	IsWatermark() bool
}

type ExplainStreamStatement

type ExplainStreamStatement struct {
	Name string
}

func (*ExplainStreamStatement) Stmt

func (ess *ExplainStreamStatement) Stmt()

type Expr

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

type ExpressionEvaluator

type ExpressionEvaluator struct {
	*ExpressionVisitorAdaptor
	// contains filtered or unexported fields
}

func (*ExpressionEvaluator) Visit

func (ee *ExpressionEvaluator) Visit(expr Node) Visitor

func (*ExpressionEvaluator) VisitBinaryExpr

func (ee *ExpressionEvaluator) VisitBinaryExpr(expr *BinaryExpr)

func (*ExpressionEvaluator) VisitFieldRef

func (ee *ExpressionEvaluator) VisitFieldRef(expr *FieldRef)

func (*ExpressionEvaluator) VisitIntegerLiteral

func (ee *ExpressionEvaluator) VisitIntegerLiteral(expr *IntegerLiteral)

type ExpressionVisitor

type ExpressionVisitor interface {
	Visit(Node) Visitor

	VisitBinaryExpr(*BinaryExpr)
	VisitFieldRef(*FieldRef)
	VisitIntegerLiteral(*IntegerLiteral)
}

type ExpressionVisitorAdaptor

type ExpressionVisitorAdaptor struct {
}

func (*ExpressionVisitorAdaptor) DoVisit

func (eva *ExpressionVisitorAdaptor) DoVisit(v ExpressionVisitor, expr Node)

func (*ExpressionVisitorAdaptor) Visit

func (eva *ExpressionVisitorAdaptor) Visit(expr Node) Visitor

func (*ExpressionVisitorAdaptor) VisitBinaryExpr

func (eva *ExpressionVisitorAdaptor) VisitBinaryExpr(expr *BinaryExpr)

func (*ExpressionVisitorAdaptor) VisitFieldRef

func (eva *ExpressionVisitorAdaptor) VisitFieldRef(expr *FieldRef)

type Field

type Field struct {
	Name  string
	AName string
	Expr
}

type FieldRef

type FieldRef struct {
	StreamName StreamName
	Name       string
}

type FieldType

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

type Fields

type Fields []Field

type FunctionValuer

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

ONLY use NewFunctionValuer function to initialize

func NewFunctionValuer

func NewFunctionValuer(p *funcPlugins) *FunctionValuer

Should only be called by stream to make sure a single instance for an operation

func (*FunctionValuer) Call

func (fv *FunctionValuer) Call(name string, args []interface{}) (interface{}, bool)

func (*FunctionValuer) Meta

func (*FunctionValuer) Meta(_ string) (interface{}, bool)

func (*FunctionValuer) Value

func (*FunctionValuer) Value(_ string) (interface{}, bool)

type GroupedTuples

type GroupedTuples []DataValuer

func (GroupedTuples) AggregateEval

func (s GroupedTuples) AggregateEval(expr Expr, v CallValuer) []interface{}

type GroupedTuplesSet

type GroupedTuplesSet []GroupedTuples

func (GroupedTuplesSet) Index

func (s GroupedTuplesSet) Index(i int) Valuer

func (GroupedTuplesSet) Len

func (s GroupedTuplesSet) Len() int

func (GroupedTuplesSet) Swap

func (s GroupedTuplesSet) Swap(i, j int)

type IndexExpr

type IndexExpr struct {
	Index int
}

type IntegerLiteral

type IntegerLiteral struct {
	Val int
}

type Join

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

type JoinTuple

type JoinTuple struct {
	Tuples []Tuple
}

func (*JoinTuple) AddTuple

func (jt *JoinTuple) AddTuple(tuple Tuple)

func (*JoinTuple) AddTuples

func (jt *JoinTuple) AddTuples(tuples []Tuple)

func (*JoinTuple) All

func (jt *JoinTuple) All(stream string) (interface{}, bool)

func (*JoinTuple) Meta

func (jt *JoinTuple) Meta(key string) (interface{}, bool)

func (*JoinTuple) Value

func (jt *JoinTuple) Value(key string) (interface{}, bool)

type JoinTupleSets

type JoinTupleSets []JoinTuple

func (JoinTupleSets) AggregateEval

func (s JoinTupleSets) AggregateEval(expr Expr, v CallValuer) []interface{}

func (JoinTupleSets) Index

func (s JoinTupleSets) Index(i int) Valuer

func (JoinTupleSets) Len

func (s JoinTupleSets) Len() int

func (JoinTupleSets) Swap

func (s JoinTupleSets) Swap(i, j int)

type JoinType

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

type Joins

type Joins []Join

type Literal

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

type Message

type Message map[string]interface{}

Message is a valuer that substitutes values for the mapped interface.

func (Message) Meta

func (m Message) Meta(key string) (interface{}, bool)

func (Message) Value

func (m Message) Value(key string) (interface{}, bool)

Value returns the value for a key in the Message.

type MetaRef

type MetaRef struct {
	StreamName StreamName
	Name       string
}

type Metadata

type Metadata Message

func (Metadata) Meta

func (m Metadata) Meta(key string) (interface{}, bool)

func (Metadata) Value

func (m Metadata) Value(key string) (interface{}, bool)

type MultiSorter

type MultiSorter struct {
	SortingData
	// contains filtered or unexported fields
}

multiSorter implements the Sort interface, sorting the changes within.Hi

func OrderedBy

func OrderedBy(fields SortFields, fv *FunctionValuer) *MultiSorter

OrderedBy returns a Sorter that sorts using the less functions, in order. Call its Sort method to sort the data.

func (*MultiSorter) Less

func (ms *MultiSorter) Less(i, j int) bool

Less is part of sort.Interface. It is implemented by looping along the less functions until it finds a comparison that discriminates between the two items (one is less than the other). Note that it can call the less functions twice per call. We could change the functions to return -1, 0, 1 and reduce the number of calls for greater efficiency: an exercise for the reader.

func (*MultiSorter) Sort

func (ms *MultiSorter) Sort(data SortingData) error

Sort sorts the argument slice according to the less functions passed to OrderedBy.

type Node

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

type NumberLiteral

type NumberLiteral struct {
	Val float64
}

type Options

type Options map[string]string

The stream AST tree

type ParenExpr

type ParenExpr struct {
	Expr Expr
}

type ParseTree

type ParseTree struct {
	Handlers map[Token]func(*Parser) (Statement, error)
	Tokens   map[Token]*ParseTree
	Keys     []string
}

func (*ParseTree) Handle

func (t *ParseTree) Handle(tok Token, fn func(*Parser) (Statement, error))

func (*ParseTree) Parse

func (pt *ParseTree) Parse(p *Parser) (Statement, error)

type Parser

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

func NewParser

func NewParser(r io.Reader) *Parser

func (*Parser) ConvertToWindows

func (p *Parser) ConvertToWindows(wtype WindowType, args []Expr) (*Window, error)

func (*Parser) Parse

func (p *Parser) Parse() (*SelectStatement, error)

func (*Parser) ParseCreateStreamStmt

func (p *Parser) ParseCreateStreamStmt() (*StreamStmt, error)

func (*Parser) ParseExpr

func (p *Parser) ParseExpr() (Expr, error)

func (*Parser) ParseJoin

func (p *Parser) ParseJoin(joinType JoinType) (*Join, error)

func (*Parser) ParseQueries

func (p *Parser) ParseQueries() (SelectStatements, error)

type RecType

type RecType struct {
	StreamFields StreamFields
}

type ResultsAndMessages

type ResultsAndMessages []EvalResultMessage

type Scanner

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

func NewScanner

func NewScanner(r io.Reader) *Scanner

func (*Scanner) Scan

func (s *Scanner) Scan() (tok Token, lit string)

func (*Scanner) ScanBackquoteIdent

func (s *Scanner) ScanBackquoteIdent() (tok Token, lit string)

func (*Scanner) ScanDigit

func (s *Scanner) ScanDigit() (tok Token, lit string)

func (*Scanner) ScanIdent

func (s *Scanner) ScanIdent() (tok Token, lit string)

func (*Scanner) ScanNumber

func (s *Scanner) ScanNumber(startWithDot bool, isNeg bool) (tok Token, lit string)

func (*Scanner) ScanString

func (s *Scanner) ScanString() (tok Token, lit string)

func (*Scanner) ScanWhiteSpace

func (s *Scanner) ScanWhiteSpace() (tok Token, lit string)

type SelectStatement

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

func GetStatementFromSql

func GetStatementFromSql(sql string) (*SelectStatement, error)

func (*SelectStatement) Stmt

func (ss *SelectStatement) Stmt()

type SelectStatements

type SelectStatements []SelectStatement

type ShowStreamsStatement

type ShowStreamsStatement struct {
}

func (*ShowStreamsStatement) Stmt

func (ss *ShowStreamsStatement) Stmt()

type SortField

type SortField struct {
	Name      string
	Ascending bool
}

type SortFields

type SortFields []SortField

type SortingData

type SortingData interface {
	Len() int
	Swap(i, j int)
	Index(i int) Valuer
}

type Source

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

type Sources

type Sources []Source

type Statement

type Statement interface {
	Stmt()
	Node
}

type StreamField

type StreamField struct {
	Name string
	FieldType
}

func (*StreamField) MarshalJSON

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

type StreamFields

type StreamFields []StreamField

type StreamName

type StreamName string

type StreamStmt

type StreamStmt struct {
	Name         StreamName
	StreamFields StreamFields
	Options      Options
}

func (*StreamStmt) Stmt

func (ss *StreamStmt) Stmt()

type StringLiteral

type StringLiteral struct {
	Val string
}

type Table

type Table struct {
	Name  string
	Alias string
}

type TimeLiteral

type TimeLiteral struct {
	Val Token
}

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"
	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  //->

	// 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
	GROUP
	ORDER
	HAVING
	BY
	ASC
	DESC
	FILTER

	TRUE
	FALSE

	CREATE
	DROP
	EXPLAIN
	DESCRIBE
	SHOW
	STREAM
	STREAMS
	WITH

	XBIGINT
	XFLOAT
	XSTRING
	XBYTEA
	XDATETIME
	XBOOLEAN
	XARRAY
	XSTRUCT

	DATASOURCE
	KEY
	FORMAT
	CONF_KEY
	TYPE
	STRICT_VALIDATION
	TIMESTAMP
	TIMESTAMP_FORMAT
	JSONCONFIG

	DD
	HH
	MI
	SS
	MS
)

func (Token) Precedence

func (tok Token) Precedence() int

func (Token) String

func (tok Token) String() string

type Tuple

type Tuple struct {
	Emitter   string
	Message   Message
	Timestamp int64
	Metadata  Metadata
}

func (*Tuple) AggregateEval

func (t *Tuple) AggregateEval(expr Expr, v CallValuer) []interface{}

func (*Tuple) All

func (t *Tuple) All(stream string) (interface{}, bool)

func (*Tuple) GetMetadata

func (t *Tuple) GetMetadata() Metadata

func (*Tuple) GetTimestamp

func (t *Tuple) GetTimestamp() int64

func (*Tuple) IsWatermark

func (t *Tuple) IsWatermark() bool

func (*Tuple) Meta

func (t *Tuple) Meta(key string) (interface{}, bool)

func (*Tuple) Value

func (t *Tuple) Value(key string) (interface{}, bool)

type Valuer

type Valuer interface {
	// Value returns the value and existence flag for a given key.
	Value(key string) (interface{}, bool)
	Meta(key string) (interface{}, bool)
}

Valuer is the interface that wraps the Value() method.

func MultiAggregateValuer

func MultiAggregateValuer(data AggregateData, singleCallValuer CallValuer, valuers ...Valuer) Valuer

func MultiValuer

func MultiValuer(valuers ...Valuer) Valuer

MultiValuer returns a Valuer that iterates over multiple Valuer instances to find a match.

type ValuerEval

type ValuerEval struct {
	Valuer Valuer

	// IntegerFloatDivision will set the eval system to treat
	// a division between two integers as a floating point division.
	IntegerFloatDivision bool
}

ValuerEval will evaluate an expression using the Valuer.

func (*ValuerEval) Eval

func (v *ValuerEval) Eval(expr Expr) interface{}

Eval evaluates an expression and returns a value.

type Visitor

type Visitor interface {
	Visit(Node) Visitor
}

type Wildcard

type Wildcard struct {
	Token Token
}

type WildcardValuer

type WildcardValuer struct {
	Data Wildcarder
}

func (*WildcardValuer) Meta

func (wv *WildcardValuer) Meta(key string) (interface{}, bool)

func (*WildcardValuer) Value

func (wv *WildcardValuer) Value(key string) (interface{}, bool)

TODO deal with wildcard of a stream, e.g. SELECT Table.* from Table inner join Table1

type Wildcarder

type Wildcarder interface {
	// Value returns the value and existence flag for a given key.
	All(stream string) (interface{}, bool)
}

type Window

type Window struct {
	WindowType WindowType
	Length     *IntegerLiteral
	Interval   *IntegerLiteral
	Filter     Expr
}

type WindowTuples

type WindowTuples struct {
	Emitter string
	Tuples  []Tuple
}

type WindowTuplesSet

type WindowTuplesSet []WindowTuples

func (WindowTuplesSet) AddTuple

func (w WindowTuplesSet) AddTuple(tuple *Tuple) WindowTuplesSet

func (WindowTuplesSet) AggregateEval

func (w WindowTuplesSet) AggregateEval(expr Expr, v CallValuer) []interface{}

func (WindowTuplesSet) GetBySrc

func (w WindowTuplesSet) GetBySrc(src string) []Tuple

func (WindowTuplesSet) Index

func (w WindowTuplesSet) Index(i int) Valuer

func (WindowTuplesSet) Len

func (w WindowTuplesSet) Len() int

func (WindowTuplesSet) Sort

func (w WindowTuplesSet) Sort()

Sort by tuple timestamp

func (WindowTuplesSet) Swap

func (w WindowTuplesSet) Swap(i, j int)

type WindowType

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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