influxql

package
v0.9.0-rc6 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2015 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package influxql implements a parser for the InfluxDB query language.

InfluxQL is a DML and DDL language for the InfluxDB time series database. It provides the ability to query for aggregate statistics as well as create and configure the InfluxDB server.

Selecting data

The SELECT query is used for retrieving data from one or more series. It allows for a list of columns followed by a list of series to select from.

SELECT value FROM cpu_load

You can also add a a conditional expression to limit the results of the query:

SELECT value FROM cpu_load WHERE host = 'influxdb.com'

Two or more series can be combined into a single query and executed together:

SELECT cpu0.value + cpu1.value
FROM cpu_load AS cpu0 INNER JOIN cpu_load cpu1 ON cpu0.host = cpu1.host

Limits and ordering can be set on selection queries as well:

SELECT value FROM cpu_load LIMIT 100 ORDER DESC;

Removing data

The DELETE query is available to remove time series data points from the database. This query will delete "cpu_load" values older than an hour:

DELETE FROM cpu_load WHERE time < now() - 1h

Continuous Queries

Queries can be run indefinitely on the server in order to generate new series. This is done by running a "SELECT INTO" query. For example, this query computes the hourly mean for cpu_load and stores it into a "cpu_load" series in the "daily" shard space.

SELECT mean(value) AS value FROM cpu_load GROUP BY 1h
INTO daily.cpu_load

If there is existing data on the source series then this query will be run for all historic data. To only execute the query on new incoming data you can append "NO BACKFILL" to the end of the query:

SELECT mean(value) AS value FROM cpu_load GROUP BY 1h
INTO daily.cpu_load NO BACKFILL

Continuous queries will return an id that can be used to remove them in the future. To remove a continous query, use the DROP CONTINUOUS QUERY statement:

DROP CONTINUOUS QUERY 12

You can also list all continuous queries by running:

LIST CONTINUOUS QUERIES

Index

Constants

View Source
const (
	// Unknown primitive data type.
	Unknown = DataType("")
	// Number means the data type is an int or float.
	Number = DataType("number")
	// Boolean means the data type is a boolean.
	Boolean = DataType("boolean")
	// String means the data type is a string of text.
	String = DataType("string")
	// Time means the data type is a time.
	Time = DataType("time")
	// Duration means the data type is a duration of time.
	Duration = DataType("duration")
)
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 malformatted duration.

Functions

func Eval

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

Eval evaluates expr against a map.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration to a string.

func IsRegexOp

func IsRegexOp(t Token) bool

IsRegexOp returns true if the operator accepts a regex operand.

func MapCount

func MapCount(itr Iterator, e *Emitter, tmin int64)

MapCount computes the number of values in an iterator.

func MapEcho

func MapEcho(itr Iterator, e *Emitter, tmin int64)

MapEcho emits the data points for each group by interval

func MapFirst

func MapFirst(itr Iterator, e *Emitter, tmax int64)

MapFirst collects the values to pass to the reducer

func MapLast

func MapLast(itr Iterator, e *Emitter, tmax int64)

MapLast collects the values to pass to the reducer

func MapMax

func MapMax(itr Iterator, e *Emitter, tmax int64)

MapMax collects the values to pass to the reducer

func MapMean

func MapMean(itr Iterator, e *Emitter, tmin int64)

MapMean computes the count and sum of values in an iterator to be combined by the reducer.

func MapMin

func MapMin(itr Iterator, e *Emitter, tmin int64)

MapMin collects the values to pass to the reducer

func MapRawQuery

func MapRawQuery(itr Iterator, e *Emitter, tmin int64)

func MapSpread

func MapSpread(itr Iterator, e *Emitter, tmax int64)

MapSpread collects the values to pass to the reducer

func MapStddev

func MapStddev(itr Iterator, e *Emitter, tmax int64)

MapStddev collects the values to pass to the reducer

func MapSum

func MapSum(itr Iterator, e *Emitter, tmin int64)

MapSum computes the summation of values in an iterator.

func MarshalStrings

func MarshalStrings(a []string) (ret []byte)

MarshalStrings encodes an array of strings into a byte slice.

func MatchSource

func MatchSource(src Source, name string) string

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

func ParseDuration

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

ParseDuration parses a time duration from a string.

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 ReduceFirst

func ReduceFirst(key Key, values []interface{}, e *Emitter)

ReduceFirst computes the first of value.

func ReduceLast

func ReduceLast(key Key, values []interface{}, e *Emitter)

ReduceLast computes the last of value.

func ReduceMax

func ReduceMax(key Key, values []interface{}, e *Emitter)

ReduceMax computes the max of value.

func ReduceMean

func ReduceMean(key Key, values []interface{}, e *Emitter)

ReduceMean computes the mean of values for each key.

func ReduceMin

func ReduceMin(key Key, values []interface{}, e *Emitter)

ReduceMin computes the min of value.

func ReduceRawQuery

func ReduceRawQuery(key Key, values []interface{}, e *Emitter)

func ReduceSpread

func ReduceSpread(key Key, values []interface{}, e *Emitter)

ReduceSpread computes the spread of values.

func ReduceStddev

func ReduceStddev(key Key, values []interface{}, e *Emitter)

ReduceStddev computes the stddev of values.

func ReduceSum

func ReduceSum(key Key, values []interface{}, e *Emitter)

ReduceSum computes the sum of values for each key.

func ScanBareIdent

func ScanBareIdent(r io.RuneScanner) string

ScanBareIdent reads bare identifier from a rune reader.

func ScanString

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

ScanString reads a quoted string from a rune reader.

func SplitIdent

func SplitIdent(s string) (segments []string, err error)

SplitIdent splits an identifier into quoted & unquoted segments.

func TimeRange

func TimeRange(expr Expr) (min, max time.Time)

TimeRange returns the minimum and maximum times specified by an expression. Returns zero times if there is no bound.

func UnmarshalStrings

func UnmarshalStrings(b []byte) (ret []string)

UnmarshalStrings decodes a byte slice into an array of strings.

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
}

AlterRetentionPolicyStatement represents a command to alter an existing retention policy.

func (*AlterRetentionPolicyStatement) RequiredPrivileges

func (s *AlterRetentionPolicyStatement) RequiredPrivileges() ExecutionPrivileges

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

CreateContinuousQueryStatement represents a command for creating a continuous query.

func (*CreateContinuousQueryStatement) RequiredPrivileges

func (s *CreateContinuousQueryStatement) RequiredPrivileges() ExecutionPrivileges

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
}

CreateDatabaseStatement represents a command for creating a new database.

func (*CreateDatabaseStatement) RequiredPrivileges

func (s *CreateDatabaseStatement) RequiredPrivileges() ExecutionPrivileges

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
}

CreateRetentionPolicyStatement represents a command to create a retention policy.

func (*CreateRetentionPolicyStatement) RequiredPrivileges

func (s *CreateRetentionPolicyStatement) RequiredPrivileges() ExecutionPrivileges

RequiredPrivileges returns the privilege required to execute a CreateRetentionPolicyStatement.

func (*CreateRetentionPolicyStatement) String

String returns a string representation of the create retention policy.

type CreateUserStatement

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

	// User's password
	Password string

	// User's privilege level.
	Privilege *Privilege
}

CreateUserStatement represents a command for creating a new user.

func (*CreateUserStatement) RequiredPrivileges

func (s *CreateUserStatement) RequiredPrivileges() ExecutionPrivileges

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 DB

type DB interface {
	Begin() (Tx, error)
}

DB represents an interface for creating transactions.

type DataType

type DataType string

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.

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 removing data from the database.

func (*DeleteStatement) RequiredPrivileges

func (s *DeleteStatement) RequiredPrivileges() ExecutionPrivileges

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

Normalize returns the interval and tag dimensions separately. Returns 0 if no time interval is specified. Returns an error if multiple time dimensions exist or if non-VarRef dimensions are specified.

func (Dimensions) String

func (a Dimensions) String() string

String returns a string representation of the dimensions.

type DropContinuousQueryStatement

type DropContinuousQueryStatement struct {
	Name string
}

DropContinuousQueryStatement represents a command for removing a continuous query.

func (*DropContinuousQueryStatement) RequiredPrivileges

func (s *DropContinuousQueryStatement) RequiredPrivileges() ExecutionPrivileges

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

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
}

DropMeasurmentStatement represents a command to drop a measurement.

func (*DropMeasurementStatement) RequiredPrivileges

func (s *DropMeasurementStatement) RequiredPrivileges() ExecutionPrivileges

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

