expr

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ConvertTzCallName           = "convert_tz"
	CountCallName               = "count"
	DayOfWeekCallName           = "dayofweek"
	FromUnixTimeCallName        = "from_unixtime"
	GeographyIntersectsCallName = "geography_intersects"
	HexCallName                 = "hex"
	// hll aggregation function applies to hll columns
	HllCallName = "hll"
	// countdistincthll aggregation function applies to all columns, hll value is computed on the fly
	CountDistinctHllCallName = "countdistincthll"
	HourCallName             = "hour"
	ListCallName             = ""
	MaxCallName              = "max"
	MinCallName              = "min"
	SumCallName              = "sum"
	AvgCallName              = "avg"
	// array functions
	LengthCallName    = "length"
	ContainsCallName  = "contains"
	ElementAtCallName = "element_at"
)

constants for call names.

Variables

This section is empty.

Functions

func IdentNeedsQuotes

func IdentNeedsQuotes(ident string) bool

IdentNeedsQuotes returns true if the ident string given would require quotes.

func IsUUIDColumn added in v0.0.2

func IsUUIDColumn(expression Expr) bool

IsUUIDColumn returns whether an Expr is UUID

func QuoteIdent

func QuoteIdent(segments ...string) string

QuoteIdent returns a quoted identifier from multiple bare identifiers.

func QuoteString

func QuoteString(s string) string

QuoteString returns a quoted string.

func ScanBareIdent

func ScanBareIdent(r io.RuneScanner) string

ScanBareIdent reads bare identifier from a rune reader.

func ScanDelimited

func ScanDelimited(r io.RuneScanner, start, end rune, escapes map[rune]rune, escapesPassThru bool) ([]byte, error)

func ScanString

func ScanString(r io.RuneScanner) (string, error)

ScanString reads a quoted string from a rune reader.

func Walk

func Walk(v Visitor, expr Expr)

Walk traverses an expression hierarchy in depth-first order.

func WalkFunc

func WalkFunc(e Expr, fn func(Expr))

WalkFunc traverses an expression hierarchy in depth-first order.

Types

type BinaryExpr

type BinaryExpr struct {
	Op       Token
	LHS      Expr
	RHS      Expr
	ExprType Type
}

BinaryExpr represents an operation between two expressions.

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

String returns a string representation of the binary expression.

func (*BinaryExpr) Type

func (e *BinaryExpr) Type() Type

Type returns the type.

type BooleanLiteral

type BooleanLiteral struct {
	Val bool
}

BooleanLiteral represents a boolean literal.

func (*BooleanLiteral) String

func (l *BooleanLiteral) String() string

String returns a string representation of the literal.

func (*BooleanLiteral) Type

func (l *BooleanLiteral) Type() Type

Type returns the type.

type Call

type Call struct {
	Name     string
	Args     []Expr
	ExprType Type
}

Call represents a function call.

func (*Call) String

func (c *Call) String() string

String returns a string representation of the call.

func (*Call) Type

func (c *Call) Type() Type

Type returns the type.

type Case

type Case struct {
	WhenThens []WhenThen
	Else      Expr
	ExprType  Type
}

Case represents a CASE WHEN .. THEN .. ELSE .. THEN expression.

func (*Case) String

func (c *Case) String() string

String returns a string representation of the expression.

func (*Case) Type

func (c *Case) Type() Type

Type returns the type.

type Distinct

type Distinct struct {
	// Identifier following DISTINCT
	Val string
}

Distinct represents a DISTINCT expression.

func (*Distinct) NewCall

func (d *Distinct) NewCall() *Call

NewCall returns a new call expression from this expressions.

func (*Distinct) String

func (d *Distinct) String() string

String returns a string representation of the expression.

func (*Distinct) Type

func (d *Distinct) Type() Type

Type returns the type.

type Expr

type Expr interface {
	String() string
	Type() Type
	// contains filtered or unexported methods
}

Expr represents an expression that can be evaluated to a value.

func Cast added in v0.0.2

func Cast(e Expr, t Type) Expr

Cast returns an expression that casts the input to the desired type. The returned expression AST will be used directly for VM instruction generation of the desired types.

func CloneExpr

func CloneExpr(expr Expr) Expr

CloneExpr returns a deep copy of the expression.

func ParseExpr

func ParseExpr(s string) (Expr, error)

