Documentation ¶
Overview ¶
Package pql defines the Pilosa Query Language.
Index ¶
- Constants
- func CopyArgs(m map[string]interface{}) map[string]interface{}
- func IsReservedArg(name string) bool
- func MinMax(scale int64) (Decimal, Decimal)
- func NewParser(r io.Reader) *parser
- func Pow10(p int64) int64
- func Pretty(pretty bool) func(*PQL) error
- func RegisterPluginFuncs(ops []ext.BitmapOp)
- func Size(size int) func(*PQL) error
- func Unquote(s string) (string, error)
- type Call
- func (c *Call) Arg(key string) (interface{}, bool)
- func (c *Call) ArgString(key string) string
- func (c *Call) BoolArg(key string) (bool, bool, error)
- func (c *Call) CallArg(key string) (*Call, bool, error)
- func (c *Call) CallIndex() string
- func (c *Call) CheckCallInfo() error
- func (c *Call) Clone() *Call
- func (c *Call) FieldArg() (string, error)
- func (c *Call) HasConditionArg() bool
- func (c *Call) IntArg(key string) (int64, bool, error)
- func (c *Call) String() string
- func (c *Call) TranslateInfo(columnLabel, rowLabel string) (colKey, rowKey, fieldName string)
- func (c *Call) UintArg(key string) (uint64, bool, error)
- func (c *Call) UintSliceArg(key string) ([]uint64, bool, error)
- func (c *Call) Writable() bool
- type CallType
- type Condition
- func (cond *Condition) Int64SliceValue() ([]int64, bool)
- func (cond *Condition) Int64Value() (int64, bool)
- func (cond *Condition) String() string
- func (cond *Condition) StringSliceValue() ([]string, bool)
- func (cond *Condition) StringWithSubj(subj string) string
- func (cond *Condition) Uint64SliceValue() ([]uint64, bool)
- func (cond *Condition) Uint64Value() (uint64, bool)
- type Decimal
- func (d Decimal) EqualTo(d2 Decimal) bool
- func (d Decimal) Float64() float64
- func (d Decimal) GreaterThan(d2 Decimal) bool
- func (d Decimal) GreaterThanOrEqualTo(d2 Decimal) bool
- func (d Decimal) IsValid() bool
- func (d Decimal) LessThan(d2 Decimal) bool
- func (d Decimal) LessThanOrEqualTo(d2 Decimal) bool
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) MarshalYAML() (interface{}, error)
- func (d Decimal) String() string
- func (d Decimal) SupportedByScale(scale int64) bool
- func (d Decimal) ToInt64(scale int64) int64
- func (d *Decimal) UnmarshalJSON(data []byte) error
- func (d *Decimal) UnmarshalYAML(unmarshal func(interface{}) error) error
- type PQL
- func (t *PQL) AST() *node32
- func (t *PQL) Add(rule pegRule, begin, end, index uint32)
- func (p *PQL) Execute()
- func (p *PQL) Init(options ...func(*PQL) error) error
- func (p *PQL) Parse(rule ...int) error
- func (t *PQL) PrettyPrintSyntaxTree(buffer string)
- func (t *PQL) Print()
- func (p *PQL) PrintSyntaxTree()
- func (p *PQL) Reset()
- func (p *PQL) SprintSyntaxTree() string
- func (t *PQL) Tokens() []token32
- func (t *PQL) Trim(length uint32)
- func (p *PQL) WriteSyntaxTree(w io.Writer)
- type Query
- type Token
Constants ¶
const ( // Normal calls can be executed per shard. PrecallNone = CallType(iota) // PreCallGlobal indicates a call which must be run globally *before* // distributing the call to other shards. Example: A Distinct query, // where every shard could potentially produce results for any shard, // so you have to produce the results up front. PrecallGlobal // PreCallPerNode indicates a call which needs to be run per-shard // in a way that lets it be done on each shard, but where it should // be done prior to spawning per-shard goroutines. Example: // A cross-index query, where each local shard may or may not need // to get data from a remote node, but batches of shards can // probably be gotten from the same remote node. PrecallPerNode )
Variables ¶
This section is empty.
Functions ¶
func IsReservedArg ¶
func Pow10 ¶
Pow10 is a function which can be used in place of math.Pow10() to avoid the float64 logic. Note that only powers 0-18 are currently supported; anything else will return 0, which is probably going to result in incorrect values.
func RegisterPluginFuncs ¶
RegisterPluginFuncs adds arg validation for plugin funcs. Not very good arg validation.
func Unquote ¶
Unquote interprets s as a single-quoted, double-quoted, or backquoted Go string literal, returning the string value that s quotes. It is a copy of stdlib's strconv.Unquote, but modified so that if s is single-quoted, it can still be a string rather than only character literal. This version of Unquote also accepts unquoted strings and passes them back unchanged.
Types ¶
type Call ¶
type Call struct { Name string Args map[string]interface{} Children []*Call Type CallType Precomputed map[uint64]interface{} }
Call represents a function call in the AST. The Precomputed field is used by the executor to handle non-standard call types; it does these by actually executing them separately, then replacing them in the call tree with a new call using the special precomputed type, with the Precomputed field set to a map from shards to results.
func (*Call) Arg ¶
Arg is for reading the value at key from call.Args. If the key is not in Call.Args, the value of the returned bool will be false.
func (*Call) BoolArg ¶
BoolArg is for reading the value at key from call.Args as a bool. If the key is not in Call.Args, the value of the returned bool will be false, and the error will be nil. The value is assumed to be a bool. An error is returned if the value is not a bool.
func (*Call) CallArg ¶
CallArg is for reading the value at key from call.Args as a Call. If the key is not in Call.Args, the value of the returned value will be nil, and the error will be nil. An error is returned if the value is not a Call.
func (*Call) CallIndex ¶
CallIndex handles guessing whether we've been asked to apply this to a different index. An empty string means "no".
func (*Call) CheckCallInfo ¶
CheckCallInfo tries to validate that arguments are correct and valid for the given call. It does not guarantee checking all possible errors; for instance, if an argument is a field name, CheckCallInfo can't validate that the field exists. It also updates with information like whether the call is expected to require precalling.
func (*Call) FieldArg ¶
FieldArg determines which key-value pair contains the field and rowID, in the case of arguments like Set(colID, field=rowID). Returns the field as a string if present, or an error if not.
func (*Call) HasConditionArg ¶
HasConditionArg returns true if any arg is a conditional.
func (*Call) IntArg ¶
IntArg is for reading the value at key from call.Args as an int64. If the key is not in Call.Args, the value of the returned bool will be false, and the error will be nil. The value is assumed to be a unt64 or an int64 and then cast to an int64. An error is returned if the value is not an int64 or uint64.
func (*Call) TranslateInfo ¶
TranslateInfo returns the relevant translation fields.
func (*Call) UintArg ¶
UintArg is for reading the value at key from call.Args as a uint64. If the key is not in Call.Args, the value of the returned bool will be false, and the error will be nil. The value is assumed to be a uint64 or an int64 and then cast to a uint64. An error is returned if the value is not an int64 or uint64.
func (*Call) UintSliceArg ¶
UintSliceArg reads the value at key from call.Args as a slice of uint64. If the key is not in Call.Args, the value of the returned bool will be false, and the error will be nil. If the value is a slice of int64 it will convert it to []uint64. Otherwise, if it is not a []uint64 it will return an error.
type CallType ¶
type CallType byte
Some call types may require special handling, which needs to occur before distributing processing to individual shards.
type Condition ¶
type Condition struct { Op Token Value interface{} }
Condition represents an operation & value. When used in an argument map it represents a binary expression.
func (*Condition) Int64SliceValue ¶
func (*Condition) Int64Value ¶
func (*Condition) StringSliceValue ¶
StringSliceValue returns the value(s) of the conditional as a slice of strings. For example, if cond.Value is []int64{-10,20}, this will return []string{"-10","20"}. It also returns a bool indicating that the conversion succeeded.
func (*Condition) StringWithSubj ¶
StringWithSubj returns the string representation of the condition including the provided subject.
func (*Condition) Uint64SliceValue ¶
func (*Condition) Uint64Value ¶
type Decimal ¶
Decimal represents a decimal value; the intention is to avoid relying on float64, and the primary purpose is to have a predictable way to encode such values used in query strings. Scale is the number of digits to the right of the decimal point. Precision is currently not considered; precision, for our purposes is implied to be the complete, known value.
func NewDecimal ¶
NewDecimal returns a Decimal based on the provided arguments.
func ParseDecimal ¶
ParseDecimal parses a string into a Decimal.
func (Decimal) Float64 ¶
Float64 returns d as a float64. TODO: this could potentially lose precision; we should audit its use and protect against unexpected results.
func (Decimal) GreaterThan ¶
GreaterThan returns true if d > d2.
func (Decimal) GreaterThanOrEqualTo ¶
GreaterThanOrEqualTo returns true if d >= d2.
func (Decimal) IsValid ¶
IsValid returns true if the decimal does not break any assumption or resrictions on input.
func (Decimal) LessThanOrEqualTo ¶
LessThanOrEqualTo returns true if d <= d2.
func (Decimal) MarshalJSON ¶
MarshalJSON is a custom marshaller for the Decimal type.
func (Decimal) MarshalYAML ¶
MarshalYAML is a custom marshaller for the Decimal type.
func (Decimal) SupportedByScale ¶
SupportedByScale returns true if d can be represented by a decimal based on scale. For example: scale = 2: min: -92233720368547758.08 max: 92233720368547758.07 would not support: NewDecimal(9223372036854775807, 0)
func (*Decimal) UnmarshalJSON ¶
UnmarshalJSON is a custom unmarshaller for the Decimal type. The intention is to avoid the use of float64 anywhere, so this unmarhaller parses the decimal out of the byte string.
func (*Decimal) UnmarshalYAML ¶
UnmarshalYAML is a custom unmarshaller for the Decimal type.
type PQL ¶
func (*PQL) PrettyPrintSyntaxTree ¶
func (t *PQL) PrettyPrintSyntaxTree(buffer string)
func (*PQL) PrintSyntaxTree ¶
func (p *PQL) PrintSyntaxTree()
func (*PQL) SprintSyntaxTree ¶ added in v2.1.4
func (*PQL) WriteSyntaxTree ¶
type Query ¶
type Query struct { Calls []*Call // contains filtered or unexported fields }
Query represents a PQL query.
func (*Query) WriteCallN ¶
WriteCallN returns the number of mutating calls.
type Token ¶
type Token int
Token is a lexical token of the PQL language.
const ( // Special tokens ILLEGAL Token = iota ASSIGN // = EQ // == NEQ // != LT // < LTE // <= GT // > GTE // >= BETWEEN // >< (this is like a <= x <= b) // not used in lexing/parsing, but so that the parser can signal // to the executor how to treat the arguments. We used to just add // 1 to the arguments if they were LT so the executor could assume // it was always <=, <=, but then we needed to support // floats/decimals and couldn't do that any more. BTWN_LT_LTE // a < x <= b BTWN_LTE_LT // a <= x < b BTWN_LT_LT // a < x < b )