func (s *DropRetentionPolicyStatement) RequiredPrivileges() ExecutionPrivileges

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 {
	// The Id of the series being dropped (optional)
	SeriesID uint32

	// Data source that fields are extracted from (optional)
	Source Source

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

RequiredPrivileges returns the privilige reqired to execute a DropSeriesStatement.

func (*DropSeriesStatement) String

func (s *DropSeriesStatement) String() string

String returns a string representation of the drop series statement.

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

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 Emitter

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

Emitter provides bufferred emit/flush of key/value pairs.

func NewEmitter

func NewEmitter(n int) *Emitter

NewEmitter returns a new instance of Emitter with a buffer size of n.

func (*Emitter) C

func (e *Emitter) C() <-chan map[Key]interface{}

C returns the emitter's output channel.

func (*Emitter) Close

func (e *Emitter) Close() error

Close closes the emitter's output channel.

func (*Emitter) Emit

func (e *Emitter) Emit(key Key, value interface{})

Emit sets a key and value on the emitter's bufferred data.

type ExecutionPrivilege

type ExecutionPrivilege struct {
	// Name of the database or resource.
	// If "", then the resource is the cluster.
	Name string

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

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

Executor represents the implementation of Executor. It executes all reducers and combines their result into a row.

func (*Executor) Execute

func (e *Executor) Execute() (<-chan *Row, error)

Execute begins execution of the query and returns a channel to receive rows.

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

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

func (a Fields) String() string

String returns a string representation of the fields.

type GrantStatement

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

	// Thing to grant privilege on (e.g., a DB).
	On string

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

GrantStatement represents a command for granting a privilege.

func (*GrantStatement) RequiredPrivileges

func (s *GrantStatement) RequiredPrivileges() ExecutionPrivileges

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 Iterator

type Iterator interface {
	// Tags returns the encoded dimensional tag values.
	Tags() string

	// Next returns the next value from the iterator.
	Next() (key int64, data []byte, value interface{})
}

Iterator represents a forward-only iterator over a set of points.

type Join

type Join struct {
	Measurements Measurements
}

Join represents two datasources joined together.

func (*Join) String

func (j *Join) String() string

String returns a string representation of the join.

type Key

type Key struct {
	Timestamp int64
	Values    string
}

Key represents a key returned by a Mapper or Reducer.

type MapFunc

type MapFunc func(Iterator, *Emitter, int64)

MapFunc represents a function used for mapping iterators.

type Mapper

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

Mapper represents an object for processing iterators.

func NewMapper

func NewMapper(fn MapFunc, itr Iterator, interval time.Duration) *Mapper

NewMapper returns a new instance of Mapper with a given function and interval.

func (*Mapper) Map

func (m *Mapper) Map() *Emitter

Map executes the mapper's function against the iterator. Returns a nil emitter if no data was found.

type Measurement

type Measurement struct {
	Name string
}

Measurement represents a single measurement used as a datasource.

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 Merge

type Merge struct {
	Measurements Measurements
}

Merge represents a datasource created by merging two datasources.

func (*Merge) String

func (m *Merge) String() string

String returns a string representation of the merge.

type Node

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

Node represents a node in the InfluxDB 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 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 Parsr.

func (*Parser) ParseExpr

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

ParseExpr parses an expression.

func (*Parser) ParseQuery

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

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

func (*Parser) ParseStatement

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

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

type Planner

type Planner struct {
	DB DB

	// Returns the current time. Defaults to time.Now().
	Now func() time.Time
}

Planner represents an object for creating execution plans.

func NewPlanner

func NewPlanner(db DB) *Planner

NewPlanner returns a new instance of Planner.

func (*Planner) Plan

func (p *Planner) Plan(stmt *SelectStatement) (*Executor, error)

Plan creates an execution plan for the given SelectStatement and returns an Executor.

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 Processor added in v0.9.2

type Processor interface {
	Process()
	Name() string
	C() <-chan map[Key]interface{}
	IsRawQuery() bool
}

Processor represents an object for joining reducer output.

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 Record

type Record struct {
	Key   Key
	Value interface{}
}

type ReduceFunc

type ReduceFunc func(Key, []interface{}, *Emitter)

ReduceFunc represents a function used for reducing mapper output.

func ReducePercentile

func ReducePercentile(percentile float64) ReduceFunc

ReducePercentile computes the percentile of values for each key.

type Reducer

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

Reducer represents an object for processing mapper output. Implements processor.

func NewReducer

func NewReducer(fn ReduceFunc, mappers []*Mapper) *Reducer

NewReducer returns a new instance of reducer.

func (*Reducer) C

func (r *Reducer) C() <-chan map[Key]interface{}

C returns the output channel.

func (*Reducer) IsRawQuery

func (r *Reducer) IsRawQuery() bool

func (*Reducer) Name

func (r *Reducer) Name() string

Name returns the source name.

func (*Reducer) Process

func (r *Reducer) Process()

Process processes the Reducer.

func (*Reducer) Reduce

func (r *Reducer) Reduce() *Emitter

Reduce executes the reducer's function against all output from the mappers.

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 RevokeStatement

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

	// Thing to revoke privilege to (e.g., a DB)
	On string

	// Who to revoke privilege from.
	User string
}

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

func (*RevokeStatement) RequiredPrivileges

func (s *RevokeStatement) RequiredPrivileges() ExecutionPrivileges

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 Row

type Row struct {
	Name    string            `json:"name,omitempty"`
	Tags    map[string]string `json:"tags,omitempty"`
	Columns []string          `json:"columns"`
	Values  [][]interface{}   `json:"values,omitempty"`
	Err     error             `json:"err,omitempty"`
}

Row represents a single row returned from the execution of a statement.

type Rows

type Rows []*Row

Rows represents a list of rows that can be sorted consistently by name/tag.

func (Rows) Len

func (p Rows) Len() int

func (Rows) Less

func (p Rows) Less(i, j int) bool

func (Rows) Swap

func (p Rows) Swap(i, j int)

type Scanner

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

Scanner represents a lexical scanner for InfluxQL.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner returns a new instance of Scanner.

func (*Scanner) Scan

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

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

type SelectStatement

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

	// Target (destination) for the result of the select.
	Target *Target

	// Expressions used for grouping the selection.
	Dimensions Dimensions

	// Data source that fields are extracted from.
	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

	// if it's a query for raw data values (i.e. not an aggregate)
	RawQuery bool
	// contains filtered or unexported fields
}