ParseExpr parses an expression string and returns its AST representation.

func Rewrite

func Rewrite(r Rewriter, expr Expr) Expr

Rewrite recursively invokes the rewriter to replace each expression. Nodes are traversed depth-first and rewritten from leaf to root.

func RewriteFunc

func RewriteFunc(e Expr, fn func(Expr) Expr) Expr

RewriteFunc rewrites an expression hierarchy.

type GeopointLiteral

type GeopointLiteral struct {
	Val [2]float32
}

GeopointLiteral represents a literal for GeoPoint

func (*GeopointLiteral) String

func (l *GeopointLiteral) String() string

String returns a string representation of the literal.

func (*GeopointLiteral) Type

func (l *GeopointLiteral) Type() Type

Type returns the type.

type NullLiteral

type NullLiteral struct{}

NullLiteral represents a NULL literal.

func (*NullLiteral) String

func (l *NullLiteral) String() string

String returns "NULL".

func (*NullLiteral) Type

func (l *NullLiteral) Type() Type

Type returns the type.

type NumberLiteral

type NumberLiteral struct {
	Val      float64
	Int      int
	Expr     string
	ExprType Type
}

NumberLiteral represents a numeric literal.

func (*NumberLiteral) String

func (l *NumberLiteral) String() string

String returns a string representation of the literal.

func (*NumberLiteral) Type

func (l *NumberLiteral) Type() Type

Type returns the type.

type ParenExpr

type ParenExpr struct {
	Expr     Expr
	ExprType Type // used for type casting
}

ParenExpr represents a parenthesized expression.

func (*ParenExpr) String

func (e *ParenExpr) String() string

String returns a string representation of the parenthesized expression.

func (*ParenExpr) Type

func (e *ParenExpr) Type() Type

Type returns the type.

type ParseError

type ParseError struct {
	Message  string
	Found    string
	Expected []string
	Pos      Pos
}

ParseError represents an error that occurred during parsing.

func (*ParseError) Error

func (e *ParseError) Error() string

Error returns the string representation of the error.

type Parser

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

Parser represents an InfluxQL parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) ParseExpr

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

ParseExpr parses an expression. binOpPrcdncLb: binary operator precedence lower bound. Any binary operator with a lower precedence than that will cause ParseExpr to stop. This is used for parsing binary operators following a unary operator.

type Pos

type Pos struct {
	Line int
	Char int
}

Pos specifies the line and character position of a token. The Char and Line are both zero-based indexes.

type Rewriter

type Rewriter interface {
	Rewrite(Expr) Expr
}

Rewriter can be called by Rewrite to replace nodes in the AST hierarchy. The Rewrite() function is called once per expression.

type Scanner

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

Scanner represents a lexical scanner for InfluxQL.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

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

Scan returns the next token and position from the underlying reader. Also returns the literal text read for strings, numbers, and duration tokens since these token types can have different literal representations.

type StringLiteral

type StringLiteral struct {
	Val string
}

StringLiteral represents a string literal.

func (*StringLiteral) String

func (l *StringLiteral) String() string

String returns a string representation of the literal.

func (*StringLiteral) Type

func (l *StringLiteral) Type() Type

Type returns the type.

type Token

type Token int

Token is a lexical token of the InfluxQL language.

