Documentation
¶
Overview ¶
Package dialect provides SQL dialect configuration and function classification.
This package contains the public contract for dialect definitions used by the parser, lineage analyzer, and other SQL-aware components. Concrete dialect implementations are registered from pkg/dialects/*/ packages.
The Dialect struct is now defined in pkg/core. This package provides a Builder for type-safe construction and manages the global registry.
Package dialect provides SQL dialect configuration and function classification.
This file contains stateless clause handlers that form the "toolbox" of reusable parsing logic. These handlers are pure functions that accept spi.ParserOps and return spi.Node.
Package dialect provides SQL dialect configuration and function classification.
This file contains join type definitions that form the "toolbox" of reusable join configurations. These can be composed into any dialect.
Package dialect provides SQL dialect configuration and function classification.
This file contains operator definitions that form the "toolbox" of reusable operator configurations. These can be composed into any dialect.
Package dialect provides SQL dialect configuration and function classification.
This file contains pre-built ClauseDef definitions - the "menu items" that dialects can compose from. Each ClauseDef bundles a token, handler, slot, and metadata together.
Index ¶
- Variables
- func AllClauseTokens(d *core.Dialect) []token.TokenType
- func AllFunctions(d *core.Dialect) []string
- func AllJoinTypeTokens(d *core.Dialect) []token.TokenType
- func AllKnownClauses() map[token.TokenType]string
- func ClauseHandler(d *core.Dialect, t token.TokenType) spi.ClauseHandler
- func FormatPlaceholder(d *core.Dialect, index int) string
- func FromItemHandler(d *core.Dialect, t token.TokenType) spi.FromItemHandler
- func FunctionLineageType(d *core.Dialect, name string) core.FunctionLineageType
- func Get(name string) (*core.Dialect, bool)
- func GroupBy(opts GroupByOpts) core.ClauseDef
- func InfixHandler(d *core.Dialect, t token.TokenType) spi.InfixHandler
- func IsKnownClause(t token.TokenType) (string, bool)
- func Keywords(d *core.Dialect) []string
- func List() []string
- func OrderBy(opts OrderByOpts) core.ClauseDef
- func ParseFetch(p spi.ParserOps) (spi.Node, error)
- func ParseGroupBy(p spi.ParserOps) (spi.Node, error)
- func ParseGroupByWithAll(p spi.ParserOps) (spi.Node, error)
- func ParseHaving(p spi.ParserOps) (spi.Node, error)
- func ParseLimit(p spi.ParserOps) (spi.Node, error)
- func ParseOffset(p spi.ParserOps) (spi.Node, error)
- func ParseOrderBy(p spi.ParserOps) (spi.Node, error)
- func ParseOrderByWithAll(p spi.ParserOps) (spi.Node, error)
- func ParseQualify(p spi.ParserOps) (spi.Node, error)
- func ParseWhere(p spi.ParserOps) (spi.Node, error)
- func ParseWindow(_ spi.ParserOps) (spi.Node, error)
- func PrefixHandler(d *core.Dialect, t token.TokenType) spi.PrefixHandler
- func Register(d *core.Dialect)
- func StarModifierHandler(d *core.Dialect, t token.TokenType) spi.StarModifierHandler
- type Builder
- func (b *Builder) AddClauseAfter(after, t token.TokenType, handler spi.ClauseHandler, slot core.ClauseSlot, ...) *Builder
- func (b *Builder) AddFromItem(t token.TokenType, handler spi.FromItemHandler) *Builder
- func (b *Builder) AddInfix(t token.TokenType, precedence int) *Builder
- func (b *Builder) AddInfixWithHandler(t token.TokenType, precedence int, handler spi.InfixHandler) *Builder
- func (b *Builder) AddJoinType(t token.TokenType, def core.JoinTypeDef) *Builder
- func (b *Builder) AddKeyword(name string, t token.TokenType) *Builder
- func (b *Builder) AddOperator(symbol string, t token.TokenType) *Builder
- func (b *Builder) AddPrefix(t token.TokenType, handler spi.PrefixHandler) *Builder
- func (b *Builder) AddStarModifier(t token.TokenType, handler spi.StarModifierHandler) *Builder
- func (b *Builder) Aggregates(funcs ...string) *Builder
- func (b *Builder) Build() *core.Dialect
- func (b *Builder) ClauseHandler(t token.TokenType, handler spi.ClauseHandler, slot core.ClauseSlot, ...) *Builder
- func (b *Builder) ClauseSequence(tokens ...token.TokenType) *Builder
- func (b *Builder) Clauses(defs ...core.ClauseDef) *Builder
- func (b *Builder) DefaultSchema(schema string) *Builder
- func (b *Builder) Generators(funcs ...string) *Builder
- func (b *Builder) Identifiers(quote, quoteEnd, escape string, norm core.NormalizationStrategy) *Builder
- func (b *Builder) JoinTypes(sets ...[]core.JoinTypeDef) *Builder
- func (b *Builder) Operators(sets ...[]core.OperatorDef) *Builder
- func (b *Builder) PlaceholderStyle(style core.PlaceholderStyle) *Builder
- func (b *Builder) RemoveClause(t token.TokenType) *Builder
- func (b *Builder) TableFunctions(funcs ...string) *Builder
- func (b *Builder) Windows(funcs ...string) *Builder
- func (b *Builder) WithDataTypes(types ...string) *Builder
- func (b *Builder) WithDocs(docs map[string]core.FunctionDoc) *Builder
- func (b *Builder) WithKeywords(kws ...string) *Builder
- func (b *Builder) WithReservedWords(words ...string) *Builder
- type ClauseOption
- type FetchClause
- type GroupByOpts
- type OrderByOpts
Constants ¶
This section is empty.
Variables ¶
var ( // StandardWhere is the standard WHERE clause definition. StandardWhere = core.ClauseDef{ Token: token.WHERE, Handler: spi.ClauseHandler(ParseWhere), Slot: core.SlotWhere, } // StandardGroupBy is the standard GROUP BY clause definition. StandardGroupBy = core.ClauseDef{ Token: token.GROUP, Handler: spi.ClauseHandler(ParseGroupBy), Slot: core.SlotGroupBy, Keywords: []string{"GROUP", "BY"}, } // StandardHaving is the standard HAVING clause definition. StandardHaving = core.ClauseDef{ Token: token.HAVING, Handler: spi.ClauseHandler(ParseHaving), Slot: core.SlotHaving, } // StandardWindow is the standard WINDOW clause definition. StandardWindow = core.ClauseDef{ Token: token.WINDOW, Handler: spi.ClauseHandler(ParseWindow), Slot: core.SlotWindow, } // StandardOrderBy is the standard ORDER BY clause definition. StandardOrderBy = core.ClauseDef{ Token: token.ORDER, Handler: spi.ClauseHandler(ParseOrderBy), Slot: core.SlotOrderBy, Keywords: []string{"ORDER", "BY"}, } // StandardLimit is the standard LIMIT clause definition. StandardLimit = core.ClauseDef{ Token: token.LIMIT, Handler: spi.ClauseHandler(ParseLimit), Slot: core.SlotLimit, Inline: true, } // StandardOffset is the standard OFFSET clause definition. StandardOffset = core.ClauseDef{ Token: token.OFFSET, Handler: spi.ClauseHandler(ParseOffset), Slot: core.SlotOffset, Inline: true, } // StandardFetch is the standard FETCH clause definition (SQL:2008). StandardFetch = core.ClauseDef{ Token: token.FETCH, Handler: spi.ClauseHandler(ParseFetch), Slot: core.SlotFetch, } // StandardQualify is the standard QUALIFY clause definition (DuckDB, Databricks, etc.). StandardQualify = core.ClauseDef{ Token: token.QUALIFY, Handler: spi.ClauseHandler(ParseQualify), Slot: core.SlotQualify, } )
var ANSIJoinTypes = []core.JoinTypeDef{ { Token: token.INNER, Type: core.JoinInner, RequiresOn: true, AllowsUsing: true, }, { Token: token.LEFT, Type: core.JoinLeft, OptionalToken: token.OUTER, RequiresOn: true, AllowsUsing: true, }, { Token: token.RIGHT, Type: core.JoinRight, OptionalToken: token.OUTER, RequiresOn: true, AllowsUsing: true, }, { Token: token.FULL, Type: core.JoinFull, OptionalToken: token.OUTER, RequiresOn: true, AllowsUsing: true, }, { Token: token.CROSS, Type: core.JoinCross, RequiresOn: false, AllowsUsing: false, }, }
ANSIJoinTypes contains standard SQL join types.
var ANSIOperators = []core.OperatorDef{ {Token: token.OR, Precedence: core.PrecedenceOr}, {Token: token.AND, Precedence: core.PrecedenceAnd}, {Token: token.EQ, Precedence: core.PrecedenceComparison}, {Token: token.NE, Precedence: core.PrecedenceComparison}, {Token: token.LT, Precedence: core.PrecedenceComparison}, {Token: token.GT, Precedence: core.PrecedenceComparison}, {Token: token.LE, Precedence: core.PrecedenceComparison}, {Token: token.GE, Precedence: core.PrecedenceComparison}, {Token: token.LIKE, Precedence: core.PrecedenceComparison}, {Token: token.IN, Precedence: core.PrecedenceComparison}, {Token: token.BETWEEN, Precedence: core.PrecedenceComparison}, {Token: token.IS, Precedence: core.PrecedenceComparison}, {Token: token.PLUS, Precedence: core.PrecedenceAddition}, {Token: token.MINUS, Precedence: core.PrecedenceAddition}, {Token: token.DPIPE, Precedence: core.PrecedenceAddition}, {Token: token.STAR, Precedence: core.PrecedenceMultiply}, {Token: token.SLASH, Precedence: core.PrecedenceMultiply}, {Token: token.MOD, Precedence: core.PrecedenceMultiply}, }
ANSIOperators contains standard SQL operators with their precedence.
var StandardSelectClauses = []core.ClauseDef{ StandardWhere, StandardGroupBy, StandardHaving, StandardWindow, StandardOrderBy, StandardLimit, StandardOffset, StandardFetch, }
StandardSelectClauses is the typical ANSI SELECT clause sequence. Dialects can use this directly or compose their own from the individual defs.
Functions ¶
func AllClauseTokens ¶
AllClauseTokens returns all clause tokens registered in this dialect.
func AllFunctions ¶
AllFunctions returns all known function names.
func AllJoinTypeTokens ¶
AllJoinTypeTokens returns all join type tokens registered in this dialect.
func AllKnownClauses ¶
AllKnownClauses returns all registered clause tokens. Useful for debugging and testing. This is a convenience wrapper around core.AllKnownClauses.
func ClauseHandler ¶
ClauseHandler returns the handler for a clause token type.
func FormatPlaceholder ¶
FormatPlaceholder returns a placeholder for the given parameter index (1-based).
func FromItemHandler ¶
FromItemHandler returns the handler for a FROM item token type.
func FunctionLineageType ¶
func FunctionLineageType(d *core.Dialect, name string) core.FunctionLineageType
FunctionLineageType returns the lineage classification for a function.
func GroupBy ¶
func GroupBy(opts GroupByOpts) core.ClauseDef
GroupBy returns a ClauseDef for GROUP BY with options.
func InfixHandler ¶
InfixHandler returns the custom infix handler for an operator token.
func IsKnownClause ¶
IsKnownClause returns true if ANY registered dialect uses this token as a clause. Returns the clause name for error messages. This is a convenience wrapper around core.IsKnownClause.
func OrderBy ¶
func OrderBy(opts OrderByOpts) core.ClauseDef
OrderBy returns a ClauseDef for ORDER BY with options.
func ParseFetch ¶
ParseFetch handles the FETCH FIRST/NEXT clause (SQL:2008). The FETCH keyword has already been consumed.
func ParseGroupBy ¶
ParseGroupBy handles the standard GROUP BY clause. The GROUP keyword has already been consumed.
func ParseGroupByWithAll ¶
ParseGroupByWithAll handles GROUP BY with optional ALL keyword. The GROUP keyword has already been consumed.
func ParseHaving ¶
ParseHaving handles the standard HAVING clause. The HAVING keyword has already been consumed.
func ParseLimit ¶
ParseLimit handles the standard LIMIT clause. The LIMIT keyword has already been consumed.
func ParseOffset ¶
ParseOffset handles the standard OFFSET clause. The OFFSET keyword has already been consumed.
func ParseOrderBy ¶
ParseOrderBy handles the standard ORDER BY clause. The ORDER keyword has already been consumed.
func ParseOrderByWithAll ¶
ParseOrderByWithAll handles ORDER BY with optional ALL keyword. The ORDER keyword has already been consumed.
func ParseQualify ¶
ParseQualify handles the QUALIFY clause (DuckDB, Databricks, etc.). The QUALIFY keyword has already been consumed.
func ParseWhere ¶
ParseWhere handles the standard WHERE clause. The WHERE keyword has already been consumed.
func ParseWindow ¶
ParseWindow handles named window definitions. The WINDOW keyword has already been consumed.
func PrefixHandler ¶
PrefixHandler returns the custom prefix handler for an operator token.
func Register ¶
Register registers a dialect in the global registry. Called by dialect implementations in their init() functions.
func StarModifierHandler ¶
StarModifierHandler returns the handler for a star modifier token type.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides a fluent API for constructing dialects.
func New ¶
func New(cfg *core.DialectConfig) *Builder
New creates a dialect builder from a DialectConfig. The builder will auto-wire features based on config flags when Build() is called.
func NewDialect ¶
NewDialect creates a new dialect builder with the given name.
func (*Builder) AddClauseAfter ¶
func (b *Builder) AddClauseAfter(after, t token.TokenType, handler spi.ClauseHandler, slot core.ClauseSlot, opts ...ClauseOption) *Builder
AddClauseAfter inserts a clause into the sequence after another clause.
func (*Builder) AddFromItem ¶
AddFromItem registers a FROM clause item handler.
func (*Builder) AddInfixWithHandler ¶
func (b *Builder) AddInfixWithHandler(t token.TokenType, precedence int, handler spi.InfixHandler) *Builder
AddInfixWithHandler registers an infix operator with custom handler.
func (*Builder) AddJoinType ¶
AddJoinType registers a dialect-specific join type.
func (*Builder) AddKeyword ¶
AddKeyword registers a dynamic keyword for the lexer.
func (*Builder) AddOperator ¶
AddOperator registers a custom operator symbol for the lexer.
func (*Builder) AddStarModifier ¶
AddStarModifier registers a star expression modifier handler.
func (*Builder) Aggregates ¶
Aggregates adds aggregate functions to the dialect.
func (*Builder) Build ¶
Build returns the constructed dialect. If the builder was created with New(cfg), this auto-wires features based on config flags.
func (*Builder) ClauseHandler ¶
func (b *Builder) ClauseHandler(t token.TokenType, handler spi.ClauseHandler, slot core.ClauseSlot, opts ...ClauseOption) *Builder
ClauseHandler registers a handler for a clause token with storage slot.
func (*Builder) ClauseSequence ¶
ClauseSequence sets the full clause sequence (for base dialects).
func (*Builder) DefaultSchema ¶
DefaultSchema sets the default schema name.
func (*Builder) Generators ¶
Generators adds generator functions (no input columns) to the dialect.
func (*Builder) Identifiers ¶
func (b *Builder) Identifiers(quote, quoteEnd, escape string, norm core.NormalizationStrategy) *Builder
Identifiers configures identifier quoting and normalization.
func (*Builder) JoinTypes ¶
func (b *Builder) JoinTypes(sets ...[]core.JoinTypeDef) *Builder
JoinTypes adds join type definitions in bulk.
func (*Builder) Operators ¶
func (b *Builder) Operators(sets ...[]core.OperatorDef) *Builder
Operators adds operator definitions in bulk.
func (*Builder) PlaceholderStyle ¶
func (b *Builder) PlaceholderStyle(style core.PlaceholderStyle) *Builder
PlaceholderStyle sets how query parameters are formatted.
func (*Builder) RemoveClause ¶
RemoveClause removes a clause from the sequence.
func (*Builder) TableFunctions ¶
TableFunctions adds table-valued functions to the dialect.
func (*Builder) WithDataTypes ¶
WithDataTypes registers supported data types.
func (*Builder) WithDocs ¶
func (b *Builder) WithDocs(docs map[string]core.FunctionDoc) *Builder
WithDocs registers documentation for functions.
func (*Builder) WithKeywords ¶
WithKeywords registers reserved keywords.
func (*Builder) WithReservedWords ¶
WithReservedWords registers words that need quoting when used as identifiers.
type ClauseOption ¶
ClauseOption configures a ClauseDef.
func WithInline ¶
func WithInline() ClauseOption
WithInline marks a clause as inline (keyword and value on same line).
func WithKeywords ¶
func WithKeywords(keywords ...string) ClauseOption
WithKeywords sets the display keywords for a clause.
type FetchClause ¶
type FetchClause struct {
First bool // true = FIRST, false = NEXT (semantically identical)
Count core.Expr // Number of rows (nil = 1 row implied)
Percent bool // FETCH FIRST n PERCENT ROWS
WithTies bool // true = WITH TIES, false = ONLY
}
FetchClause represents FETCH FIRST/NEXT n ROWS ONLY/WITH TIES (SQL:2008). This is defined here to avoid import cycles with the parser package.
func (*FetchClause) GetCount ¶
func (f *FetchClause) GetCount() core.Expr
GetCount implements FetchClauseData.
func (*FetchClause) GetFirst ¶
func (f *FetchClause) GetFirst() bool
GetFirst implements FetchClauseData.
func (*FetchClause) GetPercent ¶
func (f *FetchClause) GetPercent() bool
GetPercent implements FetchClauseData.
func (*FetchClause) GetWithTies ¶
func (f *FetchClause) GetWithTies() bool
GetWithTies implements FetchClauseData.
type GroupByOpts ¶
type GroupByOpts struct {
AllowAll bool // Support GROUP BY ALL
}
GroupByOpts configures GROUP BY clause behavior.
type OrderByOpts ¶
type OrderByOpts struct {
AllowAll bool // Support ORDER BY ALL
}
OrderByOpts configures ORDER BY clause behavior.