Documentation ¶
Overview ¶
Package query_parser is a parser to parse a simplified select statement (a la SQL) for the Vanadium key value store (a.k.a., syncbase).
The select is of the form:
<query_specification> ::=
<select_statement> | <delete_statement>
<select_statement> ::=
<select_clause> <from_clause> [<where_clause>] [<escape_limit_offset_clause>...]
<delete_statement> ::=
delete <from_clause> [<where_clause>] [<escape_limit_clause>...]
<select_clause> ::= SELECT <selector> [{<comma><selector>}...]
<from_clause> ::= FROM <table>
<where_clause> ::= WHERE <expression>
<escape_limit_offset_clause> ::=
ESCAPE <char_literal> | LIMIT <int_literal> | OFFSET <int_literal>
<escape_limit_clause> ::=
ESCAPE <char_literal> | LIMIT <int_literal>
<selector> ::= <column> [AS <string_literal>]
<column> ::=
k | v[<period><field>] | <function>
<field> ::= <segment>[{<period><segment>}...]
<segment> ::= <identifier>[<keys>]
<keys> ::= <key>...
<key> ::= <left_bracket> <operand> <right_bracket>
<function> ::= <identifier><left_paren>[<operand>[{<comma><operand>}...]<right_paren>
<table> ::= <identifier>
<expression> ::=
<left_paren> <expression> <right_paren> | <logical_expression> | <binary_expression>
<logical_expression> ::=
<expression> <logical_op> <expression>
<logical_op> ::=
AND | OR
<binary_expression> ::=
<operand> <binary_op> <operand> | v[<period><field>] IS [NOT] NIL
<operand> ::=
k | v[<period><field>] | <literal> | <function>
<binary_op> ::=
= | EQUAL | <> | NOT EQUAL | LIKE | NOT LIKE | < | <= | >= | >
<literal> ::=
<string_literal> | <bool_literal> | <int_literal> | <float_literal>
Example: select v.Foo.Far, v.Baz[2] from Foobarbaz where Type(v) like "%.Customer" and (v.Foo = 42 and v.Bar not like "abc%) or (k >= "100" and k < "200")
Index ¶
- Constants
- type AsClause
- type BinaryOperator
- type BinaryOperatorType
- type CharValue
- type DeleteStatement
- type EscapeClause
- type Expression
- type Field
- type FromClause
- type Function
- type Int64Value
- type LimitClause
- type Name
- type Node
- type Operand
- type OperandType
- type ResultsOffsetClause
- type Segment
- type SelectClause
- type SelectStatement
- type Selector
- type SelectorType
- type Statement
- type TableEntry
- type Token
- type TokenType
- type WhereClause
Constants ¶
const (
MaxStatementLen = 10000
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BinaryOperator ¶
type BinaryOperator struct { Type BinaryOperatorType Node }
func (BinaryOperator) String ¶
func (o BinaryOperator) String() string
type BinaryOperatorType ¶
type BinaryOperatorType int
const ( And BinaryOperatorType = 1 + iota Equal GreaterThan GreaterThanOrEqual Is IsNot LessThan LessThanOrEqual Like NotEqual NotLike Or )
type DeleteStatement ¶
type DeleteStatement struct { From *FromClause Where *WhereClause Escape *EscapeClause Limit *LimitClause Node }
func (DeleteStatement) CopyAndSubstitute ¶
func (DeleteStatement) Offset ¶
func (st DeleteStatement) Offset() int64
func (DeleteStatement) String ¶
func (st DeleteStatement) String() string
Pretty string of delete statement.
type EscapeClause ¶
func (EscapeClause) String ¶
func (e EscapeClause) String() string
type Expression ¶
type Expression struct { Operand1 *Operand Operator *BinaryOperator Operand2 *Operand Node }
func (Expression) CopyAndSubstitute ¶
func (e Expression) CopyAndSubstitute(db ds.Database, pi *paramInfo) (*Expression, error)
func (Expression) String ¶
func (e Expression) String() string
type Field ¶
func ParseIndexField ¶
ParseIndexField is used to parse datasource supplied index fields. It creates a new scanner with the contents of the field name and only succeeds if the result of parsing the contents of the scan is a field and there is nothing left over. Note: This function is NOT involved in the parsing of the AST. Offsets of 0 are
returned on error as these errors are unrelated to the input query. They are configuration errors in the datasource.
type FromClause ¶
type FromClause struct { Table TableEntry Node }
func (FromClause) String ¶
func (f FromClause) String() string
type Function ¶
type Function struct { Name string Args []*Operand ArgTypes []OperandType // Filled in by checker. RetType OperandType // Filled in by checker. Computed bool // Checker sets to true and sets RetValue if function takes no args RetValue *Operand Node }
func (Function) CopyAndSubstitute ¶
type Int64Value ¶
func (Int64Value) String ¶
func (i Int64Value) String() string
type LimitClause ¶
type LimitClause struct { Limit *Int64Value Node }
func (LimitClause) String ¶
func (l LimitClause) String() string
type Operand ¶
type Operand struct { Type OperandType BigInt *big.Int BigRat *big.Rat Bool bool Column *Field Float float64 Function *Function Int int64 Str string Time time.Time Prefix string // Computed by checker for Like expressions Pattern *pattern.Pattern // Computed by checker for Like expressions Uint uint64 Expr *Expression Object *vdl.Value Node }
func ConvertValueToAnOperand ¶
func (Operand) CopyAndSubstitute ¶
type OperandType ¶
type OperandType int
const ( TypBigInt OperandType = 1 + iota // Only as a result of Resolve/Coerce Operand TypBigRat // Only as a result of Resolve/Coerce Operand TypBool TypExpr TypField TypFloat TypFunction TypInt TypNil TypParameter TypStr TypTime TypObject // Only as the result of a ResolveOperand TypUint // Only as the result of a ResolveOperand )
type ResultsOffsetClause ¶
type ResultsOffsetClause struct { ResultsOffset *Int64Value Node }
func (ResultsOffsetClause) String ¶
func (l ResultsOffsetClause) String() string
type Segment ¶
type SelectClause ¶
func (SelectClause) String ¶
func (sel SelectClause) String() string
type SelectStatement ¶
type SelectStatement struct { Select *SelectClause From *FromClause Where *WhereClause Escape *EscapeClause Limit *LimitClause ResultsOffset *ResultsOffsetClause Node }
func (SelectStatement) CopyAndSubstitute ¶
func (SelectStatement) Offset ¶
func (st SelectStatement) Offset() int64
func (SelectStatement) String ¶
func (st SelectStatement) String() string
Pretty string of select statement.
type Selector ¶
type Selector struct { Type SelectorType Field *Field Function *Function As *AsClause // If not nil, used in returned column header. Node }
Selector: entries in the select clause. Entries can be functions for fields. The AS name, if present, will ONLY be used in the returned column header.
type Statement ¶
type TableEntry ¶
type TableEntry struct { Name string DBTable ds.Table // Checker gets table from db and sets this. Node }
func (TableEntry) String ¶
func (t TableEntry) String() string
type WhereClause ¶
type WhereClause struct { Expr *Expression Node }
func (WhereClause) CopyAndSubstitute ¶
func (w WhereClause) CopyAndSubstitute(db ds.Database, paramValues []*vdl.Value) (*WhereClause, error)
func (WhereClause) String ¶
func (w WhereClause) String() string