const (
	// Special tokens
	ILLEGAL Token = iota
	EOF
	WS

	// Literals
	IDENT     // main
	NUMBER    // 12345.67
	STRING    // "abc"
	BADSTRING // "abc
	BADESCAPE // \q
	NULL      // NULL
	UNKNOWN   // UNKNOWN
	TRUE      // true
	FALSE     // false

	EXCLAMATION // !
	UNARY_MINUS // -
	NOT         // NOT
	BITWISE_NOT // ~0

	// Date operators
	GET_WEEK_START
	GET_MONTH_START
	GET_QUARTER_START
	GET_YEAR_START
	GET_DAY_OF_MONTH
	GET_DAY_OF_YEAR
	GET_MONTH_OF_YEAR
	GET_QUARTER_OF_YEAR
	// hll operator
	GET_HLL_VALUE
	// array operator
	ARRAY_LENGTH

	IS_NULL     // IS NULL
	IS_NOT_NULL // IS NOT NULL
	IS_TRUE     // IS TRUE
	IS_FALSE    // IS FALSE

	ADD        // +
	SUB        // -
	MUL        // *
	DIV        // /
	MOD        // %
	FLOOR      // floor
	CONVERT_TZ // convert_tz

	BITWISE_AND         // &
	BITWISE_OR          // |
	BITWISE_XOR         // ^
	BITWISE_LEFT_SHIFT  // <<
	BITWISE_RIGHT_SHIFT // >>

	AND // AND
	OR  // OR

	IN     // IN
	NOT_IN // NOT_IN
	IS     // IS
	NEQ    // !=
	// Do not modify the order of the following 5 operators
	EQ  // =
	LT  // <
	LTE // <=
	GT  // >
	GTE // >=

	// Geo intersects
	GEOGRAPHY_INTERSECTS
	// Array functions
	ARRAY_CONTAINS
	ARRAY_ELEMENT_AT

	LPAREN // (
	RPAREN // )
	COMMA  // ,
	DOT    // .

	// Keywords
	ALL
	AS
	ASC
	BEGIN
	BY
	CASE
	DEFAULT
	DELETE
	DESC
	DISTINCT
	DROP
	ELSE
	END
	EXISTS
	FIELD
	FOR
	FROM
	GROUP
	IF
	INF
	INNER
	INSERT
	KEY
	KEYS
	LIMIT
	OFFSET
	ON
	ORDER
	SELECT
	THEN
	TO
	VALUES
	WHEN
	WHERE
	WITH
)

func Lookup

func Lookup(ident string) Token

Lookup returns the token associated with a given string.

func (Token) MarshalJSON

func (tok Token) MarshalJSON() ([]byte, error)

func (Token) Precedence

func (tok Token) Precedence() int

Precedence returns the operator precedence of the binary operator token.

func (Token) String

func (tok Token) String() string

String returns the string representation of the token.

type Type

type Type int

Type defines data types for expression evaluation. Expression types are determined at query compilation time, type castings are generated when apprioperiate. Notice that word widths are not specified here.

const (
	UnknownType Type = iota
	Boolean
	Unsigned
	Signed
	Float
	GeoPoint
	GeoShape
)

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

func (Type) String

func (t Type) String() string

type UnaryExpr

type UnaryExpr struct {
	Op       Token
	Expr     Expr
	ExprType Type
}

UnaryExpr represents an operation on a single expression.

func (*UnaryExpr) String

func (e *UnaryExpr) String() string

String returns a string representation of the unary expression.

func (*UnaryExpr) Type

func (e *UnaryExpr) Type() Type

Type returns the type.

type UnknownLiteral

type UnknownLiteral struct{}

UnknownLiteral represents an UNKNOWN literal.

func (*UnknownLiteral) String

func (l *UnknownLiteral) String() string

String returns "UNKNOWN".

func (*UnknownLiteral) Type

func (l *UnknownLiteral) Type() Type

Type returns the type.

type VarRef

type VarRef struct {
	Val      string
	ExprType Type

	// ID of the table in the query scope (0 for the main table, 1+ for foreign
	// tables).
	TableID int
	// ID of the column in the schema.
	ColumnID int
	// Enum dictionary for enum typed column. Can only be accessed while holding
	// the schema lock.
	EnumDict map[string]int `json:"-"`
	// Setting enum reverse dict requires holding the schema lock,
	// while reading from it does not require holding the schema lock.
	EnumReverseDict []string `json:"-"`

	DataType memCom.DataType

	// Whether this column is hll column (can run hll directly)
	IsHLLColumn bool
}

VarRef represents a reference to a variable.

func (*VarRef) String

func (r *VarRef) String() string

String returns a string representation of the variable reference.

func (*VarRef) Type

func (r *VarRef) Type() Type

Type returns the type.

type Visitor

type Visitor interface {
	Visit(Expr) Visitor
}

Visitor can be called by Walk to traverse an AST hierarchy. The Visit() function is called once per expression.

type WhenThen

type WhenThen struct {
	When Expr
	Then Expr
}

WhenThen represents a when-then conditional expression pair in a case expression.

type Wildcard

type Wildcard struct{}

Wildcard represents a wild card expression.

func (*Wildcard) String

func (e *Wildcard) String() string

String returns a string representation of the wildcard.

func (*Wildcard) Type

func (e *Wildcard) Type() Type

Type returns the type.

Jump to

Keyboard shortcuts

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