sp

package
v0.0.0-...-9551cad Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unknown primitive data type.
	Unknown DataType = 0
	// Float means the data type is a float
	Float = 1
	// Integer means the data type is a integer
	Integer = 2
	// String means the data type is a string of text.
	String = 3
	// Boolean means the data type is a boolean.
	Boolean = 4
	// AnyField means the data type is any field.
	AnyField = 5
)
View Source
const (
	// MinNanoTime is the minumum time that can be represented.
	//
	// 1677-09-21 00:12:43.145224194 +0000 UTC
	//
	// The two lowest minimum integers are used as sentinel values.  The
	// minimum value needs to be used as a value lower than any other value for
	// comparisons and another separate value is needed to act as a sentinel
	// default value that is unusable by the user, but usable internally.
	// Because these two values need to be used for a special purpose, we do
	// not allow users to write points at these two times.
	MinNanoTime = int64(math.MinInt64) + 2

	// MaxNanoTime is the maximum time that can be represented.
	//
	// 2262-04-11 23:47:16.854775806 +0000 UTC
	//
	// The highest time represented by a nanosecond needs to be used for an
	// exclusive range in the shard group, so the maximum time needs to be one
	// less than the possible maximum number of nanoseconds representable by an
	// int64 so that we don't lose a point at that one time.
	MaxNanoTime = int64(math.MaxInt64) - 1

	// MinTime is used as the minimum time value when computing an unbounded range.
	// This time is one less than the MinNanoTime so that the first minimum
	// time can be used as a sentinel value to signify that it is the default
	// value rather than explicitly set by the user.
	MinTime = MinNanoTime - 1

	// MaxTime is used as the maximum time value when computing an unbounded range.
	// This time is 2262-04-11 23:47:16.854775806 +0000 UTC
	MaxTime = MaxNanoTime
)

Variables

View Source
var (
	// ErrInvalidTime is returned when the timestamp string used to
	// compare against time field is invalid.
	ErrInvalidTime = errors.New("invalid timestamp string")
)
View Source
var (

	// ErrTimeOutOfRange gets returned when time is out of the representable range using int64 nanoseconds since the epoch.
	ErrTimeOutOfRange = fmt.Errorf("time outside range %d - %d", MinNanoTime, MaxNanoTime)
)

Functions

func BinaryExprName

func BinaryExprName(expr *BinaryExpr) string

BinaryExprName returns the name of a binary expression by concatenating the variables in the binary expression with underscores.

func CheckTime

func CheckTime(t time.Time) error

CheckTime checks that a time is within the safe range.

func ContainsVarRef

func ContainsVarRef(expr Expr) bool

ContainsVarRef returns true if expr is a VarRef or contains one.

func EsDsl

func EsDsl(sql string) (string, error)

EsDsl return dsl json string

func GetPrecisionMultiplier

func GetPrecisionMultiplier(precision string) int64

GetPrecisionMultiplier will return a multiplier for the precision specified

func IdentNeedsQuotes

func IdentNeedsQuotes(ident string) bool

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

func IsListOp

func IsListOp(t Token) bool

IsListOp returns true if the operator accepts a list operand.

func IsRegexOp

func IsRegexOp(t Token) bool

IsRegexOp returns true if the operator accepts a regex operand.

func MatchSource

func MatchSource(sources Sources, name string) string

MatchSource returns the source name that matches a field name. Returns a blank string if no sources match.

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 SafeCalcTime

func SafeCalcTime(timestamp int64, precision string) (time.Time, error)

SafeCalcTime safely calculates the time given. Will return error if the time is outside the supported range.

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)

ScanDelimited reads a delimited set of runes

func ScanString

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

ScanString reads a quoted string from a rune reader.

func Walk

func Walk(v Visitor, node Node)

Walk traverses a node hierarchy in depth-first order.

func WalkFunc

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

WalkFunc traverses a node hierarchy in depth-first order.

Types

type Agg

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

Agg .

type Aggs

type Aggs []*Agg

Aggs .

type BinaryExpr