SelectStatement represents a command for extracting data from the database.

func (*SelectStatement) Aggregated

func (s *SelectStatement) Aggregated() bool

Aggregated returns true if the statement uses aggregate functions.

func (*SelectStatement) Clone

func (s *SelectStatement) Clone() *SelectStatement

Clone returns a deep copy of the statement.

func (*SelectStatement) GroupByInterval

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

GroupByIterval extracts the time interval, if specified.

func (*SelectStatement) HasWildcard

func (s *SelectStatement) HasWildcard() bool

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

func (*SelectStatement) OnlyTimeDimensions

func (s *SelectStatement) OnlyTimeDimensions() bool

OnlyTimeDimensions returns true if the statement has a where clause with only time constraints

func (*SelectStatement) RequiredPrivileges

func (s *SelectStatement) RequiredPrivileges() ExecutionPrivileges

RequiredPrivileges returns the privilege required to execute the SelectStatement.

func (*SelectStatement) RewriteWildcards

func (s *SelectStatement) RewriteWildcards(fields Fields, dimensions Dimensions) *SelectStatement

RewriteWildcards 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.

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

func (s *SelectStatement) Substatement(ref *VarRef) (*SelectStatement, error)

Substatement returns a single-series statement for a given variable reference.

type ShowContinuousQueriesStatement

type ShowContinuousQueriesStatement struct{}

ShowContinuousQueriesStatement represents a command for listing continuous queries.

func (*ShowContinuousQueriesStatement) RequiredPrivileges

func (s *ShowContinuousQueriesStatement) RequiredPrivileges() ExecutionPrivileges

RequiredPrivileges returns the privilege required to execute a ShowContinuousQueriesStatement.

func (*ShowContinuousQueriesStatement) String

String returns a string representation of the list 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

RequiredPrivileges returns the privilege required to execute a ShowDatabasesStatement

func (*ShowDatabasesStatement) String

func (s *ShowDatabasesStatement) String() string

String returns a string representation of the list databases command.

type ShowFieldKeysStatement

