cnosql

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinTime 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.
	MinTime = int64(math.MinInt64) + 2

	// MaxTime 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.
	MaxTime = int64(math.MaxInt64) - 1
)
View Source
const (
	// DateFormat represents the format for date literals.
	DateFormat = "2006-01-02"

	// DateTimeFormat represents the format for date time literals.
	DateTimeFormat = "2006-01-02 15:04:05.999999"
)

Variables

View Source
var ErrInvalidDuration = errors.New("invalid duration")

ErrInvalidDuration is returned when parsing a malformed duration.

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 Language = &ParseTree{}

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 ConditionExpr

func ConditionExpr(cond Expr, valuer Valuer) (Expr, TimeRange, error)

ConditionExpr extracts the time range and the condition from an expression. We only support simple time ranges that are constrained with AND and are not nested. This throws an error when we encounter a time condition that is combined with OR to prevent returning unexpected results that we do not support.

func ContainsVarRef

func ContainsVarRef(expr Expr) bool

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

func Eval

func Eval(expr Expr, m map[string]interface{}) interface{}

Eval evaluates expr against a map.

func EvalBool

func EvalBool(expr Expr, m map[string]interface{}) bool

EvalBool evaluates expr and returns true if result is a boolean true. Otherwise returns false.

func FieldDimensions

func FieldDimensions(sources Sources, m FieldMapper) (fields map[string]DataType, dimensions map[string]struct{}, err error)

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration to a string.

func HasTimeExpr

func HasTimeExpr(expr Expr) bool

HasTimeExpr returns true if the expression has a time term.

func IdentNeedsQuotes

func IdentNeedsQuotes(ident string) bool

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

func IsRegexOp

func IsRegexOp(t Token) bool

IsRegexOp returns true if the operator accepts a regex operand.

func IsSelector

func IsSelector(expr Expr) bool

func IsSystemName

func IsSystemName(name string) bool

IsSystemName returns true if name is an internal system name.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses a time duration from a string. This is needed instead of time.ParseDuration because this will support the full syntax that CnosQL supports for specifying durations including weeks and days.

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 Sanitize

func Sanitize(query string) string

Sanitize attempts to sanitize passwords out of a raw query. It looks for patterns that may be related to the SET PASSWORD and CREATE USER statements and will redact the password that should be there. It will attempt to redact information from common invalid queries too, but it's not guaranteed to succeed on improper queries.

This function works on the raw query and attempts to retain the original input as much as possible.

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 AlterRetentionPolicyStatement

type AlterRetentionPolicyStatement struct {
	// Name of policy to alter.
	Name string

	// Name of the database this policy belongs to.
	Database string

	// Duration data written to this policy will be retained.
	Duration *time.Duration

	// Replication factor for data written to this policy.
	Replication *int

	// Should this policy be set as defalut for the database?
	Default bool

	// Duration of the Shard.
	ShardGroupDuration *time.Duration
}

AlterRetentionPolicyStatement represents a command to alter an existing retention policy.

func (*AlterRetentionPolicyStatement) DefaultDatabase

func (s *AlterRetentionPolicyStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*AlterRetentionPolicyStatement) RequiredPrivileges