type BinaryExpr struct {
	Op  Token
	LHS Expr
	RHS Expr
}

BinaryExpr represents an operation between two expressions.

func (*BinaryExpr) String

func (e *BinaryExpr) String() string

String returns a string representation of the binary expression.

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.

type Call

type Call struct {
	Name string
	Args []Expr
}

Call represents a function call.

func (*Call) RewriteMetricArgs

func (c *Call) RewriteMetricArgs()

RewriteMetricArgs ...

func (*Call) String

func (c *Call) String() string

String returns a string representation of the call.

type DataType

type DataType int

DataType represents the primitive data types available in InfluxQL.

func InspectDataType

func InspectDataType(v interface{}) DataType

InspectDataType returns the data type of a given value.

func InspectDataTypes

func InspectDataTypes(a []interface{}) []DataType

InspectDataTypes returns all of the data types for an interface slice.

func (DataType) String

func (d DataType) String() string

type Dimension

type Dimension struct {
	Expr  Expr
	Alias string
}

Dimension represents an expression that a select statement is grouped by.

func (*Dimension) String

func (d *Dimension) String() string

String returns a string representation of the dimension.

type Dimensions

type Dimensions []*Dimension

Dimensions represents a list of dimensions.

func (Dimensions) String

func (a Dimensions) String() string

String returns a string representation of the dimensions.

type ESAgg

type ESAgg int

ESAgg enum

const (
	IllegalAgg ESAgg = iota

	//metric aggregations method
	Avg
	Cardinality
	ExtendedStats
	GeoBounds
	GeoCentroid
	Max
	Min
	Percentiles
	PercentileRanks
	Stats
	Sum
	Top
	ValueCount
	StarCount // count(*)

	//bucket aggregations method
	DateHistogram
	DateRange
	Filter
	Filters
	GeoDistance
	GeoHashGrid
	Global
	Histogram
	IPRange
	Missing
	Nested
	Range
	ReverseNested
	Sampler
	SignificantTerms
	Terms

	BucketScript
	BucketSelector
)

These are a comprehensive list of es aggregations.

type Expr

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

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

type Field

type Field struct {
	Expr  Expr
	Alias string
}

Field represents an expression retrieved from a select statement.

func (*Field) Name

func (f *Field) Name() string

Name returns the name of the field. Returns alias, if set. Otherwise uses the function name or variable name.

func (*Field) String

func (f *Field) String() string

String returns a string representation of the field.

type Fields

type Fields []*Field

Fields represents a list of fields.

func (Fields) AliasNames

func (a Fields) AliasNames() []string

AliasNames returns a list of calculated field names in order of alias, function name, then field.

func (Fields) Len

func (a Fields) Len() int

Sort Interface for Fields

func (Fields) Less

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

func (Fields) Names

func (a Fields) Names() []string

Names returns a list of field names.

func (Fields) String

func (a Fields) String() string

String returns a string representation of the fields.

func (Fields) Swap

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

type HasDefaultDatabase

type HasDefaultDatabase interface {
	Node

	DefaultDatabase() string
	// contains filtered or unexported methods
}

HasDefaultDatabase provides an interface to get the default database from a Statement.

type IntegerLiteral

type IntegerLiteral struct {
	Val int64
}

IntegerLiteral represents an integer literal.

func (*IntegerLiteral) String

func (l *IntegerLiteral) String() string

String returns a string representation of the literal.

type ListLiteral

type ListLiteral struct {
	Vals []interface{}
}

ListLiteral represents a list of strings literal.

func (*ListLiteral) String

func (s *ListLiteral) String() string

String returns a string representation of the literal.

type Literal

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

Literal represents a static literal.

type Measurement

type Measurement struct {
	Database string
}

Measurement represents a single measurement used as a datasource.

func (*Measurement) ESString

func (m *Measurement) ESString() string

ESString ...

func (*Measurement) String

func (m *Measurement) String() string

String returns a string representation of the measurement.

type Measurements

type Measurements []*Measurement

Measurements represents a list of measurements.

func (Measurements) String

func (a Measurements) String() string

String returns a string representation of the measurements.

