v.io: v.io/v23/query/engine/internal/queryparser Index | Files

package queryparser

import "v.io/v23/query/engine/internal/queryparser"

Package queryparser 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

Package Files

doc.go query_parser.go

Constants

const (
    MaxStatementLen = 10000
)

type AsClause Uses

type AsClause struct {
    AltName Name
    Node
}

func (AsClause) String Uses

func (a AsClause) String() string

type BinaryOperator Uses

type BinaryOperator struct {
    Type BinaryOperatorType
    Node
}

func (BinaryOperator) String Uses

func (o BinaryOperator) String() string

type BinaryOperatorType Uses

type BinaryOperatorType int
const (
    And BinaryOperatorType = 1 + iota
    Equal
    GreaterThan
    GreaterThanOrEqual
    Is
    IsNot
    LessThan
    LessThanOrEqual
    Like
    NotEqual
    NotLike
    Or
)

type CharValue Uses

type CharValue struct {
    Value rune
    Node
}

func (CharValue) String Uses

func (c CharValue) String() string

type DeleteStatement Uses

type DeleteStatement struct {
    From   *FromClause
    Where  *WhereClause
    Escape *EscapeClause
    Limit  *LimitClause
    Node
}

func (DeleteStatement) CopyAndSubstitute Uses

func (st DeleteStatement) CopyAndSubstitute(db ds.Database, paramValues []*vdl.Value) (Statement, error)

func (DeleteStatement) Offset Uses

func (st DeleteStatement) Offset() int64

func (DeleteStatement) String Uses

func (st DeleteStatement) String() string

Pretty string of delete statement.

type EscapeClause Uses

type EscapeClause struct {
    EscapeChar *CharValue
    Node
}

func (EscapeClause) String Uses

func (e EscapeClause) String() string

type Expression Uses

type Expression struct {
    Operand1 *Operand
    Operator *BinaryOperator
    Operand2 *Operand
    Node
}

func (Expression) CopyAndSubstitute Uses

func (e Expression) CopyAndSubstitute(db ds.Database, pi *paramInfo) (*Expression, error)

func (Expression) String Uses

func (e Expression) String() string

type Field Uses

type Field struct {
    Segments []Segment
    Node
}

func ParseIndexField Uses

func ParseIndexField(db ds.Database, fieldName, tableName string) (*Field, error)

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.

func (Field) String Uses

func (f Field) String() string

type FromClause Uses

type FromClause struct {
    Table TableEntry
    Node
}

func (FromClause) String Uses

func (f FromClause) String() string

type Function Uses

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 Uses

func (f Function) CopyAndSubstitute(db ds.Database, pi *paramInfo) (*Function, error)

func (Function) String Uses

func (f Function) String() string

type Int64Value Uses

type Int64Value struct {
    Value int64
    Node
}

func (Int64Value) String Uses

func (i Int64Value) String() string

type LimitClause Uses

type LimitClause struct {
    Limit *Int64Value
    Node
}

func (LimitClause) String Uses

func (l LimitClause) String() string

type Name Uses

type Name struct {
    Value string
    Node
}

func (Name) String Uses

func (n Name) String() string

type Node Uses

type Node struct {
    Off int64
}

type Operand Uses

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 Uses

func ConvertValueToAnOperand(value *vdl.Value, off int64) (*Operand, error)

func (Operand) CopyAndSubstitute Uses

func (o Operand) CopyAndSubstitute(db ds.Database, pi *paramInfo) (*Operand, error)

func (Operand) String Uses

func (o Operand) String() string

type OperandType Uses

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 Uses

type ResultsOffsetClause struct {
    ResultsOffset *Int64Value
    Node
}

func (ResultsOffsetClause) String Uses

func (l ResultsOffsetClause) String() string

type Segment Uses

type Segment struct {
    Value string
    Keys  []*Operand // Used as key(s) or index(es) to dereference map/set/array/list.
    Node
}

func (Segment) String Uses

func (s Segment) String() string

type SelectClause Uses

type SelectClause struct {
    Selectors []Selector
    Node
}

func (SelectClause) String Uses

func (sel SelectClause) String() string

type SelectStatement Uses

type SelectStatement struct {
    Select        *SelectClause
    From          *FromClause
    Where         *WhereClause
    Escape        *EscapeClause
    Limit         *LimitClause
    ResultsOffset *ResultsOffsetClause
    Node
}

func (SelectStatement) CopyAndSubstitute Uses

func (st SelectStatement) CopyAndSubstitute(db ds.Database, paramValues []*vdl.Value) (Statement, error)

func (SelectStatement) Offset Uses

func (st SelectStatement) Offset() int64

func (SelectStatement) String Uses

func (st SelectStatement) String() string

Pretty string of select statement.

type Selector Uses

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.

func (Selector) String Uses

func (s Selector) String() string

type SelectorType Uses

type SelectorType int
const (
    TypSelField SelectorType = 1 + iota
    TypSelFunc
)

type Statement Uses

type Statement interface {
    Offset() int64
    String() string
    CopyAndSubstitute(db ds.Database, paramValues []*vdl.Value) (Statement, error)
}

func Parse Uses

func Parse(db ds.Database, src string) (*Statement, error)

Parse a statement. Return it or an error.

type TableEntry Uses

type TableEntry struct {
    Name    string
    DBTable ds.Table // Checker gets table from db and sets this.
    Node
}

func (TableEntry) String Uses

func (t TableEntry) String() string

type Token Uses

type Token struct {
    Tok   TokenType
    Value string
    Off   int64
}

type TokenType Uses

type TokenType int
const (
    TokCHAR TokenType = 1 + iota
    TokCOMMA
    TokEOF
    TokEQUAL
    TokFLOAT
    TokIDENT
    TokINT
    TokLEFTANGLEBRACKET
    TokLEFTBRACKET
    TokLEFTPAREN
    TokMINUS
    TokParameter // allowed only in prepared statements
    TokPERIOD
    TokRIGHTANGLEBRACKET
    TokRIGHTBRACKET
    TokRIGHTPAREN
    TokSTRING
    TokERROR
)

type WhereClause Uses

type WhereClause struct {
    Expr *Expression
    Node
}

func (WhereClause) CopyAndSubstitute Uses

func (w WhereClause) CopyAndSubstitute(db ds.Database, paramValues []*vdl.Value) (*WhereClause, error)

func (WhereClause) String Uses

func (w WhereClause) String() string

Package queryparser imports 11 packages (graph) and is imported by 8 packages. Updated 2020-10-29. Refresh now. Tools for package owners.