type ShowFieldKeysStatement struct {
	// Data source that fields are extracted from.
	Source Source

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

func (s *ShowFieldKeysStatement) RequiredPrivileges() ExecutionPrivileges

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 ShowMeasurementsStatement

type ShowMeasurementsStatement struct {
	// 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) RequiredPrivileges

func (s *ShowMeasurementsStatement) RequiredPrivileges() ExecutionPrivileges

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 ShowRetentionPoliciesStatement

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

ShowRetentionPoliciesStatement represents a command for listing retention policies.

func (*ShowRetentionPoliciesStatement) RequiredPrivileges

func (s *ShowRetentionPoliciesStatement) RequiredPrivileges() ExecutionPrivileges

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

func (*ShowRetentionPoliciesStatement) String

String returns a string representation of a ShowRetentionPoliciesStatement.

type ShowSeriesStatement

type ShowSeriesStatement struct {
	// Measurement(s) the series are listed for.
	Source Source

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

func (s *ShowSeriesStatement) RequiredPrivileges() ExecutionPrivileges

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 ShowTagKeysStatement

type ShowTagKeysStatement struct {
	// Data source that fields are extracted from.
	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
}

ShowTagKeysStatement represents a command for listing tag keys.

func (*ShowTagKeysStatement) RequiredPrivileges

func (s *ShowTagKeysStatement) RequiredPrivileges() ExecutionPrivileges

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 ShowTagValuesStatement

type ShowTagValuesStatement struct {
	// Data source that fields are extracted from.
	Source Source

	// Tag key(s) to pull values from.
	TagKeys []string

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

ShowTagValuesStatement represents a command for listing tag values.

func (*ShowTagValuesStatement) RequiredPrivileges

func (s *ShowTagValuesStatement) RequiredPrivileges() ExecutionPrivileges

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

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

func (*ShowUsersStatement) String

func (s *ShowUsersStatement) String() string

String retuns 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 Statement

type Statement interface {
	Node

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

Statement represents a single command in InfluxQL.

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 Target

type Target struct {
	// Measurement to write into.
	Measurement string

	// Database to write into.
	Database string
}

TODO pauldix: Target should actually have a Database, RetentionPolicy, and Measurement. These should be set based on the ON part of the query, and the SplitIdent of the INTO name Target represents a target (destination) policy, measurment, 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 Token

type Token int

Token is a lexical token of the InfluxQL language.

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

	// Literals
	IDENT        // main
	NUMBER       // 12345.67
	DURATION_VAL // 13h
	STRING       // "abc"
	BADSTRING    // "abc
	BADESCAPE    // \q
	TRUE         // true
	FALSE        // false

	// Operators
	ADD // +
	SUB // -
	MUL // *
	DIV // /

	AND // AND
	OR  // OR

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

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

	// Keywords
	ALL
	ALTER
	AS
	ASC
	BEGIN
	BY
	CREATE
	CONTINUOUS
	DATABASE
	DATABASES
	DEFAULT
	DELETE
	DESC
	DROP
	DURATION
	END
	EXISTS
	EXPLAIN
	FIELD
	FROM
	GRANT
	GROUP
	IF
	IN
	INNER
	INSERT
	INTO
	KEY
	KEYS
	LIMIT
	SHOW
	MEASUREMENT
	MEASUREMENTS
	OFFSET
	ON
	ORDER
	PASSWORD
	POLICY
	POLICIES
	PRIVILEGES
	QUERIES
	QUERY
	READ
	REPLICATION
	RETENTION
	REVOKE
	SELECT
	SERIES
	TAG
	TO
	USER
	USERS
	VALUES
	WHERE
	WITH
	WRITE
)

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 Tx

type Tx interface {
	// Opens and closes the transaction.
	Open() error
	Close() error

	// SetNow sets the current time to be used throughout the transaction.
	SetNow(time.Time)

	// Creates a list of iterators for a simple select statement.
	//
	// The statement must adhere to the following rules:
	//   1. It can only have a single VarRef field.
	//   2. It can only have a single source measurement.
	CreateIterators(*SelectStatement) ([]Iterator, error)

	// DecodeValues is for use in a raw data query
	DecodeValues(fieldIDs []uint8, timestamp int64, data []byte) []interface{}
	// FieldIDs will take an array of fields and return the id associated with each
	FieldIDs(fields []*Field) ([]uint8, error)
}

Tx represents a transaction. The Tx must be opened before being used.

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
}

VarRef represents a reference to a variable.

func (*VarRef) String

func (r *VarRef) String() string

String returns a string representation of the variable reference.

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

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