type Node

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

Node represents a node in the InfluxDB abstract syntax tree.

type NowValuer

type NowValuer struct {
	Now time.Time
}

NowValuer returns only the value for "now()".

func (*NowValuer) Value

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

Value is a method that returns the value and existence flag for a given key.

type NumberLiteral

type NumberLiteral struct {
	Val float64
}

NumberLiteral represents a numeric literal.

func (*NumberLiteral) String

func (l *NumberLiteral) String() string

String returns a string representation of the literal.

type ParenExpr

type ParenExpr struct {
	Expr Expr
}

ParenExpr represents a parenthesized expression.

func (*ParenExpr) String

func (e *ParenExpr) String() string

String returns a string representation of the parenthesized expression.

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() (Expr, error)

ParseExpr parses an expression.

func (*Parser) ParseStatement

func (p *Parser) ParseStatement() (Statement, error)

ParseStatement parses an InfluxQL string and returns a Statement AST object.

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 RegexLiteral

type RegexLiteral struct {
	Val *regexp.Regexp
}

RegexLiteral represents a regular expression.

func (*RegexLiteral) String

func (r *RegexLiteral) String() string

String returns a string representation of the literal.

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.

func (*Scanner) ScanNumber

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

ScanNumber consumes anything that looks like the start of a number. Numbers start with a digit, full stop, plus sign or minus sign. This function can return non-number tokens if a scan is a false positive. For example, a minus sign followed by a letter will just return a minus sign.

func (*Scanner) ScanRegex

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

ScanRegex consumes a token to find escapes

type SelectStatement

type SelectStatement struct {
	// Expressions returned from the selection.
	Fields Fields

	// Data sources that fields are extracted from.
	Sources Sources

	// An expression evaluated on data point.
	Condition Expr

	// Fields to sort results by
	SortFields SortFields

	// Maximum number of rows to be returned. Unlimited if zero.
	Limit int

	// Returns rows starting at an offset from the first row.
	Offset int

	// Expressions used for grouping the selection.
	Dimensions Dimensions

	// Expressions used for filter grouping buckets.
	Having Expr

	// if it's a query for raw data values (i.e. not an aggregate)
	IsRawQuery bool

	// Removes duplicate rows from raw queries.
	Dedupe bool
}

SelectStatement represents a command for extracting data from the database.

func (*SelectStatement) BucketSelectorAggregation

func (s *SelectStatement) BucketSelectorAggregation() *Agg

func (*SelectStatement) ColumnNames

func (s *SelectStatement) ColumnNames() []string

ColumnNames will walk all fields and functions and return the appropriate field names for the select statement while maintaining order of the field names

func (*SelectStatement) FunctionCalls

func (s *SelectStatement) FunctionCalls() []*Call

FunctionCalls returns the Call objects from the query

func (*SelectStatement) FunctionCallsByPosition

func (s *SelectStatement) FunctionCallsByPosition() [][]*Call

FunctionCallsByPosition returns the Call objects from the query in the order they appear in the select statement

func (*SelectStatement) HasDerivative

func (s *SelectStatement) HasDerivative() bool

HasDerivative returns true if one of the function calls in the statement is a derivative aggregate

func (*SelectStatement) IsSimpleDerivative

func (s *SelectStatement) IsSimpleDerivative() bool

IsSimpleDerivative return true if one of the function call is a derivative function with a variable ref as the first arg

func (*SelectStatement) NamesInDimension

func (s *SelectStatement) NamesInDimension() []string

NamesInDimension returns the field and tag names (idents) in the group by

func (*SelectStatement) NamesInHaving

func (s *SelectStatement) NamesInHaving() []string

NamesInHaving returns the field and tag names (idents) referenced in the having clause

func (*SelectStatement) NamesInSelect

func (s *SelectStatement) NamesInSelect() []string

NamesInSelect returns the field and tag names (idents) in the select clause

func (*SelectStatement) NamesInWhere

func (s *SelectStatement) NamesInWhere() []string

NamesInWhere returns the field and tag names (idents) referenced in the where clause

