Documentation
¶
Overview ¶
Package expr implements the AST representation of query expressions.
Each of the AST node types satisfies the Node interface.
The critical entry points for this package are Walk, Check, and Simplify. Those routines allow a caller to examine the AST and collect output diagnostics or perform rewriting.
Index ¶
- Constants
- Variables
- func Check(n Node) error
- func CheckHint(n Node, h Hint) error
- func DefaultBinding(e Node) string
- func EncodeBindings(bind []Binding, dst *ion.Buffer, st *ion.Symtab)
- func EncodeOrder(ord []Order, dst *ion.Buffer, st *ion.Symtab)
- func Equal(a, b Node) bool
- func Equivalent(a, b Node) bool
- func FlatPath(e Node) ([]string, bool)
- func IsConstant(e Node) bool
- func IsIdentifier(e Node, s string) bool
- func IsPath(e Node) bool
- func JSONTypeBits(typ ion.Type) uint
- func Quote(s string) string
- func QuoteID(s string) string
- func ToRedacted(p Printable) string
- func ToString(p Printable) string
- func Unescape(buf []byte) (string, error)
- func Unquote(s string) (string, error)
- func Walk(v Visitor, n Node)
- type Aggregate
- func AggregateAnd(e Node) *Aggregate
- func AggregateBoolAnd(e Node) *Aggregate
- func AggregateBoolOr(e Node) *Aggregate
- func AggregateOr(e Node) *Aggregate
- func AggregateXor(e Node) *Aggregate
- func Avg(e Node) *Aggregate
- func Count(e Node) *Aggregate
- func CountDistinct(e Node) *Aggregate
- func CountNonNull(e Node) *Aggregate
- func Earliest(e Node) *Aggregate
- func Latest(e Node) *Aggregate
- func Max(e Node) *Aggregate
- func Min(e Node) *Aggregate
- func Sum(e Node) *Aggregate
- func SumCount(e Node) *Aggregate
- func SumInt(e Node) *Aggregate
- type AggregateOp
- type AggregateRole
- type Appended
- type ArithOp
- type Arithmetic
- func Add(left, right Node) *Arithmetic
- func BitAnd(left, right Node) *Arithmetic
- func BitOr(left, right Node) *Arithmetic
- func BitXor(left, right Node) *Arithmetic
- func Div(left, right Node) *Arithmetic
- func Mod(left, right Node) *Arithmetic
- func Mul(left, right Node) *Arithmetic
- func NewArith(op ArithOp, left, right Node) *Arithmetic
- func ShiftLeftLogical(left, right Node) *Arithmetic
- func ShiftRightArithmetic(left, right Node) *Arithmetic
- func ShiftRightLogical(left, right Node) *Arithmetic
- func Sub(left, right Node) *Arithmetic
- type Binding
- type Bool
- type Builtin
- type BuiltinOp
- type CTE
- type Case
- type CaseLimb
- type Cast
- type CmpOp
- type Comparison
- type Constant
- type Dot
- type ExplainFormat
- type Field
- type Float
- type From
- type Hint
- type Ident
- type Index
- type Integer
- type IsKey
- type Join
- type JoinKind
- type Keyword
- type List
- type Logical
- type LogicalOp
- type Lookup
- type Member
- type Missing
- type Node
- func BindingValues(bind []Binding) []Node
- func Compare(op CmpOp, left, right Node) Node
- func Copy(e Node) Node
- func DateAdd(part Timepart, value, date Node) Node
- func DateBinWithInterval(stride int64, ts Node, origin Node) Node
- func DateDiff(part Timepart, timestamp1, timestamp2 Node) Node
- func DateExtract(part Timepart, from Node) Node
- func DateTrunc(part Timepart, from Node) Node
- func DateTruncWeekday(from Node, dow Weekday) Node
- func Decode(d ion.Datum) (Node, error)
- func IfThenElse(whenExpr, thenExpr, elseExpr Node) Node
- func In(val Node, cmp ...Node) Node
- func MakePath(path []string) Node
- func NullIf(a, b Node) Node
- func ParsePath(x string) (Node, error)
- func Rewrite(r Rewriter, n Node) Node
- func Simplify(n Node, h Hint) Node
- func SimplifyLogic(n Node, h Hint) Node
- type Not
- type Null
- type Order
- type Printable
- type Query
- func (q *Query) Check() error
- func (q *Query) CheckHint(h Hint) error
- func (q *Query) Clone() *Query
- func (q *Query) Encode(dst *ion.Buffer, st *ion.Symtab)
- func (q *Query) Equals(other *Query) bool
- func (q *Query) Redacted() string
- func (q *Query) SetField(f ion.Field) error
- func (q *Query) Text() string
- type Rational
- type Rewriter
- type Select
- type Star
- type String
- type StringMatch
- type StringMatchOp
- type Struct
- type SyntaxError
- type Table
- type Timepart
- type Timestamp
- func (t *Timestamp) Bin(stride int64, origin Timestamp) Timestamp
- func (t *Timestamp) Datum() ion.Datum
- func (t *Timestamp) Encode(dst *ion.Buffer, st *ion.Symtab)
- func (t *Timestamp) Equals(e Node) bool
- func (t *Timestamp) Trunc(part Timepart) Timestamp
- func (t *Timestamp) Type() TypeSet
- func (t *Timestamp) UnixMicro() int64
- type TypeError
- type TypeSet
- type UnaryArith
- type UnaryArithOp
- type Union
- type UnionType
- type Unpivot
- type Visitor
- type WalkFunc
- type Weekday
- type Window
Constants ¶
const ( ApproxCountDistinctMinPrecision = 4 ApproxCountDistinctMaxPrecision = 16 ApproxCountDistinctDefaultPrecision = 11 )
Variables ¶
var IsKeyword func(s string) bool
IsKeyword is the function that the expr library uses to determine if a string would match as a PartiQL keyword.
(Please don't set this yourself; it is set by expr/partiql so that they can share keyword tables.)
var NaN = Float(math.NaN())
var NoHint noHint
var TimePartMultiplier = [...]uint64{ Microsecond: 1, Millisecond: 1000, Second: 1000000, Minute: 1000000 * 60, Hour: 1000000 * 60 * 60, Day: 1000000 * 60 * 60 * 24, DOW: 0, DOY: 0, Week: 1000000 * 60 * 60 * 24 * 7, Month: 0, Quarter: 0, Year: 0, }
TimePartMultiplier provides part to microsecond multiplication constant of time parts that don't require decomposition from unix time.
Functions ¶
func Check ¶
Check walks the AST given by n and performs rudimentary sanity-checking on all of the values in the tree.
func CheckHint ¶
CheckHint performs the same sanity-checking as Check, except that it uses additional type-hint information.
func DefaultBinding ¶
DefaultBinding returns the default binding for the node e, or the empty string if the expression has no default binding.
func Equivalent ¶
Equivalent returns whether two nodes are equivalent.
Two nodes are equal if they are equivalent numbers (i.e. '0' and '0.0') or if they are identical.
func FlatPath ¶
FlatPath attempts to flatten e into a list of path components. For example, the expression a.b.c would expand to
[]string{"a", "b", "c"}
FlatPath returns (nil, false) if e is not a path or the path cannot be flattened.
func IsIdentifier ¶
IsIdentifier returns whether e == Ident(s), in other words, a path expression with a single component that is equivalent to the given string.
func IsPath ¶
IsPath returns whether or not e is a path expression. A path expression is composed entirely of Ident, Dot, and Index operations.
func JSONTypeBits ¶
JSONTypeBits returns a unique bit pattern associated with the given ion type. (This is the constprop'd version of the TYPE_BIT function.)
func Quote ¶
Quote produces SQL single-quoted strings; escape sequences are encoded using either the traditional ascii escapes (\n, \t, etc.) or extended unicode escapes (\u0100, etc.) where appropriate
func QuoteID ¶
QuoteID produces a textual PartiQL identifier; the returned string will be double-quoted with escapes if it contains non-printable characters or it is a PartiQL keyword.
func ToRedacted ¶
ToRedacted returns the string representation of this AST node and its children in approximately PartiQL syntax, but with all constant expressions replaced with random (deterministic) values.
func ToString ¶
ToString returns the string representation of this AST node and its children in approximately PartiQL syntax
func Unescape ¶
Unescape converts special sequences \t, \n and also unicode chars \uhhhh into plain string.
func Walk ¶
Walk traverses an AST in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).
(see also: ast.Walk)
Types ¶
type Aggregate ¶
type Aggregate struct { // Op is the aggregation operation // (sum, min, max, etc.) Op AggregateOp // Miscellaneous data: used by OpTDigest to store percentile values q Misc float32 // Precision is the parameter for OpApproxCountDistinct Precision uint8 // Role describes how aggregate is supposed to be used in a multi-node architecture Role AggregateRole // Inner is the expression to be aggregated; // this may be nil when the operation is a window function Inner Node // Over, if non-nil, is the OVER part // of the aggregation Over *Window // Filter is an optional filtering expression Filter Node }
Aggregate is an aggregation expression
func AggregateAnd ¶
func AggregateBoolAnd ¶
func AggregateBoolOr ¶
func AggregateOr ¶
func AggregateXor ¶
func CountDistinct ¶
CountDistinct produces the COUNT(DISTINCT e) aggregate
func CountNonNull ¶
CountNonNull counts the number of non-null rows
func SumCount ¶
SumCount produces the SUM(e) aggregate that may be used to aggregate COUNT(...) results
func SumInt ¶
SumInt produces the SUM(e) aggregate that is guaranteed to operate only on integer inputs
func (*Aggregate) IsDistinct ¶
IsDistinct returns if the aggregate has DISTINCT clause.
type AggregateOp ¶
type AggregateOp int
AggregateOp is one of the aggregation operations
const ( // Invalid or no aggregate operation - if you see this it means that the value was either not // initialized yet or it describes non-aggregate operation (for example ssainfo.aggregateOp). OpNone AggregateOp = iota // Describes SQL COUNT(...) aggregate operation OpCount // Describes SQL SUM(...) aggregate operation. OpSum // Describes SQL AVG(...) aggregate OpAvg // Describes SQL MIN(...) aggregate operation. OpMin // Describes SQL MAX(...) aggregate operation. OpMax // Describes SQL COUNT(DISTINCT ...) operation OpCountDistinct // OpSumInt is equivalent to the SUM() operation, // except that it only accepts integer inputs // (and therefore always produces an integer output) OpSumInt // OpSumCount is equivalent to the SUM() operation, // except that it evaluates to 0 instead of // NULL if there are no inputs. This should be // used to aggregate COUNT(...) results instead // of SUM_INT. OpSumCount // Describes SQL BIT_AND(...) aggregate operation. OpBitAnd // Describes SQL BIT_OR(...) aggregate operation. OpBitOr // Describes SQL BIT_XOR(...) aggregate operation. OpBitXor // Describes SQL BOOL_AND(...) aggregate operation. OpBoolAnd // Describes SQL BOOL_OR(...) aggregate operation. OpBoolOr // Describes SQL MIN(timestamp). // // EARLIEST() function is used by Sneller to distinguish // between arithmetic vs timestamp aggregation OpEarliest // Describes SQL MAX(timestamp). // // LATEST() function is used by Sneller to distinguish // between arithmetic vs timestamp aggregation OpLatest // Describes APPROX_COUNT_DISTINCT aggregate, that produces // an integer output OpApproxCountDistinct // OpVariancePop is equivalent to the VARIANCE() and VARIANCE_POP() // operation and calculates the population variance OpVariancePop // OpStdDevPop is equivalent to the STDDEV() and STDDEV_POP() operation // Note that it does not calculate the sample standard deviation OpStdDevPop // OpApproxPercentile is equivalent to APPROX_PERCENTILE() operation OpApproxPercentile // OpApproxMedian is equivalent to (non-SQL but eg present in snowflake) APPROX_MEDIAN() operation OpApproxMedian // OpRowNumber corresponds to ROW_NUMBER() OpRowNumber // OpRank corresponds to RANK() OpRank // OpDenseRank corresponds to DENSE_RANK() OpDenseRank // Describes SNELLER_DATASHAPE aggregate OpSystemDatashape // Describes SNELLER_DATASHAPE_MERGE aggregate, that // merges the results from multiple SNELLER_DATASHAPE // aggregates. OpSystemDatashapeMerge )
func (AggregateOp) AcceptDistinct ¶
func (a AggregateOp) AcceptDistinct() bool
AcceptDistinct returns true if the aggregate can be used with DISTINCT keyword.
func (AggregateOp) AcceptExpression ¶
func (a AggregateOp) AcceptExpression() bool
AcceptExpression returns true if the aggregate can be used with an arbitrary expression.
func (AggregateOp) AcceptStar ¶
func (a AggregateOp) AcceptStar() bool
AcceptStar returns true if the aggregate can be used with '*'.
func (AggregateOp) String ¶
func (a AggregateOp) String() string
func (AggregateOp) WindowOnly ¶
func (a AggregateOp) WindowOnly() bool
WindowOnly returns whether or no the aggregate op is only valid when used with a window function
type AggregateRole ¶
type AggregateRole uint8
AggregateRole describes how the aggregate's internal state has to be interpreted.
In the case of single-node execution, the state lives locally and is transformed into the final value (AggregateRoleFinal: that's the default behaviour).
In the case of multi-node execution, the state can be build on a child node, and then transferred to the main node (AggregateRolePartial). On the main node, the internal state is used to update the local state and then to calculate the final value (AggregateRoleMerge).
const ( // Aggregate yields the final value, to be consumed by "end user" (the default) AggregateRoleFinal AggregateRole = iota // Aggregate collects some data in internal state, and the state is supposed // to be pushed forward. AggregateRolePartial // Aggregate gathers data from its counterpart having role AggregateRolePartial // and is supposed to produce a final value in the end. AggregateRoleMerge )
func (AggregateRole) String ¶
func (r AggregateRole) String() string
type Arithmetic ¶
Arithmetic is a binary arithmetic expression
func Add ¶
func Add(left, right Node) *Arithmetic
func BitAnd ¶
func BitAnd(left, right Node) *Arithmetic
func BitOr ¶
func BitOr(left, right Node) *Arithmetic
func BitXor ¶
func BitXor(left, right Node) *Arithmetic
func Div ¶
func Div(left, right Node) *Arithmetic
func Mod ¶
func Mod(left, right Node) *Arithmetic
func Mul ¶
func Mul(left, right Node) *Arithmetic
func NewArith ¶
func NewArith(op ArithOp, left, right Node) *Arithmetic
NewArith generates a binary arithmetic expression.
func ShiftLeftLogical ¶
func ShiftLeftLogical(left, right Node) *Arithmetic
func ShiftRightArithmetic ¶
func ShiftRightArithmetic(left, right Node) *Arithmetic
func ShiftRightLogical ¶
func ShiftRightLogical(left, right Node) *Arithmetic
func Sub ¶
func Sub(left, right Node) *Arithmetic
func (*Arithmetic) Equals ¶
func (a *Arithmetic) Equals(x Node) bool
type Binding ¶
type Binding struct { Expr Node // contains filtered or unexported fields }
func ParseBindings ¶
ParseBindings parses a comma-separated list of path expressions with (optional) binding parameters.
For example
a.b as b, a.x[3] as foo
is parsed into two Binding structures with the path expressions 'a.b' and 'a.x[3]'
func (*Binding) As ¶
As sets the binding result of b to x. If x is the empty string, then the binding is reset to the default value for this expression.
type Builtin ¶
type Builtin struct { Func BuiltinOp // function name Text string // actual text provided to Call Args []Node // function arguments }
Builtin is a Node that represents a call to a builtin function
func CallByName ¶
CallByName yields 'fn(args...)' Use Call when you know the BuiltinOp associated with fn.
type BuiltinOp ¶
type BuiltinOp int
const ( // Note: names of builin functions that appear in SQL // are derived from the constant name. If a function // has non-trival const-to-name mapping or there // are aliases, the names are provied in the comment, // after "sql:" prefix. // See _generate/builtin_names.go Concat BuiltinOp = iota Trim Ltrim Rtrim Upper Lower Contains ContainsCI // sql:CONTAINS_CI EqualsCI // sql:EQUALS_CI EqualsFuzzy EqualsFuzzyUnicode ContainsFuzzy ContainsFuzzyUnicode OctetLength CharLength // sql:CHAR_LENGTH sql:CHARACTER_LENGTH IsSubnetOf Substring SplitPart BitCount Abs Sign Round RoundEven Trunc Floor Ceil // sql:CEIL sql:CEILING Sqrt Cbrt Exp ExpM1 // sql:EXPM1 Exp2 Exp10 Hypot Ln Ln1p // sql:LN1P Log Log2 Log10 Pow // sql:POW sql:POWER PowUint // sql:POW_UINT Pi Degrees Radians Sin Cos Tan Asin Acos Atan Atan2 Pmod Least Greatest WidthBucket DateAddMicrosecond DateAddMillisecond DateAddSecond DateAddMinute DateAddHour DateAddDay DateAddWeek DateAddMonth DateAddQuarter DateAddYear DateBin DateDiffMicrosecond DateDiffMillisecond DateDiffSecond DateDiffMinute DateDiffHour DateDiffDay DateDiffWeek DateDiffMonth DateDiffQuarter DateDiffYear DateExtractMicrosecond DateExtractMillisecond DateExtractSecond DateExtractMinute DateExtractHour DateExtractDay DateExtractDOW // sql:DATE_EXTRACT_DOW DateExtractDOY // sql:DATE_EXTRACT_DOY DateExtractMonth DateExtractQuarter DateExtractYear DateTruncMicrosecond DateTruncMillisecond DateTruncSecond DateTruncMinute DateTruncHour DateTruncDay DateTruncDOW // sql:DATE_TRUNC_DOW DateTruncMonth DateTruncQuarter DateTruncYear ToUnixEpoch ToUnixMicro GeoHash GeoTileX GeoTileY GeoTileES // sql:GEO_TILE_ES GeoDistance ObjectSize // sql:SIZE ArrayContains ArraySize ArrayPosition ArraySum VectorInnerProduct // sql:INNER_PRODUCT VectorL1Distance // sql:L1_DISTANCE VectorL2Distance // sql:L2_DISTANCE VectorCosineDistance // sql:COSINE_DISTANCE TableGlob TablePattern // used by query planner: InSubquery // matches IN (SELECT ...) InReplacement // IN_REPLACEMENT(x, id) HashReplacement // HASH_REPLACEMENT(id, kind, k, x) ScalarReplacement // SCALAR_REPLACEMENT(id) StructReplacement // STRUCT_REPLACEMENT(id) ListReplacement // LIST_REPLACEMENT(id) TimeBucket MakeList // MAKE_LIST(args...) constructs a list MakeStruct // MAKE_STRUCT(field, value, ...) constructs a structure TypeBit // TYPE_BIT(arg) produces the bits associated with the type of arg AssertIonType PartitionValue // PARTITION_VALUE(int) is used as a placeholder during query planning Unspecified // catch-all for opaque built-ins; sql:UNKNOWN )
func (BuiltinOp) IsDateDiff ¶
IsDateDiff checks whether the built-in function is `DATE_DIFF_xxx`
func (BuiltinOp) IsDateExtract ¶
IsDateExtract checks whether the built-in function is `EXTRACT_xxx`
func (BuiltinOp) IsDateTrunc ¶
IsDateTrunc checks whether the built-in function is `DATE_TRUNC_xxx`
type Case ¶
type Case struct { // Limbs are each of the case limbs. // There ought to be at least one. Limbs []CaseLimb // Else is the ELSE limb of the case // expression, or nil if no ELSE was specified. Else Node // Valence is a hint passed to // the expression-compilation code // regarding the result type of // the case expression. Some optimizations // make the valence of the CASE obvious. Valence string }
Case represents a CASE expression.
func (*Case) IsPathLimbs ¶
IsPathLimbs returns true if the ELSE value and every THEN limb of the CASE expression is a Path expression, Null, or Missing.
type CaseLimb ¶
type CaseLimb struct {
When, Then Node
}
CaseLimb is one 'WHEN expr THEN expr' case limb.
type Cast ¶
type Cast struct { // From is the expression on the left-hand-side of the CAST. From Node // To is the representation of the constant on the right-hand-side // of the CAST expression. // Typically, only one bit of the TypeSet is present, to indicate // the desired result type. To TypeSet }
Cast represents a CAST(... AS ...) expression.
func (*Cast) TargetTypeName ¶
TargetTypeName returns the name of the target type.
type CmpOp ¶
type CmpOp int
CmpOp is a comparison operation type
type Comparison ¶
func (*Comparison) Equals ¶
func (c *Comparison) Equals(x Node) bool
func (*Comparison) Type ¶
func (c *Comparison) Type() TypeSet
type Constant ¶
type Constant interface { Node // Datum returns the ion Datum // associated with this constant. Datum() ion.Datum }
Constant is a Node that is a constant value.
type Dot ¶
Dot represents the '.' infix operator, i.e.
Inner '.' Field
The Inner value within Dot should be structure-typed.
type ExplainFormat ¶
type ExplainFormat uint8
ExplainFormat describes the format of explain output
const ( // ExplainNone does no explain ExplainNone ExplainFormat = iota // ExplainDefault returns singe blob of text ExplainDefault // ExplainText returns a singe blob of text ExplainText // ExplainList returns each line of plan separately ExplainList // ExplainGraphviz returns plan in graphviz format ExplainGraphviz )
type Field ¶
type Field struct { // Label is the label for the field Label string // Value is a value in a Struct literal Value Constant }
Field is a field in a Struct literal,
type From ¶
type From interface { // Tables returns the list of // table bindings created in // the FROM clause Tables() []Binding Node }
From represents a FROM clause
type Hint ¶
Hint is an argument that can be supplied to type-checking operations to refine the type of nodes that have types that would otherwise be unknown to the query planner.
type Ident ¶
type Ident string
Ident is a top-level identifier
func Identifier ¶
Identifier produces a single-element path expression from an identifier string
type Index ¶
Index represents the '[]' infix operator, i.e.
Inner '[' Offset ']'
The Inner value within Index should be list-typed.
type Join ¶
type Join struct { Kind JoinKind On Node Left From // left table expression; can be another join Right Binding // right binding }
Join is an implementation of From that joins a table and a subsequent From clause
type List ¶
type List struct {
Values []Constant
}
List is a literal list constant.
type Logical ¶
Logical is a Node that represents a logical expression
func Xnor ¶
Xnor computes 'left XNOR right', which is equivalent to 'left = right' for boolean expressions.
type Lookup ¶
type Lookup struct {
// Expr is the value to be looked up in Keys,
// and Else is the value to be returned if
// there is no corresponding key (or MISSING
// if Else is nil).
Expr, Else Node
// Keys and Values are the corresponding
// keys and values for the contents of the
// lookup table.
Keys, Values ion.Bag
}
Lookup is an associative array lookup operation against a constant table.
type Member ¶
Member is an implementation of IN that compares against a list of constant values, i.e. MEMBER(x, 3, 'foo', ['x', 1.5])
type Node ¶
type Node interface { Printable // Equals returns whether this node // is equivalent to another node. // Nodes are Equal if they are // syntactically equivalent or correspond // to equal numeric values. Equals(Node) bool Encode(dst *ion.Buffer, st *ion.Symtab) // contains filtered or unexported methods }
Node is an expression AST node
func BindingValues ¶
BindingValues collects all of bind[*].Expr and returns them as a slice.
func Compare ¶
Compare generates a comparison operation of the given type and with the given arguments
func DateExtract ¶
func DateTruncWeekday ¶
func IfThenElse ¶
IfThenElse ternary conditional. eg. result := (count=0) ? thenExpr : elseExpr is written as IfThenElse(Compare(Equals, count, Integer(0)), thenExpr, elseExpr)
func MakePath ¶
MakePath constructs a path expression from a list of identifier path components. This is the reverse operation of FlatPath.
func NullIf ¶
NullIf implements SQL NULLIF(a, b); it is transformed into an equivalent CASE expression:
CASE WHEN a = b THEN NULL ELSE a
func Simplify ¶
Simplify attempts to perform some algebraic simplifications of 'n' and returns the simplified node. If no simplification can be performed, 'n' itself is returned.
func SimplifyLogic ¶
SimplifyLogic is similar to Simplify, except that it performs additional simplifications assuming that the result of the expression is implicitly tested against 'IS TRUE'. (In other words, this simplifier performs optimizations that are only legal inside a WHERE clause.)
type Query ¶
type Query struct { Explain ExplainFormat With []CTE // Into, if non-nil, is the INTO // portion of Body when Body is // a SELECT-FROM-WHERE that includes // an INTO clause. Into Node // Body is the body of the query. // Body can be: // - A SELECT expression // - A UNION expression // - A UNION ALL expression Body Node }
Query contains a complete query.
func DecodeQuery ¶
DecodeQuery decodes an Ion structure representing a query.
Returns query, tail of unprocessed Ion and error.
func (*Query) Equals ¶
Equals returns true if q and other are syntactically equivalent queries, or false otherwise.
type Rewriter ¶
type Rewriter interface { // Rewrite is applied to nodes // in depth-first order, and each // node is re-written to use the // returned value. Rewrite(Node) Node // Walk is called during node traversal // and the returned Rewriter is used for // all the children of Node. // If the returned rewriter is nil, // then traversal does not proceed past Node. Walk(Node) Rewriter }
Rewriter accepts a Node and returns a new node (or just its argument)
func LogicSimplifier ¶
LogicSimplifier returns a Rewriter that performs bottom-up simplification of logical expressions using the given Hint
func Simplifier ¶
Simplifier returns a Rewriter that performs bottom-up simplification of expressions using the given Hint
type Select ¶
type Select struct { // DISTINCT presence Distinct bool // DISTINCT ON (expressions) DistinctExpr []Node // List of output columns Columns []Binding // FROM clause From From // WHERE clause Where Node // GROUP BY clauses, or nil GroupBy []Binding // HAVING clause, or nil Having Node // ORDER BY clauses, or nil OrderBy []Order // When OrderBy is non-nil, // indicates the presence of PRESERVE Preserve bool // LIMIT <Integer> when non-nil Limit *Integer // OFFSET <Integer> when non-nil Offset *Integer }
func (*Select) HasDistinct ¶
HasDistinct returns if select implements 'SELECT DISTINCT ... FROM ...' or 'SELECT DISTINCT ON (...) ... FROM ...'
type StringMatch ¶
type StringMatch struct { Op StringMatchOp Expr Node Pattern string Escape string }
StringMatch is an expression that matches an arbitrary value against a literal string pattern.
func (*StringMatch) Equals ¶
func (s *StringMatch) Equals(x Node) bool
type StringMatchOp ¶
type StringMatchOp int
StringMatchOp is one of the string-matching operations (LIKE, ILIKE, SIMILAR TO, ...)
const ( Like StringMatchOp = iota // LIKE <literal> (also ~~) Ilike // ILIKE <literal> (also ~~*) SimilarTo // SIMILAR TO <literal> RegexpMatch // ~ <literal> RegexpMatchCi // ~* <literal> case-insensitive regex match )
func (StringMatchOp) String ¶
func (s StringMatchOp) String() string
type Struct ¶
type Struct struct {
Fields []Field
}
Struct is a literal struct constant
func (*Struct) FieldByName ¶
FieldByName returns value for given field or nil if there's no such field
type SyntaxError ¶
SyntaxError is the error type returned from Check when an expression has illegal syntax.
func (*SyntaxError) Error ¶
func (s *SyntaxError) Error() string
type Table ¶
type Table struct {
Binding
}
Table is an implementation of From that simply binds a top-level table as a bag of values
type TypeSet ¶
type TypeSet uint16
TypeSet is a set of ion types; type #15 is the MISSING type
Value expression nodes can produce their TypeSet (see TypeOf), which lets the AST checker perform some rudimentary type-checking to determine if the semantics of the operations are incompatible.
const ( // AnyType is the TypeSet that // contains all types. AnyType TypeSet = 0xffff MissingType TypeSet = (1 << 15) BoolType TypeSet = (1 << ion.BoolType) // LogicalType is the return type // of logical operations LogicalType TypeSet = (1 << ion.BoolType) | MissingType // UnsignedType is the return type // of operations that produce only // unsigned integers UnsignedType TypeSet = (1 << ion.UintType) // IntegerType is the return type // of operations that produce only // signed and unsigned integers IntegerType TypeSet = UnsignedType | (1 << ion.IntType) FloatType TypeSet = (1 << ion.FloatType) // NumericType is the return type // of number operations NumericType TypeSet = IntegerType | (1 << ion.FloatType) StringType TypeSet = (1 << ion.StringType) TimeType TypeSet = (1 << ion.TimestampType) ListType TypeSet = (1 << ion.ListType) StructType TypeSet = (1 << ion.StructType) DecimalType TypeSet = (1 << ion.DecimalType) SymbolType TypeSet = (1 << ion.SymbolType) NullType TypeSet = (1 << ion.NullType) )
func (TypeSet) Comparable ¶
Comparable returns whether or not two values can be compared against one another under ordinary typing rules
func (TypeSet) Logical ¶
Logical returns whether or not the type set includes the boolean type (in other words, whether it is sensible to use this type in a logical expression)
func (TypeSet) MaybeMissing ¶
MaybeMissing returns whether or not the type set includes the MISSING value
type UnaryArith ¶
type UnaryArith struct { Op UnaryArithOp Child Node }
func BitNot ¶
func BitNot(child Node) *UnaryArith
func Neg ¶
func Neg(child Node) *UnaryArith
func NewUnaryArith ¶
func NewUnaryArith(op UnaryArithOp, child Node) *UnaryArith
func (*UnaryArith) Equals ¶
func (u *UnaryArith) Equals(x Node) bool
type UnaryArithOp ¶
type UnaryArithOp int
UnaryArithOp is one of the unary arithmetic ops (unary negation, trunc, floor, etc.)
const ( NegOp UnaryArithOp = iota BitNotOp )
type Visitor ¶
Visitor is an interface that must be satisfied by the argument to Visit.
A Visitor's Visit method is invoked for each node encountered by Walk. If the result visitor w is not nil, Walk visits each of the children of node with the visitor w, followed by a call of w.Visit(nil).
(see also: ast.Visitor)