sql

package
v2.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
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

View Source
var ErrUnsupportedClause = errors.New("unsupported clause")

ErrUnsupportedClause represents an error of type "unsupported clause"

View Source
var ErrUnsupportedVerb = errors.New("unsupported verb")

ErrUnsupportedVerb represents an error of type "unsupported verb"

Functions

func AtFrom

func AtFrom(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtFrom is the state where the current item is of type TokenFrom

func AtGroupBy

func AtGroupBy(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtGroupBy is the state where the current item is of type TokenGroupBy

func AtHaving

func AtHaving(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtHaving is the state where the current item is of type TokenHaving

func AtIntoOutfile

func AtIntoOutfile(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtIntoOutfile is the state where the current item is of type TokenIntoOutfile

func AtLimit

func AtLimit(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtLimit is the state where the current item is of type TokenLimit

func AtOrderBy

func AtOrderBy(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtOrderBy is the state where the current item is of type TokenOrderBy

func AtSelect

func AtSelect(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

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

func AtUnion(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn

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 AtWhere

func AtWhere(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

AtWhere is the state where the current item is of type TokenWhere

func DefaultIsBreakable

func DefaultIsBreakable(t token.Typ) bool

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

func DefaultIsContinuable(t token.Typ) bool

DefaultIsContinuable returns true if the token is irrelevant to the parsing of the base query such as a Space or Comment

func FindVerb

func FindVerb(_, ip parsing.Parser, rs *parsing.RunState) parsing.StateFn

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

func HasLimitClause(results ts.Lookup) bool

HasLimitClause returns true if the limitTokens entry is not nil

func IsFromFieldDelimiterType

func IsFromFieldDelimiterType(t token.Typ) bool

IsFromFieldDelimiterType returns true if the provided Typ is a FROM delimiter

func IsWhereBreakable

func IsWhereBreakable(t token.Typ) bool

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 New

func New(po *parsing.Options) parsing.Parser

New returns a new SQL Parser, customized with the provided options

func SelectTokens

func SelectTokens(rs *parsing.RunState) []token.Tokens

SelectTokens returns the parsed tokens grouped into the SELECT clause

func UnsupportedClause

func UnsupportedClause(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn

UnsupportedClause aborts the Parser with an Unsupported Clause error

func UnsupportedVerb

func UnsupportedVerb(_, _ parsing.Parser, rs *parsing.RunState) parsing.StateFn

UnsupportedVerb aborts the Parser with an Unsupported Verb 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

func (p *Parser) GetColumnsList(rs *parsing.RunState) token.Tokens

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) Options

func (sp *Parser) Options() *parsing.Options

Options returns the SQL Parser options

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL