Documentation ¶
Index ¶
- Variables
- type Analyzer
- type Batch
- type Builder
- func (ab *Builder) AddPostAnalyzeRule(name string, fn RuleFunc) *Builder
- func (ab *Builder) AddPostValidationRule(name string, fn RuleFunc) *Builder
- func (ab *Builder) AddPreAnalyzeRule(name string, fn RuleFunc) *Builder
- func (ab *Builder) AddPreValidationRule(name string, fn RuleFunc) *Builder
- func (ab *Builder) Build() *Analyzer
- func (ab *Builder) WithDebug() *Builder
- func (ab *Builder) WithParallelism(parallelism int) *Builder
- type Rule
- type RuleFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrColumnTableNotFound is returned when the column does not exist in a // the table. ErrColumnTableNotFound = errors.NewKind("table %q does not have column %q") // ErrColumnNotFound is returned when the column does not exist in any // table in scope. ErrColumnNotFound = errors.NewKind("column %q could not be found in any table in scope") // ErrAmbiguousColumnName is returned when there is a column reference that // is present in more than one table. ErrAmbiguousColumnName = errors.NewKind("ambiguous column name %q, it's present in all these tables: %v") // ErrFieldMissing is returned when the field is not on the schema. ErrFieldMissing = errors.NewKind("field %q is not on schema") // ErrOrderByColumnIndex is returned when in an order clause there is a // column that is unknown. ErrOrderByColumnIndex = errors.NewKind("unknown column %d in order by clause") // ErrMisusedAlias is returned when a alias is defined and used in the same projection. ErrMisusedAlias = errors.NewKind("column %q does not exist in scope, but there is an alias defined in" + " this projection with that name. Aliases cannot be used in the same projection they're defined in") )
var ( // ErrValidationResolved is returned when the plan can not be resolved. ErrValidationResolved = errors.NewKind("plan is not resolved because of node '%T'") // ErrValidationOrderBy is returned when the order by contains aggregation // expressions. ErrValidationOrderBy = errors.NewKind("OrderBy does not support aggregation expressions") // ErrValidationGroupBy is returned when the aggregation expression does not // appear in the grouping columns. ErrValidationGroupBy = errors.NewKind("GroupBy aggregate expression '%v' doesn't appear in the grouping columns") // ErrValidationSchemaSource is returned when there is any column source // that does not match the table name. ErrValidationSchemaSource = errors.NewKind("one or more schema sources are empty") // ErrProjectTuple is returned when there is a tuple of more than 1 column // inside a projection. ErrProjectTuple = errors.NewKind("selected field %d should have 1 column, but has %d") // ErrUnknownIndexColumns is returned when there are columns in the expr // to index that are unknown in the table. ErrUnknownIndexColumns = errors.NewKind("unknown columns to index for table %q: %s") // ErrCaseResultType is returned when one or more of the types of the values in // a case expression don't match. ErrCaseResultType = errors.NewKind( "expecting all case branches to return values of type %s, " + "but found value %q of type %s on %s", ) )
var DefaultRules = []Rule{
{"resolve_natural_joins", resolveNaturalJoins},
{"resolve_orderby_literals", resolveOrderByLiterals},
{"resolve_orderby", resolveOrderBy},
{"resolve_grouping_columns", resolveGroupingColumns},
{"qualify_columns", qualifyColumns},
{"resolve_columns", resolveColumns},
{"resolve_database", resolveDatabase},
{"resolve_star", resolveStar},
{"resolve_functions", resolveFunctions},
{"reorder_aggregations", reorderAggregations},
{"reorder_projection", reorderProjection},
{"move_join_conds_to_filter", moveJoinConditionsToFilter},
{"eval_filter", evalFilter},
{"optimize_distinct", optimizeDistinct},
}
DefaultRules to apply when analyzing nodes.
var DefaultValidationRules = []Rule{
{validateResolvedRule, validateIsResolved},
{validateOrderByRule, validateOrderBy},
{validateGroupByRule, validateGroupBy},
{validateSchemaSourceRule, validateSchemaSource},
{validateProjectTuplesRule, validateProjectTuples},
{validateIndexCreationRule, validateIndexCreation},
{validateCaseResultTypesRule, validateCaseResultTypes},
}
DefaultValidationRules to apply while analyzing nodes.
var ErrMaxAnalysisIters = errors.NewKind("exceeded max analysis iterations (%d)")
ErrMaxAnalysisIters is thrown when the analysis iterations are exceeded
var OnceAfterAll = []Rule{
{"track_process", trackProcess},
{"parallelize", parallelize},
{"clear_warnings", clearWarnings},
}
OnceAfterAll contains the rules to be applied just once after all other rules have been applied.
var OnceAfterDefault = []Rule{
{"remove_unnecessary_converts", removeUnnecessaryConverts},
{"assign_catalog", assignCatalog},
{"prune_columns", pruneColumns},
{"pushdown", pushdown},
{"erase_projection", eraseProjection},
}
OnceAfterDefault contains the rules to be applied just once after the DefaultRules.
var OnceBeforeDefault = []Rule{
{"resolve_subqueries", resolveSubqueries},
{"resolve_tables", resolveTables},
{"check_aliases", checkAliases},
}
OnceBeforeDefault contains the rules to be applied just once before the DefaultRules.
Functions ¶
This section is empty.
Types ¶
type Analyzer ¶
type Analyzer struct { Debug bool Parallelism int // Batches of Rules to apply. Batches []*Batch // Catalog of databases and registered functions. Catalog *sql.Catalog }
Analyzer analyzes nodes of the execution plan and applies rules and validations to them.
func NewDefault ¶
NewDefault creates a default Analyzer instance with all default Rules and configuration. To add custom rules, the easiest way is use the Builder.
type Batch ¶
Batch executes a set of rules a specific number of times. When this number of times is reached, the actual node and ErrMaxAnalysisIters is returned.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder provides an easy way to generate Analyzer with custom rules and options.
func NewBuilder ¶
NewBuilder creates a new Builder from a specific catalog. This builder allow us add custom Rules and modify some internal properties.
func (*Builder) AddPostAnalyzeRule ¶
AddPostAnalyzeRule adds a new rule to the analyzer after standard analyzer rules.
func (*Builder) AddPostValidationRule ¶
AddPostValidationRule adds a new rule to the analyzer after standard validation rules.
func (*Builder) AddPreAnalyzeRule ¶
AddPreAnalyzeRule adds a new rule to the analyze before the standard analyzer rules.
func (*Builder) AddPreValidationRule ¶
AddPreValidationRule adds a new rule to the analyzer before standard validation rules.
func (*Builder) WithParallelism ¶
WithParallelism sets the parallelism level on the analyzer.
Source Files ¶
- aggregations.go
- analyzer.go
- assign_catalog.go
- assign_indexes.go
- batch.go
- filters.go
- optimization_rules.go
- parallelize.go
- process.go
- prune_columns.go
- pushdown.go
- resolve_columns.go
- resolve_database.go
- resolve_functions.go
- resolve_natural_joins.go
- resolve_orderby.go
- resolve_stars.go
- resolve_subqueries.go
- resolve_tables.go
- rules.go
- validation_rules.go
- warnings.go