func (*SelectStatement) RewriteConditions

func (s *SelectStatement) RewriteConditions()

RewriteConditions ...

func (*SelectStatement) RewriteDimensions

func (s *SelectStatement) RewriteDimensions()

RewriteDimensions ...

func (*SelectStatement) RewriteHaving

func (s *SelectStatement) RewriteHaving()

RewriteHaving ...

func (*SelectStatement) String

func (s *SelectStatement) String() string

String returns a string representation of the select statement.

type SortField

type SortField struct {
	// Name of the field
	Name string

	// Sort order.
	Ascending bool
}

SortField represents a field to sort results by.

func (*SortField) String

func (field *SortField) String() string

String returns a string representation of a sort field

type SortFields

type SortFields []*SortField

SortFields represents an ordered list of ORDER BY fields

func (SortFields) String

func (a SortFields) String() string

String returns a string representation of sort fields

type Source

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

Source represents a source of data for a statement.

type Sources

type Sources []Source

Sources represents a list of sources.

func (Sources) Names

func (a Sources) Names() []string

Names returns a list of source names.

func (Sources) String

func (a Sources) String() string

String returns a string representation of a Sources array.

type Statement

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

Statement represents a single command in InfluxQL.

func ParseStatement

func ParseStatement(s string) (Statement, error)

ParseStatement parses a statement string and returns its AST representation.

type Statements

type Statements []Statement

Statements represents a list of statements.

func (Statements) String

func (a Statements) String() string

String returns a string representation of the statements.

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.

type Token

type Token int

Token is a lexical token of the InfluxQL language.

const (
	// ILLEGAL Token, EOF, WS are Special InfluxQL tokens.
	ILLEGAL Token = iota
	EOF
	WS

	// IDENT and the following are InfluxQL literal tokens.
	IDENT     // main
	NUMBER    // 12345.67
	INTEGER   // 12345
	STRING    // "abc"
	BADSTRING // "abc
	BADESCAPE // \q
	TRUE      // true
	FALSE     // false
	REGEX     // Regular expressions
	BADREGEX  // `.*

	// ADD and the following are InfluxQL Operators
	ADD // +
	SUB // -
	MUL // *
	DIV // /
	MOD // %

	AND // AND
	OR  // OR
	NI  // not in
	IN

	EQ       // =
	NEQ      // !=
	EQREGEX  // =~
	NEQREGEX // !~
	LT       // <
	LTE      // <=
	GT       // >
	GTE      // >=

	LBRACKET // [
	LPAREN   // (
	RBRACKET // ]
	RPAREN   // )
	COMMA    // ,
	DOT      // .

	// ALL and the following are InfluxQL Keywords
	AS
	ASC
	BY
	DESC
	FROM
	GROUP
	HAVING
	LIMIT
	ORDER
	SELECT
	WHERE
)

These are a comprehensive list of InfluxQL language tokens.

func Lookup

func Lookup(ident string) Token

Lookup returns the token associated with a given string.

func (Token) GroovyWrapped

func (tok Token) GroovyWrapped() string

GroovyWrapped ...

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 Valuer

type Valuer interface {
	Value(key string) (interface{}, bool)
}

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

Value returns the value and existence flag for a given key.

type VarRef

type VarRef struct {
	Val      string
	Segments []string
}

VarRef represents a reference to a variable.

func (*VarRef) GroovyWrapped

func (r *VarRef) GroovyWrapped() string

GroovyWrapped ...

func (*VarRef) String

func (r *VarRef) String() string

String returns a string representation of the variable reference.

type VarRefs

type VarRefs []VarRef

VarRefs represents a slice of VarRef types.

func (VarRefs) Strings

func (a VarRefs) Strings() []string

Strings returns a slice of the variable names.

type Visitor

type Visitor interface {
	Visit(Node) Visitor
}

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

type Wildcard

type Wildcard struct {
	Type Token
}

Wildcard represents a wild card expression.

func (*Wildcard) String

func (e *Wildcard) String() string

String returns a string representation of the wildcard.

Jump to

Keyboard shortcuts

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