func (s *AlterRetentionPolicyStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute an AlterRetentionPolicyStatement.

func (*AlterRetentionPolicyStatement) String

String returns a string representation of the alter retention policy statement.

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 BooleanValue

type BooleanValue bool

BooleanValue is a boolean literal.

func (BooleanValue) TokenType

func (v BooleanValue) TokenType() Token

func (BooleanValue) Value

func (v BooleanValue) Value() string

type BoundParameter

type BoundParameter struct {
	Name string
}

BoundParameter represents a bound parameter literal. This is not available to the query language itself, but can be used when constructing a query string from an AST.

func (*BoundParameter) String

func (bp *BoundParameter) String() string

String returns a string representation of the bound parameter.

type Call

type Call struct {
	Name string
	Args []Expr
}

Call represents a function call.

func (*Call) String

func (c *Call) String() string

String returns a string representation of the call.

type CallTypeMapper

type CallTypeMapper interface {
	TypeMapper

	CallType(name string, args []DataType) (DataType, error)
}

CallTypeMapper maps a data type to the function call.

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 CreateContinuousQueryStatement

type CreateContinuousQueryStatement struct {
	// Name of the continuous query to be created.
	Name string

	// Name of the database to create the continuous query on.
	Database string

	// Source of data (SELECT statement).
	Source *SelectStatement

	// Interval to resample previous queries.
	ResampleEvery time.Duration

	// Maximum duration to resample previous queries.
	ResampleFor time.Duration
}

CreateContinuousQueryStatement represents a command for creating a continuous query.

func (*CreateContinuousQueryStatement) DefaultDatabase

func (s *CreateContinuousQueryStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*CreateContinuousQueryStatement) RequiredPrivileges

func (s *CreateContinuousQueryStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a CreateContinuousQueryStatement.

func (*CreateContinuousQueryStatement) String

String returns a string representation of the statement.

type CreateDatabaseStatement

type CreateDatabaseStatement struct {
	// Name of the database to be created.
	Name string

	// RetentionPolicyCreate indicates whether the user explicitly wants to create a retention policy.
	RetentionPolicyCreate bool

	// RetentionPolicyDuration indicates retention duration for the new database.
	RetentionPolicyDuration *time.Duration

	// RetentionPolicyReplication indicates retention replication for the new database.
	RetentionPolicyReplication *int

	// RetentionPolicyName indicates retention name for the new database.
	RetentionPolicyName string

	// RetentionPolicyShardGroupDuration indicates shard group duration for the new database.
	RetentionPolicyShardGroupDuration time.Duration
}

CreateDatabaseStatement represents a command for creating a new database.

func (*CreateDatabaseStatement) RequiredPrivileges

func (s *CreateDatabaseStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a CreateDatabaseStatement.

func (*CreateDatabaseStatement) String

func (s *CreateDatabaseStatement) String() string

String returns a string representation of the create database statement.

type CreateRetentionPolicyStatement

type CreateRetentionPolicyStatement struct {
	// Name of policy to create.
	Name string

	// Name of database this policy belongs to.
	Database string

	// Duration data written to this policy will be retained.
	Duration time.Duration

	// Replication factor for data written to this policy.
	Replication int

	// Should this policy be set as default for the database?
	Default bool

	// Shard Duration.
	ShardGroupDuration time.Duration
}

CreateRetentionPolicyStatement represents a command to create a retention policy.

func (*CreateRetentionPolicyStatement) DefaultDatabase

func (s *CreateRetentionPolicyStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*CreateRetentionPolicyStatement) RequiredPrivileges

func (s *CreateRetentionPolicyStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a CreateRetentionPolicyStatement.

func (*CreateRetentionPolicyStatement) String

String returns a string representation of the create retention policy.

type CreateSubscriptionStatement

type CreateSubscriptionStatement struct {
	Name            string
	Database        string
	RetentionPolicy string
	Destinations    []string
	Mode            string
}

CreateSubscriptionStatement represents a command to add a subscription to the incoming data stream.

func (*CreateSubscriptionStatement) DefaultDatabase

func (s *CreateSubscriptionStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*CreateSubscriptionStatement) RequiredPrivileges

func (s *CreateSubscriptionStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a CreateSubscriptionStatement.

func (*CreateSubscriptionStatement) String

func (s *CreateSubscriptionStatement) String() string

String returns a string representation of the CreateSubscriptionStatement.

type CreateUserStatement

type CreateUserStatement struct {
	// Name of the user to be created.
	Name string

	// User's password.
	Password string

	// User's admin privilege.
	Admin bool
}

CreateUserStatement represents a command for creating a new user.

func (*CreateUserStatement) RequiredPrivileges

func (s *CreateUserStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a CreateUserStatement.

func (*CreateUserStatement) String

func (s *CreateUserStatement) String() string

String returns a string representation of the create user statement.

type DataType

type DataType int

DataType represents the primitive data types available in CnosQL.

const (
	// Unknown primitive data type.
	Unknown DataType = 0
	// Float means the data type is a float.
	Float DataType = 1
	// Integer means the data type is an integer.
	Integer DataType = 2
	// String means the data type is a string of text.
	String DataType = 3
	// Boolean means the data type is a boolean.
	Boolean DataType = 4
	// Time means the data type is a time.
	Time DataType = 5
	// Duration means the data type is a duration of time.
	Duration DataType = 6
	// Tag means the data type is a tag.
	Tag DataType = 7
	// AnyField means the data type is any field.
	AnyField DataType = 8
	// Unsigned means the data type is an unsigned integer.
	Unsigned DataType = 9
)

func DataTypeFromString

func DataTypeFromString(s string) DataType

DataTypeFromString returns a data type given the string representation of that data type.

func EvalType

func EvalType(expr Expr, sources Sources, typmap TypeMapper) DataType

EvalType evaluates the expression's type.

func InspectDataType

func InspectDataType(v interface{}) DataType

InspectDataType returns the data type of a given value.

func (DataType) LessThan

func (d DataType) LessThan(other DataType) bool

LessThan returns true if the other DataType has greater precedence than the current data type. Unknown has the lowest precedence.

NOTE: This is not the same as using the `<` or `>` operator because the integers used decrease with higher precedence, but Unknown is the lowest precedence at the zero value.

func (DataType) String

func (d DataType) String() string

String returns the human-readable string representation of the DataType.

func (DataType) Zero

func (d DataType) Zero() interface{}

Zero returns the zero value for the DataType. The return value of this method, when sent back to InspectDataType, may not produce the same value.

type DeleteSeriesStatement

type DeleteSeriesStatement struct {
	// Data source that fields are extracted from (optional)
	Sources Sources

	// An expression evaluated on data point (optional)
	Condition Expr
}

DeleteSeriesStatement represents a command for deleting all or part of a series from a database.

func (DeleteSeriesStatement) RequiredPrivileges

func (s DeleteSeriesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DeleteSeriesStatement.

func (*DeleteSeriesStatement) String

func (s *DeleteSeriesStatement) String() string

String returns a string representation of the delete series statement.

type DeleteStatement

type DeleteStatement struct {
	// Data source that values are removed from.
	Source Source

	// An expression evaluated on data point.
	Condition Expr
}

DeleteStatement represents a command for deleting data from the database.

func (*DeleteStatement) DefaultDatabase

func (s *DeleteStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*DeleteStatement) RequiredPrivileges

func (s *DeleteStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DeleteStatement.

func (*DeleteStatement) String

func (s *DeleteStatement) String() string

String returns a string representation of the delete statement.

type Dimension

type Dimension struct {
	Expr Expr
}

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) Normalize

func (a Dimensions) Normalize() (time.Duration, []string)

Normalize returns the interval and tag dimensions separately. Returns 0 if no time interval is specified.

func (Dimensions) String

func (a Dimensions) String() string

String returns a string representation of the dimensions.

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.

type DropContinuousQueryStatement

type DropContinuousQueryStatement struct {
	Name     string
	Database string
}

DropContinuousQueryStatement represents a command for removing a continuous query.

func (*DropContinuousQueryStatement) DefaultDatabase

func (s *DropContinuousQueryStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*DropContinuousQueryStatement) RequiredPrivileges

func (s *DropContinuousQueryStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a DropContinuousQueryStatement

func (*DropContinuousQueryStatement) String

String returns a string representation of the statement.

type DropDatabaseStatement

type DropDatabaseStatement struct {
	// Name of the database to be dropped.
	Name string
}

DropDatabaseStatement represents a command to drop a database.

func (*DropDatabaseStatement) RequiredPrivileges

func (s *DropDatabaseStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DropDatabaseStatement.

func (*DropDatabaseStatement) String

func (s *DropDatabaseStatement) String() string

String returns a string representation of the drop database statement.

type DropMeasurementStatement

type DropMeasurementStatement struct {
	// Name of the measurement to be dropped.
	Name string
}

DropMeasurementStatement represents a command to drop a measurement.

func (*DropMeasurementStatement) RequiredPrivileges

func (s *DropMeasurementStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a DropMeasurementStatement

func (*DropMeasurementStatement) String

func (s *DropMeasurementStatement) String() string

String returns a string representation of the drop measurement statement.

type DropRetentionPolicyStatement

type DropRetentionPolicyStatement struct {
	// Name of the policy to drop.
	Name string

	// Name of the database to drop the policy from.
	Database string
}

DropRetentionPolicyStatement represents a command to drop a retention policy from a database.

func (*DropRetentionPolicyStatement) DefaultDatabase

func (s *DropRetentionPolicyStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*DropRetentionPolicyStatement) RequiredPrivileges

func (s *DropRetentionPolicyStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DropRetentionPolicyStatement.

func (*DropRetentionPolicyStatement) String

String returns a string representation of the drop retention policy statement.

type DropSeriesStatement

type DropSeriesStatement struct {
	// Data source that fields are extracted from (optional)
	Sources Sources

	// An expression evaluated on data point (optional)
	Condition Expr
}

DropSeriesStatement represents a command for removing a series from the database.

func (DropSeriesStatement) RequiredPrivileges

func (s DropSeriesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DropSeriesStatement.

func (*DropSeriesStatement) String

func (s *DropSeriesStatement) String() string

String returns a string representation of the drop series statement.

type DropShardStatement

type DropShardStatement struct {
	// ID of the shard to be dropped.
	ID uint64
}

DropShardStatement represents a command for removing a shard from the node.

func (*DropShardStatement) RequiredPrivileges

func (s *DropShardStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DropShardStatement.

func (*DropShardStatement) String

func (s *DropShardStatement) String() string

String returns a string representation of the drop series statement.

type DropSubscriptionStatement

type DropSubscriptionStatement struct {
	Name            string
	Database        string
	RetentionPolicy string
}

DropSubscriptionStatement represents a command to drop a subscription to the incoming data stream.

func (*DropSubscriptionStatement) DefaultDatabase

func (s *DropSubscriptionStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*DropSubscriptionStatement) RequiredPrivileges

func (s *DropSubscriptionStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a DropSubscriptionStatement

func (*DropSubscriptionStatement) String

func (s *DropSubscriptionStatement) String() string

String returns a string representation of the DropSubscriptionStatement.

type DropUserStatement

type DropUserStatement struct {
	// Name of the user to drop.
	Name string
}

DropUserStatement represents a command for dropping a user.

func (*DropUserStatement) RequiredPrivileges

func (s *DropUserStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a DropUserStatement.

func (*DropUserStatement) String

func (s *DropUserStatement) String() string

String returns a string representation of the drop user statement.

type DurationLiteral

type DurationLiteral struct {
	Val time.Duration
}

DurationLiteral represents a duration literal.

func (*DurationLiteral) String

func (l *DurationLiteral) String() string

String returns a string representation of the literal.

type DurationValue

type DurationValue string

DurationValue is a duration literal.

func (DurationValue) TokenType

func (v DurationValue) TokenType() Token

func (DurationValue) Value

func (v DurationValue) Value() string

type ErrorValue

type ErrorValue string

ErrorValue is a special value that returns an error during parsing when it is used.

func (ErrorValue) TokenType

func (e ErrorValue) TokenType() Token

func (ErrorValue) Value

func (e ErrorValue) Value() string

type ExecutionPrivilege

type ExecutionPrivilege struct {
	// Admin privilege required.
	Admin bool

	// Name of the database.
	Name string

	// Database privilege required.
	Privilege Privilege
}

ExecutionPrivilege is a privilege required for a user to execute a statement on a database or resource.

type ExecutionPrivileges

type ExecutionPrivileges []ExecutionPrivilege

ExecutionPrivileges is a list of privileges required to execute a statement.

type ExplainStatement

type ExplainStatement struct {
	Statement *SelectStatement

	Analyze bool
}

ExplainStatement represents a command for explaining a select statement.

func (*ExplainStatement) RequiredPrivileges

func (e *ExplainStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ExplainStatement.

func (*ExplainStatement) String

func (e *ExplainStatement) String() string

String returns a string representation of the explain statement.

type Expr

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

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

func CloneExpr

func CloneExpr(expr Expr) Expr

CloneExpr returns a deep copy of the expression.

func MustParseExpr

func MustParseExpr(s string) Expr

MustParseExpr parses an expression string and returns its AST. Panic on error.

func ParseExpr

func ParseExpr(s string) (Expr, error)

ParseExpr parses an expression string and returns its AST representation.

func Reduce

func Reduce(expr Expr, valuer Valuer) Expr

Reduce evaluates expr using the available values in valuer. References that don't exist in valuer are ignored.

func RewriteExpr

func RewriteExpr(expr Expr, fn func(Expr) Expr) Expr

RewriteExpr recursively invokes the function to replace each expr. Nodes are traversed depth-first and rewritten from leaf to root.

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 FieldMapper

type FieldMapper interface {
	FieldDimensions(m *Measurement) (fields map[string]DataType, dimensions map[string]struct{}, err error)

	TypeMapper
}

FieldMapper returns the data type for the field inside of the measurement.

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

Len implements sort.Interface.

func (Fields) Less

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

Less implements sort.Interface.

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)

Swap implements sort.Interface.

type FillOption

type FillOption int

FillOption represents different options for filling aggregate windows.

const (
	// NullFill means that empty aggregate windows will just have null values.
	NullFill FillOption = iota
	// NoFill means that empty aggregate windows will be purged from the result.
	NoFill
	// NumberFill means that empty aggregate windows will be filled with a provided number.
	NumberFill
	// PreviousFill means that empty aggregate windows will be filled with whatever the previous aggregate window had.
	PreviousFill
	// LinearFill means that empty aggregate windows will be filled with whatever a linear value between non null windows.
	LinearFill
)

type GrantAdminStatement

type GrantAdminStatement struct {
	// Who to grant the privilege to.
	User string
}

GrantAdminStatement represents a command for granting admin privilege.

func (*GrantAdminStatement) RequiredPrivileges

func (s *GrantAdminStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a GrantAdminStatement.

func (*GrantAdminStatement) String

func (s *GrantAdminStatement) String() string

String returns a string representation of the grant admin statement.

type GrantStatement

type GrantStatement struct {
	// The privilege to be granted.
	Privilege Privilege

	// Database to grant the privilege to.
	On string

	// Who to grant the privilege to.
	User string
}

GrantStatement represents a command for granting a privilege.

func (*GrantStatement) DefaultDatabase

func (s *GrantStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*GrantStatement) RequiredPrivileges

func (s *GrantStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a GrantStatement.

func (*GrantStatement) String

func (s *GrantStatement) String() string

String returns a string representation of the grant statement.

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 Identifier

type Identifier string

Identifier is an identifier value.

func (Identifier) TokenType

func (v Identifier) TokenType() Token

func (Identifier) Value

func (v Identifier) Value() string

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 IntegerValue

type IntegerValue int64

IntegerValue is an integer literal.

func (IntegerValue) TokenType

func (v IntegerValue) TokenType() Token

func (IntegerValue) Value

func (v IntegerValue) Value() string

type KillQueryStatement

type KillQueryStatement struct {
	// The query to kill.
	QueryID uint64

	// The host to delegate the kill to.
	Host string
}

KillQueryStatement represents a command for killing a query.

func (*KillQueryStatement) RequiredPrivileges

func (s *KillQueryStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a KillQueryStatement.

func (*KillQueryStatement) String

func (s *KillQueryStatement) String() string

String returns a string representation of the kill query statement.

type ListLiteral

type ListLiteral struct {
	Vals []string
}

ListLiteral represents a list of tag key literals.

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 MapValuer

type MapValuer map[string]interface{}

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

func (MapValuer) Value

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

Value returns the value for a key in the MapValuer.

type Measurement

type Measurement struct {
	Database        string
	RetentionPolicy string
	Name            string
	Regex           *RegexLiteral
	IsTarget        bool

	// This field indicates that the measurement should read be read from the
	// specified system iterator.
	SystemIterator string
}

Measurement represents a single measurement used as a datasource.

func (*Measurement) Clone

func (m *Measurement) Clone() *Measurement

Clone returns a deep clone of the Measurement.

func (*Measurement) MarshalBinary

func (m *Measurement) MarshalBinary() ([]byte, error)

MarshalBinary encodes a Measurement to a binary format.

func (*Measurement) String

func (m *Measurement) String() string

String returns a string representation of the measurement.

func (*Measurement) UnmarshalBinary

func (m *Measurement) UnmarshalBinary(buf []byte) error

UnmarshalBinary decodes binary data into a 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 NilLiteral

type NilLiteral struct{}

NilLiteral represents a nil literal. This is not available to the query language itself. It's only used internally.

func (*NilLiteral) String

func (l *NilLiteral) String() string

String returns a string representation of the literal.

type Node

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

Node represents a node in the CnosDB abstract syntax tree.

func Rewrite

func Rewrite(r Rewriter, node Node) Node

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

func RewriteFunc

func RewriteFunc(node Node, fn func(Node) Node) Node

RewriteFunc rewrites a node hierarchy.

type NowValuer

type NowValuer struct {
	Now      time.Time
	Location *time.Location
}

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

func (*NowValuer) Call

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

Call evaluates the now() function to replace now() with the current time.

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.

func (*NowValuer) Zone

func (v *NowValuer) Zone() *time.Location

Zone is a method that returns the time.Location.

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 NumberValue

type NumberValue float64

NumberValue is a number literal.

func (NumberValue) TokenType

func (v NumberValue) TokenType() Token

func (NumberValue) Value

func (v NumberValue) Value() string

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 ParseTree

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

func (*ParseTree) Clone

func (t *ParseTree) Clone() *ParseTree

func (*ParseTree) Group

func (t *ParseTree) Group(tokens ...Token) *ParseTree

Group groups together a set of related handlers with a common token prefix.

func (*ParseTree) Handle

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

Handle registers a handler to be invoked when seeing the given token.

func (*ParseTree) Parse

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

Parse parses a statement using the language defined in the parse tree.

func (*ParseTree) With

func (t *ParseTree) With(fn func(*ParseTree))

With passes the current parse tree to a function to allow nested functions.

type Parser

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

Parser represents an CnosQL parser.

func NewParser

func NewParser(r io.Reader) *Parser

NewParser returns a new instance of Parser.

func (*Parser) ParseDuration

func (p *Parser) ParseDuration() (time.Duration, error)

ParseDuration parses a string and returns a duration literal. This function assumes the DURATION token has already been consumed.

func (*Parser) ParseExpr

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

ParseExpr parses an expression.

func (*Parser) ParseIdent

func (p *Parser) ParseIdent() (string, error)

ParseIdent parses an identifier.

func (*Parser) ParseIdentList

func (p *Parser) ParseIdentList() ([]string, error)

ParseIdentList parses a comma delimited list of identifiers.

func (*Parser) ParseInt

func (p *Parser) ParseInt(min, max int) (int, error)

ParseInt parses a string representing a base 10 integer and returns the number. It returns an error if the parsed number is outside the range [min, max].

func (*Parser) ParseOptionalTokenAndInt

func (p *Parser) ParseOptionalTokenAndInt(t Token) (int, error)

ParseOptionalTokenAndInt parses the specified token followed by an int, if it exists.

func (*Parser) ParseQuery

func (p *Parser) ParseQuery() (*Query, error)

ParseQuery parses an CnosQL string and returns a Query AST object.

func (*Parser) ParseStatement

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

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

func (*Parser) ParseUInt64

func (p *Parser) ParseUInt64() (uint64, error)

ParseUInt64 parses a string and returns a 64-bit unsigned integer literal.

func (*Parser) ParseVarRef

func (p *Parser) ParseVarRef() (*VarRef, error)

ParseVarRef parses a reference to a measurement or field.

func (*Parser) Scan

func (p *Parser) Scan() (tok Token, pos Pos, lit string)

Scan returns the next token from the underlying scanner.

func (*Parser) ScanIgnoreWhitespace

func (p *Parser) ScanIgnoreWhitespace() (tok Token, pos Pos, lit string)

ScanIgnoreWhitespace scans the next non-whitespace and non-comment token.

func (*Parser) ScanRegex

func (p *Parser) ScanRegex() (tok Token, pos Pos, lit string)

ScanRegex returns the next token from the underlying scanner using the regex scanner.

func (*Parser) SetParams

func (p *Parser) SetParams(params map[string]interface{})

SetParams sets the parameters that will be used for any bound parameter substitutions.

func (*Parser) Unscan

func (p *Parser) Unscan()

Unscan pushes the previously read token back onto the buffer.

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 Privilege

type Privilege int

Privilege is a type of action a user can be granted the right to use.

const (
	// NoPrivileges means no privileges required / granted / revoked.
	NoPrivileges Privilege = iota
	// ReadPrivilege means read privilege required / granted / revoked.
	ReadPrivilege
	// WritePrivilege means write privilege required / granted / revoked.
	WritePrivilege
	// AllPrivileges means all privileges required / granted / revoked.
	AllPrivileges
)

func NewPrivilege

func NewPrivilege(p Privilege) *Privilege

NewPrivilege returns an initialized *Privilege.

func (Privilege) String

func (p Privilege) String() string

String returns a string representation of a Privilege.

type Query

type Query struct {
	Statements Statements
}

Query represents a collection of ordered statements.

func ParseQuery

func ParseQuery(s string) (*Query, error)

ParseQuery parses a query string and returns its AST representation.

func (*Query) String

func (q *Query) String() string

String returns a string representation of the query.

type RegexLiteral

type RegexLiteral struct {
	Val *regexp.Regexp
}

RegexLiteral represents a regular expression.

func CloneRegexLiteral

func CloneRegexLiteral(r *RegexLiteral) *RegexLiteral

CloneRegexLiteral returns a clone of the RegexLiteral.

func (*RegexLiteral) String

func (r *RegexLiteral) String() string

String returns a string representation of the literal.

type RegexValue

type RegexValue string

RegexValue is a regexp literal.

func (RegexValue) TokenType

func (v RegexValue) TokenType() Token

func (RegexValue) Value

func (v RegexValue) Value() string

type RevokeAdminStatement

type RevokeAdminStatement struct {
	// Who to revoke admin privilege from.
	User string
}

RevokeAdminStatement represents a command to revoke admin privilege from a user.

func (*RevokeAdminStatement) RequiredPrivileges

func (s *RevokeAdminStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a RevokeAdminStatement.

func (*RevokeAdminStatement) String

func (s *RevokeAdminStatement) String() string

String returns a string representation of the revoke admin statement.

type RevokeStatement

type RevokeStatement struct {
	// The privilege to be revoked.
	Privilege Privilege

	// Database to revoke the privilege from.
	On string

	// Who to revoke privilege from.
	User string
}

RevokeStatement represents a command to revoke a privilege from a user.

func (*RevokeStatement) DefaultDatabase

func (s *RevokeStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*RevokeStatement) RequiredPrivileges

func (s *RevokeStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a RevokeStatement.

func (*RevokeStatement) String

func (s *RevokeStatement) String() string

String returns a string representation of the revoke statement.

type Rewriter

type Rewriter interface {
	Rewrite(Node) Node
}

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

type Scanner

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

Scanner represents a lexical scanner for CnosQL.

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) 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

	// Target (destination) for the result of a SELECT INTO query.
	Target *Target

	// Expressions used for grouping the selection.
	Dimensions Dimensions

	// Data sources (measurements) 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

	// Maxiumum number of series to be returned. Unlimited if zero.
	SLimit int

	// Returns series starting at an offset from the first one.
	SOffset int

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

	// What fill option the select statement uses, if any.
	Fill FillOption

	// The value to fill empty aggregate buckets with, if any.
	FillValue interface{}

	// The timezone for the query, if any.
	Location *time.Location

	// Renames the implicit time field name.
	TimeAlias string

	// Removes the "time" column from the output.
	OmitTime bool

	// Removes measurement name from resulting query. Useful for meta queries.
	StripName bool

	// Overrides the output measurement name.
	EmitName string

	// Removes duplicate rows from raw queries.
	Dedupe bool
	// contains filtered or unexported fields
}

SelectStatement represents a command for extracting data from the database.

func (*SelectStatement) Clone

func (s *SelectStatement) Clone() *SelectStatement

Clone returns a deep copy of the statement.

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) FieldExprByName

func (s *SelectStatement) FieldExprByName(name string) (int, Expr)

FieldExprByName returns the expression that matches the field name and the index where this was found. If the name matches one of the arguments to "top" or "bottom", the variable reference inside of the function is returned and the index is of the function call rather than the variable reference. If no expression is found, -1 is returned for the index and the expression will be nil.

func (*SelectStatement) GroupByInterval

func (s *SelectStatement) GroupByInterval() (time.Duration, error)

GroupByInterval extracts the time interval, if specified.

func (*SelectStatement) GroupByOffset

func (s *SelectStatement) GroupByOffset() (time.Duration, error)

GroupByOffset extracts the time interval offset, if specified.

func (*SelectStatement) HasDimensionWildcard

func (s *SelectStatement) HasDimensionWildcard() bool

HasDimensionWildcard returns whether or not the select statement has at least 1 wildcard in the dimensions aka `GROUP BY`.

func (*SelectStatement) HasFieldWildcard

func (s *SelectStatement) HasFieldWildcard() (hasWildcard bool)

HasFieldWildcard returns whether or not the select statement has at least 1 wildcard in the fields.

func (*SelectStatement) HasWildcard

func (s *SelectStatement) HasWildcard() bool

HasWildcard returns whether or not the select statement has at least 1 wildcard.

func (*SelectStatement) Reduce

func (s *SelectStatement) Reduce(valuer Valuer) *SelectStatement

Reduce calls the Reduce function on the different components of the SelectStatement to reduce the statement.

func (*SelectStatement) RequiredPrivileges

func (s *SelectStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute the SelectStatement. NOTE: Statement should be normalized first (database name(s) in Sources and Target should be populated). If the statement has not been normalized, an empty string will be returned for the database name and it is up to the caller to interpret that as the default database.

func (*SelectStatement) RewriteDistinct

func (s *SelectStatement) RewriteDistinct()

RewriteDistinct rewrites the expression to be a call for map/reduce to work correctly. This method assumes all validation has passed.

func (*SelectStatement) RewriteFields

func (s *SelectStatement) RewriteFields(m FieldMapper) (*SelectStatement, error)

RewriteFields returns the re-written form of the select statement. Any wildcard query fields are replaced with the supplied fields, and any wildcard GROUP BY fields are replaced with the supplied dimensions. Any fields with no type specifier are rewritten with the appropriate type.

func (*SelectStatement) RewriteRegexConditions

func (s *SelectStatement) RewriteRegexConditions()

RewriteRegexConditions rewrites regex conditions to make better use of the database index.

Conditions that can currently be simplified are:

  • host =~ /^foo$/ becomes host = 'foo'
  • host !~ /^foo$/ becomes host != 'foo'

Note: if the regex contains groups, character classes, repetition or similar, it's likely it won't be rewritten. In order to support rewriting regexes with these characters would be a lot more work.

func (*SelectStatement) RewriteTimeFields

func (s *SelectStatement) RewriteTimeFields()

RewriteTimeFields removes any "time" field references.

func (*SelectStatement) SetTimeRange

func (s *SelectStatement) SetTimeRange(start, end time.Time) error

SetTimeRange sets the start and end time of the select statement to [start, end). i.e. start inclusive, end exclusive. This is used commonly for continuous queries so the start and end are in buckets.

func (*SelectStatement) String

func (s *SelectStatement) String() string

String returns a string representation of the select statement.

func (*SelectStatement) TimeAscending

func (s *SelectStatement) TimeAscending() bool

TimeAscending returns true if the time field is sorted in chronological order.

func (*SelectStatement) TimeFieldName

func (s *SelectStatement) TimeFieldName() string

TimeFieldName returns the name of the time field.

func (*SelectStatement) ValidateDimensions added in v1.0.3

func (s *SelectStatement) ValidateDimensions(mapper FieldMapper) error

type SetPasswordUserStatement

type SetPasswordUserStatement struct {
	// Plain-text password.
	Password string

	// Who to grant the privilege to.
	Name string
}

SetPasswordUserStatement represents a command for changing user password.

func (*SetPasswordUserStatement) RequiredPrivileges

func (s *SetPasswordUserStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a SetPasswordUserStatement.

func (*SetPasswordUserStatement) String

func (s *SetPasswordUserStatement) String() string

String returns a string representation of the set password statement.

type ShowContinuousQueriesStatement

type ShowContinuousQueriesStatement struct{}

ShowContinuousQueriesStatement represents a command for listing continuous queries.

func (*ShowContinuousQueriesStatement) RequiredPrivileges

func (s *ShowContinuousQueriesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowContinuousQueriesStatement.

func (*ShowContinuousQueriesStatement) String

String returns a string representation of the show continuous queries statement.

type ShowDatabasesStatement

type ShowDatabasesStatement struct{}

ShowDatabasesStatement represents a command for listing all databases in the cluster.

func (*ShowDatabasesStatement) RequiredPrivileges

func (s *ShowDatabasesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowDatabasesStatement.

func (*ShowDatabasesStatement) String

func (s *ShowDatabasesStatement) String() string

String returns a string representation of the show databases command.

type ShowDiagnosticsStatement

type ShowDiagnosticsStatement struct {
	// Module
	Module string
}

ShowDiagnosticsStatement represents a command for show node diagnostics.

func (*ShowDiagnosticsStatement) RequiredPrivileges

func (s *ShowDiagnosticsStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowDiagnosticsStatement

func (*ShowDiagnosticsStatement) String

func (s *ShowDiagnosticsStatement) String() string

String returns a string representation of the ShowDiagnosticsStatement.

type ShowFieldKeyCardinalityStatement

type ShowFieldKeyCardinalityStatement struct {
	Database      string
	Exact         bool
	Sources       Sources
	Condition     Expr
	Dimensions    Dimensions
	Limit, Offset int
}

ShowFieldKeyCardinalityStatement represents a command for listing field key cardinality.

func (*ShowFieldKeyCardinalityStatement) DefaultDatabase

func (s *ShowFieldKeyCardinalityStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowFieldKeyCardinalityStatement) RequiredPrivileges

func (s *ShowFieldKeyCardinalityStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowFieldKeyCardinalityStatement.

func (*ShowFieldKeyCardinalityStatement) String

String returns a string representation of the statement.

type ShowFieldKeysStatement

type ShowFieldKeysStatement struct {
	// Database to query. If blank, use the default database.
	// The database can also be specified per source in the Sources.
	Database string

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

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

ShowFieldKeysStatement represents a command for listing field keys.

func (*ShowFieldKeysStatement) DefaultDatabase

func (s *ShowFieldKeysStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowFieldKeysStatement) RequiredPrivileges

func (s *ShowFieldKeysStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowFieldKeysStatement.

func (*ShowFieldKeysStatement) String

func (s *ShowFieldKeysStatement) String() string

String returns a string representation of the statement.

type ShowGrantsForUserStatement

type ShowGrantsForUserStatement struct {
	// Name of the user to display privileges.
	Name string
}

ShowGrantsForUserStatement represents a command for listing user privileges.

func (*ShowGrantsForUserStatement) RequiredPrivileges

func (s *ShowGrantsForUserStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowGrantsForUserStatement

func (*ShowGrantsForUserStatement) String

func (s *ShowGrantsForUserStatement) String() string

String returns a string representation of the show grants for user.

type ShowMeasurementCardinalityStatement

type ShowMeasurementCardinalityStatement struct {
	Exact         bool // If false then cardinality estimation will be used.
	Database      string
	Sources       Sources
	Condition     Expr
	Dimensions    Dimensions
	Limit, Offset int
}

ShowMeasurementCardinalityStatement represents a command for listing measurement cardinality.

func (*ShowMeasurementCardinalityStatement) DefaultDatabase

func (s *ShowMeasurementCardinalityStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowMeasurementCardinalityStatement) RequiredPrivileges

RequiredPrivileges returns the privilege required to execute a ShowMeasurementCardinalityStatement.

func (*ShowMeasurementCardinalityStatement) String

String returns a string representation of the statement.

type ShowMeasurementsStatement

type ShowMeasurementsStatement struct {
	// Database to query. If blank, use the default database.
	Database string

	// Retention policy to query. If blank, use all retention policies (do not use default)
	RetentionPolicy string

	WildcardDatabase        bool
	WildcardRetentionPolicy bool
	// Measurement name or regex.
	Source Source

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

ShowMeasurementsStatement represents a command for listing measurements.

func (*ShowMeasurementsStatement) DefaultDatabase

func (s *ShowMeasurementsStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowMeasurementsStatement) RequiredPrivileges

func (s *ShowMeasurementsStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowMeasurementsStatement.

func (*ShowMeasurementsStatement) String

func (s *ShowMeasurementsStatement) String() string

String returns a string representation of the statement.

type ShowQueriesStatement

type ShowQueriesStatement struct{}

ShowQueriesStatement represents a command for listing all running queries.

func (*ShowQueriesStatement) RequiredPrivileges

func (s *ShowQueriesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowQueriesStatement.

func (*ShowQueriesStatement) String

func (s *ShowQueriesStatement) String() string

String returns a string representation of the show queries statement.

type ShowRetentionPoliciesStatement

type ShowRetentionPoliciesStatement struct {
	// Name of the database to list policies for.
	Database string
}

ShowRetentionPoliciesStatement represents a command for listing retention policies.

func (*ShowRetentionPoliciesStatement) DefaultDatabase

func (s *ShowRetentionPoliciesStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowRetentionPoliciesStatement) RequiredPrivileges

func (s *ShowRetentionPoliciesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowRetentionPoliciesStatement

func (*ShowRetentionPoliciesStatement) String

String returns a string representation of a ShowRetentionPoliciesStatement.

type ShowSeriesCardinalityStatement

type ShowSeriesCardinalityStatement struct {
	// Database to query. If blank, use the default database.
	// The database can also be specified per source in the Sources.
	Database string

	// Specifies whether the user requires exact counting or not.
	Exact bool

	// Measurement(s) the series are listed for.
	Sources Sources

	// An expression evaluated on a series name or tag.
	Condition Expr

	// Expressions used for grouping the selection.
	Dimensions Dimensions

	Limit, Offset int
}

ShowSeriesCardinalityStatement represents a command for listing series cardinality.

func (*ShowSeriesCardinalityStatement) DefaultDatabase

func (s *ShowSeriesCardinalityStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowSeriesCardinalityStatement) RequiredPrivileges

func (s *ShowSeriesCardinalityStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowSeriesCardinalityStatement.

func (*ShowSeriesCardinalityStatement) String

String returns a string representation of the show continuous queries statement.

type ShowSeriesStatement

type ShowSeriesStatement struct {
	// Database to query. If blank, use the default database.
	// The database can also be specified per source in the Sources.
	Database string

	// Measurement(s) the series are listed for.
	Sources Sources

	// An expression evaluated on a series name or tag.
	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
}

ShowSeriesStatement represents a command for listing series in the database.

func (*ShowSeriesStatement) DefaultDatabase

func (s *ShowSeriesStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowSeriesStatement) RequiredPrivileges

func (s *ShowSeriesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowSeriesStatement.

func (*ShowSeriesStatement) String

func (s *ShowSeriesStatement) String() string

String returns a string representation of the list series statement.

type ShowShardGroupsStatement

type ShowShardGroupsStatement struct{}

ShowShardGroupsStatement represents a command for displaying shard groups in the cluster.

func (*ShowShardGroupsStatement) RequiredPrivileges

func (s *ShowShardGroupsStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privileges required to execute the statement.

func (*ShowShardGroupsStatement) String

func (s *ShowShardGroupsStatement) String() string

String returns a string representation of the SHOW SHARD GROUPS command.

type ShowShardsStatement

type ShowShardsStatement struct{}

ShowShardsStatement represents a command for displaying shards in the cluster.

func (*ShowShardsStatement) RequiredPrivileges

func (s *ShowShardsStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privileges required to execute the statement.

func (*ShowShardsStatement) String

func (s *ShowShardsStatement) String() string

String returns a string representation.

type ShowStatsStatement

type ShowStatsStatement struct {
	Module string
}

ShowStatsStatement displays statistics for a given module.

func (*ShowStatsStatement) RequiredPrivileges

func (s *ShowStatsStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowStatsStatement

func (*ShowStatsStatement) String

func (s *ShowStatsStatement) String() string

String returns a string representation of a ShowStatsStatement.

type ShowSubscriptionsStatement

type ShowSubscriptionsStatement struct {
}

ShowSubscriptionsStatement represents a command to show a list of subscriptions.

func (*ShowSubscriptionsStatement) RequiredPrivileges

func (s *ShowSubscriptionsStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowSubscriptionsStatement.

func (*ShowSubscriptionsStatement) String

func (s *ShowSubscriptionsStatement) String() string

String returns a string representation of the ShowSubscriptionsStatement.

type ShowTagKeyCardinalityStatement

type ShowTagKeyCardinalityStatement struct {
	Database      string
	Exact         bool
	Sources       Sources
	Condition     Expr
	Dimensions    Dimensions
	Limit, Offset int
}

ShowTagKeyCardinalityStatement represents a command for listing tag key cardinality.

func (*ShowTagKeyCardinalityStatement) DefaultDatabase

func (s *ShowTagKeyCardinalityStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowTagKeyCardinalityStatement) RequiredPrivileges

func (s *ShowTagKeyCardinalityStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowTagKeyCardinalityStatement.

func (*ShowTagKeyCardinalityStatement) String

String returns a string representation of the statement.

type ShowTagKeysStatement

type ShowTagKeysStatement struct {
	// Database to query. If blank, use the default database.
	// The database can also be specified per source in the Sources.
	Database string

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

	// Op to compare tag keys with
	TagKeyOp Token

	// Literal to compare tag keys with
	TagKeyExpr Expr
	// An expression evaluated on data point.
	Condition Expr

	// Fields to sort results by.
	SortFields SortFields

	// Maximum number of tag keys per measurement. Unlimited if zero.
	Limit int

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

	// Maxiumum number of series to be returned. Unlimited if zero.
	SLimit int

	// Returns series starting at an offset from the first one.
	SOffset int
}

ShowTagKeysStatement represents a command for listing tag keys.

func (*ShowTagKeysStatement) DefaultDatabase

func (s *ShowTagKeysStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowTagKeysStatement) RequiredPrivileges

func (s *ShowTagKeysStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowTagKeysStatement.

func (*ShowTagKeysStatement) String

func (s *ShowTagKeysStatement) String() string

String returns a string representation of the statement.

type ShowTagValuesCardinalityStatement

type ShowTagValuesCardinalityStatement struct {
	Database      string
	Exact         bool
	Sources       Sources
	Op            Token
	TagKeyExpr    Literal
	Condition     Expr
	Dimensions    Dimensions
	Limit, Offset int
}

ShowTagValuesCardinalityStatement represents a command for listing tag value cardinality.

func (*ShowTagValuesCardinalityStatement) DefaultDatabase

func (s *ShowTagValuesCardinalityStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowTagValuesCardinalityStatement) RequiredPrivileges

func (s *ShowTagValuesCardinalityStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege required to execute a ShowTagValuesCardinalityStatement.

func (*ShowTagValuesCardinalityStatement) String

String returns a string representation of the statement.

type ShowTagValuesStatement

type ShowTagValuesStatement struct {
	// Database to query. If blank, use the default database.
	// The database can also be specified per source in the Sources.
	Database string

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

	// Operation to use when selecting tag key(s).
	// This is one of: (associated TagKeyExpr Literal
	// type in parentheses:
	// 	EQ (*StringLiteral)
	//	NEQ (*StringLiteral)
	//	IN (*ListLiteral)
	//	EQREGEX (*RegexLiteral)
	//	NEQREGEX (*RegexLiteral)
	Op Token

	// Literal to compare the tag key(s) with.
	// The value of the above Op field determines its dynamic type.
	TagKeyExpr Literal

	// An expression evaluated on each data point.
	Condition Expr

	// NOTE: The specification doesn't permit ORDER BY in
	// a SHOW TAG VALUES statement and this field is
	// ignored in practice. It's only left here to maintain
	// backward compatibility.
	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
}

ShowTagValuesStatement represents a command for listing tag values.

func (*ShowTagValuesStatement) DefaultDatabase

func (s *ShowTagValuesStatement) DefaultDatabase() string

DefaultDatabase returns the default database from the statement.

func (*ShowTagValuesStatement) RequiredPrivileges

func (s *ShowTagValuesStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowTagValuesStatement.

func (*ShowTagValuesStatement) String

func (s *ShowTagValuesStatement) String() string

String returns a string representation of the statement.

type ShowUsersStatement

type ShowUsersStatement struct{}

ShowUsersStatement represents a command for listing users.

func (*ShowUsersStatement) RequiredPrivileges

func (s *ShowUsersStatement) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges returns the privilege(s) required to execute a ShowUsersStatement

func (*ShowUsersStatement) String

func (s *ShowUsersStatement) String() string

String returns a string representation of the ShowUsersStatement.

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) MarshalBinary

func (a Sources) MarshalBinary() ([]byte, error)

MarshalBinary encodes a list of sources to a binary format.

func (Sources) Measurements

func (a Sources) Measurements() []*Measurement

Measurements returns all measurements including ones embedded in subqueries.

func (Sources) RequiredPrivileges

func (a Sources) RequiredPrivileges() (ExecutionPrivileges, error)

RequiredPrivileges recursively returns a list of execution privileges required.

func (Sources) String

func (a Sources) String() string

String returns a string representation of a Sources array.

func (*Sources) UnmarshalBinary

func (a *Sources) UnmarshalBinary(buf []byte) error

UnmarshalBinary decodes binary data into a list of sources.

type Statement

type Statement interface {
	Node

	RequiredPrivileges() (ExecutionPrivileges, error)
	// contains filtered or unexported methods
}

Statement represents a single command in CnosQL.

func MustParseStatement

func MustParseStatement(s string) Statement

MustParseStatement parses a statement string and returns its AST. Panic on error.

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) IsTimeLiteral

func (l *StringLiteral) IsTimeLiteral() bool

IsTimeLiteral returns if this string can be interpreted as a time literal.

func (*StringLiteral) String

func (l *StringLiteral) String() string

String returns a string representation of the literal.

func (*StringLiteral) ToTimeLiteral

func (l *StringLiteral) ToTimeLiteral(loc *time.Location) (*TimeLiteral, error)

ToTimeLiteral returns a time literal if this string can be converted to a time literal.

type StringValue

type StringValue string

StringValue is a string literal.

func (StringValue) TokenType

func (v StringValue) TokenType() Token

func (StringValue) Value

func (v StringValue) Value() string

type SubQuery

type SubQuery struct {
	Statement *SelectStatement
}

SubQuery is a source with a SelectStatement as the backing store.

func (*SubQuery) String

func (s *SubQuery) String() string

String returns a string representation of the subquery.

type Target

type Target struct {
	// Measurement to write into.
	Measurement *Measurement
}

Target represents a target (destination) policy, measurement, and DB.

func (*Target) String

func (t *Target) String() string

String returns a string representation of the Target.

type TimeLiteral

type TimeLiteral struct {
	Val time.Time
}

TimeLiteral represents a point-in-time literal.

func (*TimeLiteral) String

func (l *TimeLiteral) String() string

String returns a string representation of the literal.

type TimeRange

type TimeRange struct {
	Min, Max time.Time
}

TimeRange represents a range of time from Min to Max. The times are inclusive.

func (TimeRange) Intersect

func (t TimeRange) Intersect(other TimeRange) TimeRange

Intersect joins this TimeRange with another TimeRange.

func (TimeRange) IsZero

func (t TimeRange) IsZero() bool

IsZero is true if the min and max of the time range are zero.

func (TimeRange) MaxTime

func (t TimeRange) MaxTime() time.Time

MaxTime returns the maximum time of the TimeRange. If the maximum time is zero, this returns the maximum possible time.

func (TimeRange) MaxTimeNano

func (t TimeRange) MaxTimeNano() int64

MaxTimeNano returns the maximum time in nanoseconds since the epoch. If the maximum time is zero, this returns the maximum possible time.

func (TimeRange) MinTime

func (t TimeRange) MinTime() time.Time

MinTime returns the minimum time of the TimeRange. If the minimum time is zero, this returns the minimum possible time.

func (TimeRange) MinTimeNano

func (t TimeRange) MinTimeNano() int64

MinTimeNano returns the minimum time in nanoseconds since the epoch. If the minimum time is zero, this returns the minimum possible time.

type Token

type Token int

Token is a lexical token of the CnosQL language.

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

	// IDENT and the following are CnosQL literal tokens.
	IDENT       // main
	BOUNDPARAM  // $param
	NUMBER      // 12345.67
	INTEGER     // 12345
	DURATIONVAL // 13h
	STRING      // "abc"
	BADSTRING   // "abc
	BADESCAPE   // \q
	TRUE        // true
	FALSE       // false
	REGEX       // Regular expressions
	BADREGEX    // `.*

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

	AND // AND
	OR  // OR
	IN  // IN

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

	LPAREN      // (
	RPAREN      // )
	COMMA       // ,
	COLON       // :
	DOUBLECOLON // ::
	SEMICOLON   // ;
	DOT         // .

	// ALL and the following are CnosQL Keywords
	ALL
	ALTER
	ANALYZE
	ANY
	AS
	ASC
	BEGIN
	BY
	CARDINALITY
	CREATE
	CONTINUOUS
	DATABASE
	DATABASES
	DEFAULT
	DELETE
	DESC
	DESTINATIONS
	DIAGNOSTICS
	DISTINCT
	DROP
	DURATION
	END
	EVERY
	EXACT
	EXPLAIN
	FIELD
	FOR
	FROM
	GRANT
	GRANTS
	GROUP
	GROUPS
	INF
	INSERT
	INTO
	KEY
	KEYS
	KILL
	LIMIT
	MEASUREMENT
	MEASUREMENTS
	NAME
	OFFSET
	ON
	ORDER
	PASSWORD
	POLICY
	POLICIES
	PRIVILEGES
	QUERIES
	QUERY
	READ
	REPLICATION
	RESAMPLE
	RETENTION
	REVOKE
	SELECT
	SERIES
	SET
	SHOW
	SHARD
	SHARDS
	SLIMIT
	SOFFSET
	STATS
	SUBSCRIPTION
	SUBSCRIPTIONS
	TAG
	TO
	USER
	USERS
	VALUES
	WHERE
	WITH
	WRITE
)

These are a comprehensive list of CnosQL language tokens.

func Lookup

func Lookup(ident string) Token

Lookup returns the token associated with a given string.

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 TypeError

type TypeError struct {
	// Expr contains the expression that generated the type error.
	Expr Expr
	// Message contains the informational message about the type error.
	Message string
}

TypeError is an error when two types are incompatible.

func (*TypeError) Error

func (e *TypeError) Error() string

type TypeMapper

type TypeMapper interface {
	MapType(measurement *Measurement, field string) DataType
}

TypeMapper maps a data type to the measurement and field.

func MultiTypeMapper

func MultiTypeMapper(mappers ...TypeMapper) TypeMapper

MultiTypeMapper combines multiple TypeMappers into a single one. The MultiTypeMapper will return the first type that is not Unknown. It will not iterate through all of them to find the highest priority one.

type TypeValuerEval

type TypeValuerEval struct {
	TypeMapper TypeMapper
	Sources    Sources
}

TypeValuerEval evaluates an expression to determine its output type.

func (*TypeValuerEval) EvalType

func (v *TypeValuerEval) EvalType(expr Expr) (DataType, error)

EvalType returns the type for an expression. If the expression cannot be evaluated for some reason, like incompatible types, it is returned as a TypeError in the error. If the error is non-fatal so we can continue even though an error happened, true will be returned. This function assumes that the expression has already been reduced.

type UnsignedLiteral

type UnsignedLiteral struct {
	Val uint64
}

UnsignedLiteral represents an unsigned literal. The parser will only use an unsigned literal if the parsed integer is greater than math.MaxInt64.

func (*UnsignedLiteral) String

func (l *UnsignedLiteral) String() string

String returns a string representation of the literal.

type Value

type Value interface {
	TokenType() Token
	Value() string
}

Value represents a value that can be bound to a parameter when parsing the query.

func BindValue

func BindValue(v interface{}) Value

BindValue will bind an interface value to its cnosql value. This method of binding values only supports literals.

type Valuer

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

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

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.

func (*ValuerEval) EvalBool

func (v *ValuerEval) EvalBool(expr Expr) bool

EvalBool evaluates expr and returns true if result is a boolean true. Otherwise returns false.

type VarRef

type VarRef struct {
	Val  string
	Type DataType
}

VarRef represents a reference to a variable.

func ExprNames

func ExprNames(expr Expr) []VarRef

ExprNames returns a list of non-"time" field names from an expression.

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) Len

func (a VarRefs) Len() int

Len implements sort.Interface.

func (VarRefs) Less

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

Less implements sort.Interface.

func (VarRefs) Strings

func (a VarRefs) Strings() []string

Strings returns a slice of the variable names.

func (VarRefs) Swap

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

Swap implements sort.Interface.

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.

type ZoneValuer

type ZoneValuer interface {
	Valuer

	// Zone returns the time zone location. This function may return nil
	// if no time zone is known.
	Zone() *time.Location
}

ZoneValuer is the interface that specifies the current time zone.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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