Documentation
¶
Overview ¶
Package sql provides a basic SQL SQLParser that can be extended by individual implementations. Because Trickster is a proxy/cache for time series, this package currently only has base support for specific SELECT statements
NOTE: While Trickster does not proved a true, full AST; we would love to and welcome all contributions
Index ¶
- Variables
- func AtFrom(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtGroupBy(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtHaving(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtIntoOutfile(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtLimit(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtOrderBy(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtSelect(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtUnion(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func AtWhere(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func DefaultIsBreakable(t token.Typ) bool
- func DefaultIsContinuable(t token.Typ) bool
- func FindVerb(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func GetField(rs *parsing.RunState, isDelim, isBreakable, isContinuable token.TypeCheckFunc, ...) (token.Tokens, bool)
- func HasLimitClause(results ts.Lookup) bool
- func IsFromFieldDelimiterType(t token.Typ) bool
- func IsWhereBreakable(t token.Typ) bool
- func New(po *parsing.Options) parsing.Parser
- func SelectTokens(rs *parsing.RunState) []token.Tokens
- func UnsupportedClause(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn
- func UnsupportedVerb(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn
- type Parser
- func (p *Parser) GetColumnsList(rs *parsing.RunState) token.Tokens
- func (p *Parser) GetFieldList(rs *parsing.RunState, allowedToken token.Typ, disAllowedTokenErr error, ...) []token.Tokens
- func (sp *Parser) Options() *parsing.Options
- func (sp *Parser) Run(ctx context.Context, p parsing.Parser, query string) (*parsing.RunState, error)
- func (p *Parser) SelectQueryKeywords() parsing.DecisionSet
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyGroupBy = errors.New("missing or empty GROUP BY section")
ErrEmptyGroupBy is an error for when a GROUP BY clause is missing or has no columngs
var ErrNotAtFrom = errors.New("not at a FROM token")
ErrNotAtFrom is an error for when the RunState expected, but did not get, a FROM token
var ErrNotAtGroupBy = errors.New("not at a GROUP BY token")
ErrNotAtGroupBy is an error for when the RunState expected, but did not get, a GROUP BY token
var ErrNotAtHaving = errors.New("not at a HAVING token")
ErrNotAtHaving is an error for when the RunState expected, but did not get, a HAVING token
var ErrNotAtLimit = errors.New("not at a LIMIT token")
ErrNotAtLimit is an error for when the RunState expected, but did not get, a LIMIT token
var ErrNotAtOrderBy = errors.New("not at an ORDER BY token")
ErrNotAtOrderBy is an error for when the RunState expected, but did not get, an ORDER BY token
var ErrNotAtSelect = errors.New("not at a SELECT token")
ErrNotAtSelect is an error for when the RunState expected, but did not get, a SELECT token
var ErrNotAtWhere = errors.New("not at a WHERE token")
ErrNotAtWhere is an error for when the RunState expected, but did not get, a WHERE token
var ErrNotAtWith = errors.New("not at a WITH token")
ErrNotAtWith is an error for when the RunState expected, but did not get, a WITH token
var ErrUnsupportedClause = errors.New("unsupported clause")
ErrUnsupportedClause represents an error of type "unsupported clause"
var ErrUnsupportedVerb = errors.New("unsupported verb")
ErrUnsupportedVerb represents an error of type "unsupported verb"
Functions ¶
func AtIntoOutfile ¶
AtIntoOutfile is the state where the current item is of type TokenIntoOutfile
func AtSelect ¶
AtSelect is the state where the current item is of type TokenSelect it will parse the incoming items into a list of item lists that comprise the fields in the clause
func AtUnion ¶
AtUnion is the state where the current item is of type TokenUnion Trickster does not currently support queries with Union (we only need to look at the first query to get the structure and time series info we need, but we welcome all help in extending this support!)
func DefaultIsBreakable ¶
DefaultIsBreakable returns true if the token is a loop-breakable token - a primary keyword. These indicate the parser should break any loops and start a new token collection
func DefaultIsContinuable ¶
DefaultIsContinuable returns true if the token is irrelevant to the parsing of the base query such as a Space or Comment
func FindVerb ¶
FindVerb will find the SQL Verb (SELECT, INSERT, etc.), bypassing any spaces or comments
func GetField ¶
func GetField( rs *parsing.RunState, isDelim, isBreakable, isContinuable token.TypeCheckFunc, isolateDelimiter bool, ) (token.Tokens, bool)
GetField returns a list of tokens associated with the Field or Phrase, omitting non-conjuctive delimiters (e.g., comma) not enclosed in parenthesis. The returned Tokens adds any logical operator delimiter as the last element.
func HasLimitClause ¶
HasLimitClause returns true if the limitTokens entry is not nil
func IsFromFieldDelimiterType ¶
IsFromFieldDelimiterType returns true if the provided Typ is a FROM delimiter
func IsWhereBreakable ¶
IsWhereBreakable returns true if the token is a loop-breakable token (EOF or Error), or a primary keyword excluding BETWEEN. These indicate the parser should break any loops and start a new token collection
func SelectTokens ¶
SelectTokens returns the parsed tokens grouped into the SELECT clause
func UnsupportedClause ¶
UnsupportedClause aborts the Parser with an Unsupported Clause error
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents the base SQLParser struct that conforms to the Parser interface
func (*Parser) GetColumnsList ¶
GetColumnsList returns a list of columns following a keyword and terminated by a keywords or EOF It omits the comma delimiter, and includes only the field identifier tokens This works for getting columns in GROUP BY clauses. RunState.Current() is expected to be on the sql keyword just prior to the start of its list
func (*Parser) GetFieldList ¶
func (p *Parser) GetFieldList(rs *parsing.RunState, allowedToken token.Typ, disAllowedTokenErr error, isDelim, isBreakable, isContinuable token.TypeCheckFunc, isolateDelimiter bool, ) []token.Tokens
GetFieldList gets a list of fields. A field is considered a list of tokens that comprises the definition of a single output field/column in the result. It expects RunState to be at the keyword just prior to the start of the
func (*Parser) Run ¶
func (sp *Parser) Run(ctx context.Context, p parsing.Parser, query string, ) (*parsing.RunState, error)
Run runs the SQL Parser
func (*Parser) SelectQueryKeywords ¶
func (p *Parser) SelectQueryKeywords() parsing.DecisionSet
SelectQueryKeywords returns the SelectQueryKeywords DecisionSet