Documentation
¶
Index ¶
- Variables
- func Format(plan LogicalNode) string
- func Traverse(node Traversable, callback func(node Traversable) bool)
- type Aggregate
- type AggregateFunctionCall
- func (s *AggregateFunctionCall) Accept(v Visitor) any
- func (a *AggregateFunctionCall) Children() []Traversable
- func (a *AggregateFunctionCall) Equal(other Traversable) bool
- func (a *AggregateFunctionCall) Field() *Field
- func (a *AggregateFunctionCall) Plans() []Plan
- func (a *AggregateFunctionCall) String() string
- type AliasExpr
- type AnalyzedPlan
- type ArithmeticOp
- type ArithmeticOperator
- type ArrayAccess
- type ArrayConstructor
- type Assignment
- type CartesianProduct
- type Case
- type Collate
- type CollationType
- type ColumnRef
- type ComparisonOp
- type ComparisonOperator
- type ConflictDoNothing
- type ConflictResolution
- type ConflictUpdate
- type Delete
- type Distinct
- type EmptyScan
- type ExprRef
- type Expression
- type Field
- type FieldAccess
- type Filter
- type GetObjectFunc
- type GetTableFunc
- type GetVarTypeFunc
- type IdentifiedExpr
- type Index
- type IndexColumnConstraint
- type IndexConstraintType
- type IndexNamed
- type Insert
- type IsActionFunc
- type IsIn
- type Join
- type JoinType
- type Limit
- type Literal
- type LogicalNode
- type LogicalOp
- type LogicalOperator
- type Plan
- type ProcedureScanSource
- func (s *ProcedureScanSource) Accept(v Visitor) any
- func (f *ProcedureScanSource) Children() []Traversable
- func (f *ProcedureScanSource) Equal(other Traversable) bool
- func (f *ProcedureScanSource) FormatScan() string
- func (f *ProcedureScanSource) Plans() []Plan
- func (f *ProcedureScanSource) Relation() *Relation
- type Project
- type QuerySection
- type Relation
- type Return
- type RewriteConfig
- type ScalarFunctionCall
- type Scan
- type ScanSource
- type SetOperation
- type SetOperationType
- type Sort
- type SortExpression
- type Subplan
- type SubplanType
- type Subquery
- type SubqueryExpr
- type TableScanSource
- type TableSourceType
- type TopLevelPlan
- type Traversable
- type Tuples
- type TypeCast
- type UnaryOp
- type UnaryOperator
- type Update
- type Variable
- type Visitor
- type Window
- type WindowFunction
Constants ¶
This section is empty.
Variables ¶
var ( ErrIllegalAggregate = errors.New("illegal aggregate") ErrIllegalWindowFunction = errors.New("illegal window function") ErrColumnNotFound = errors.New("column not found or cannot be referenced in this part of the query") ErrUpdateOrDeleteWithoutWhere = errors.New("UPDATE and DELETE statements with a FROM table require a WHERE clause") ErrUnknownTable = errors.New("unknown table") ErrSetIncompatibleSchemas = errors.New("incompatible schemas in COMPOUND operation") ErrNotNullableColumn = errors.New("column is not nullable") ErrIllegalConflictArbiter = errors.New("illegal conflict arbiter") ErrAmbiguousColumn = errors.New("ambiguous column") ErrWindowAlreadyDefined = errors.New("window already defined") ErrInvalidWindowFunction = errors.New("invalid window function") ErrWindowNotDefined = errors.New("window not defined") ErrFunctionDoesNotExist = errors.New("function does not exist") ErrActionInSQLStmt = errors.New("actions cannot be used in SQL statements") ErrUntypedEmptyArray = errors.New("cannot detect type for empty array") )
Functions ¶
func Format ¶
func Format(plan LogicalNode) string
func Traverse ¶
func Traverse(node Traversable, callback func(node Traversable) bool)
Traverse traverses a logical plan in preorder. It will call the callback function for each node in the plan. If the callback function returns false, the traversal will not continue to the children of the node.
Types ¶
type Aggregate ¶
type Aggregate struct {
// GroupingExpressions are the expressions used
// in the GROUP BY clause.
GroupingExpressions []Expression
// AggregateExpressions are the expressions used
// in the SELECT clause (e.g. SUM(x), COUNT(y)).
AggregateExpressions []*IdentifiedExpr
// Child is the input to the aggregation
// (e.g. a Project node).
Child Plan
// contains filtered or unexported fields
}
func (*Aggregate) Children ¶
func (a *Aggregate) Children() []Traversable
func (*Aggregate) Equal ¶
func (a *Aggregate) Equal(other Traversable) bool
type AggregateFunctionCall ¶
type AggregateFunctionCall struct {
FunctionName string
Args []Expression
Star bool
Distinct bool
// contains filtered or unexported fields
}
func (*AggregateFunctionCall) Accept ¶
func (s *AggregateFunctionCall) Accept(v Visitor) any
func (*AggregateFunctionCall) Children ¶
func (a *AggregateFunctionCall) Children() []Traversable
func (*AggregateFunctionCall) Equal ¶
func (a *AggregateFunctionCall) Equal(other Traversable) bool
func (*AggregateFunctionCall) Field ¶
func (a *AggregateFunctionCall) Field() *Field
func (*AggregateFunctionCall) Plans ¶
func (a *AggregateFunctionCall) Plans() []Plan
func (*AggregateFunctionCall) String ¶
func (a *AggregateFunctionCall) String() string
type AliasExpr ¶
type AliasExpr struct {
Expr Expression
Alias string
}
func (*AliasExpr) Children ¶
func (a *AliasExpr) Children() []Traversable
func (*AliasExpr) Equal ¶
func (a *AliasExpr) Equal(other Traversable) bool
type AnalyzedPlan ¶
type AnalyzedPlan struct {
// Plan is the plan of the query.
Plan Plan
// CTEs are plans for the common table expressions in the query.
// They are in the order that they were defined.
CTEs []*Subplan
}
AnalyzedPlan is the full result of a logical plan that has been analyzed.
func CreateLogicalPlan ¶
func CreateLogicalPlan(statement *parse.SQLStatement, tables GetTableFunc, vars GetVarTypeFunc, objects GetObjectFunc, isAction IsActionFunc, applyDefaultOrdering bool, defaultNamespace string, ) (analyzed *AnalyzedPlan, err error)
CreateLogicalPlan creates a logical plan from a SQL statement. If applyDefaultOrdering is true, it will rewrite the query to apply default ordering. Default ordering will modify the passed query. If defaultNamespace is not empty, it will be used as the default namespace for all tables.
func (*AnalyzedPlan) Format ¶
func (a *AnalyzedPlan) Format() string
Format formats the plan into a human-readable string.
type ArithmeticOp ¶
type ArithmeticOp struct {
Left Expression
Right Expression
Op ArithmeticOperator
}
func (*ArithmeticOp) Accept ¶
func (s *ArithmeticOp) Accept(v Visitor) any
func (*ArithmeticOp) Children ¶
func (a *ArithmeticOp) Children() []Traversable
func (*ArithmeticOp) Equal ¶
func (a *ArithmeticOp) Equal(other Traversable) bool
func (*ArithmeticOp) Field ¶
func (a *ArithmeticOp) Field() *Field
func (*ArithmeticOp) Plans ¶
func (a *ArithmeticOp) Plans() []Plan
func (*ArithmeticOp) String ¶
func (a *ArithmeticOp) String() string
type ArithmeticOperator ¶
type ArithmeticOperator uint8
const ( Add ArithmeticOperator = iota Subtract Multiply Divide Modulo Concat )
type ArrayAccess ¶
type ArrayAccess struct {
Array Expression
Index Expression
}
func (*ArrayAccess) Accept ¶
func (s *ArrayAccess) Accept(v Visitor) any
func (*ArrayAccess) Children ¶
func (a *ArrayAccess) Children() []Traversable
func (*ArrayAccess) Equal ¶
func (a *ArrayAccess) Equal(other Traversable) bool
func (*ArrayAccess) Field ¶
func (a *ArrayAccess) Field() *Field
func (*ArrayAccess) Plans ¶
func (a *ArrayAccess) Plans() []Plan
func (*ArrayAccess) String ¶
func (a *ArrayAccess) String() string
type ArrayConstructor ¶
type ArrayConstructor struct {
Elements []Expression
}
func (*ArrayConstructor) Accept ¶
func (s *ArrayConstructor) Accept(v Visitor) any
func (*ArrayConstructor) Children ¶
func (a *ArrayConstructor) Children() []Traversable
func (*ArrayConstructor) Equal ¶
func (a *ArrayConstructor) Equal(other Traversable) bool
func (*ArrayConstructor) Field ¶
func (a *ArrayConstructor) Field() *Field
func (*ArrayConstructor) Plans ¶
func (a *ArrayConstructor) Plans() []Plan
func (*ArrayConstructor) String ¶
func (a *ArrayConstructor) String() string
type Assignment ¶
type Assignment struct {
// Column is the column to update.
Column string
// Value is the value to update the column to.
Value Expression
}
Assignment is a struct that represents an assignment in an update statement.
type CartesianProduct ¶
CartesianProduct is a logical plan node that represents a cartesian product between two relations. This is used in joins and set operations. Kwil doesn't actually allow cartesian products to be executed, but it is a necessary intermediate step for planning complex updates and deletes.
func (*CartesianProduct) Accept ¶
func (s *CartesianProduct) Accept(v Visitor) any
func (*CartesianProduct) Children ¶
func (c *CartesianProduct) Children() []Traversable
func (*CartesianProduct) Equal ¶
func (c *CartesianProduct) Equal(other Traversable) bool
func (*CartesianProduct) Plans ¶
func (c *CartesianProduct) Plans() []Plan
func (*CartesianProduct) Relation ¶
func (c *CartesianProduct) Relation() *Relation
func (*CartesianProduct) String ¶
func (c *CartesianProduct) String() string
type Case ¶
type Case struct {
// Value is the value that is being compared.
// Can be nil if there is no value to compare.
Value Expression
// WhenClauses are the list of when/then pairs.
// The first element of each pair is the condition,
// which must match the data type of Value. If Value
// is nil, the condition must be a boolean.
WhenClauses [][2]Expression
// Else is the else clause. Can be nil.
Else Expression
}
func (*Case) Children ¶
func (c *Case) Children() []Traversable
func (*Case) Equal ¶
func (c *Case) Equal(other Traversable) bool
type Collate ¶
type Collate struct {
Expr Expression
Collation CollationType
}
func (*Collate) Children ¶
func (c *Collate) Children() []Traversable
func (*Collate) Equal ¶
func (c *Collate) Equal(other Traversable) bool
type CollationType ¶
type CollationType uint8
const ( // NoCaseCollation is a collation that is case-insensitive. NoCaseCollation CollationType = iota )
func (CollationType) String ¶
func (c CollationType) String() string
type ColumnRef ¶
type ColumnRef struct {
// Parent relation name, can be empty.
// If not specified by user, it will be qualified
// during the planning phase.
Parent string
ColumnName string
// contains filtered or unexported fields
}
Column reference
func (*ColumnRef) Children ¶
func (c *ColumnRef) Children() []Traversable
func (*ColumnRef) Equal ¶
func (c *ColumnRef) Equal(other Traversable) bool
type ComparisonOp ¶
type ComparisonOp struct {
Left Expression
Right Expression
Op ComparisonOperator
}
func (*ComparisonOp) Accept ¶
func (s *ComparisonOp) Accept(v Visitor) any
func (*ComparisonOp) Children ¶
func (c *ComparisonOp) Children() []Traversable
func (*ComparisonOp) Equal ¶
func (c *ComparisonOp) Equal(other Traversable) bool
func (*ComparisonOp) Field ¶
func (c *ComparisonOp) Field() *Field
func (*ComparisonOp) Plans ¶
func (c *ComparisonOp) Plans() []Plan
func (*ComparisonOp) String ¶
func (c *ComparisonOp) String() string
type ComparisonOperator ¶
type ComparisonOperator uint8
const ( // operators can have 3 types of classifications: // - sargable // - not sargable // - rarely sarable // https://en.wikipedia.org/wiki/Sargable // for the purposes of our planner, we will treat rarely // sargable as not sargable Equal ComparisonOperator = iota // sargable LessThan // sargable GreaterThan // sargable // IS and IS NOT are rarely sargable because they can only be used // with NULL values or BOOLEAN values Is // rarely sargable IsDistinctFrom // not sargable Like // not sargable ILike // not sargable )
func (ComparisonOperator) String ¶
func (c ComparisonOperator) String() string
type ConflictDoNothing ¶
type ConflictDoNothing struct {
// ArbiterIndex is the index to use to determine if there is a conflict.
// If/when Kwil supports partial indexes, we will turn this into a list
// of indexes. Can be nil when DO NOTHING is used.
ArbiterIndex Index
// contains filtered or unexported fields
}
ConflictDoNothing is a struct that represents the resolution of a conflict using DO NOTHING.
func (*ConflictDoNothing) Accept ¶
func (s *ConflictDoNothing) Accept(v Visitor) any
func (*ConflictDoNothing) Children ¶
func (c *ConflictDoNothing) Children() []Traversable
func (*ConflictDoNothing) Equal ¶
func (c *ConflictDoNothing) Equal(other Traversable) bool
func (*ConflictDoNothing) Plans ¶
func (c *ConflictDoNothing) Plans() []Plan
func (*ConflictDoNothing) Relation ¶
func (c *ConflictDoNothing) Relation() *Relation
func (*ConflictDoNothing) String ¶
func (c *ConflictDoNothing) String() string
type ConflictResolution ¶
type ConflictResolution interface {
Plan
// contains filtered or unexported methods
}
type ConflictUpdate ¶
type ConflictUpdate struct {
// ArbiterIndex is the index to use to determine if there is a conflict.
// If/when Kwil supports partial indexes, we will turn this into a list
// of indexes. See: https://github.com/cockroachdb/cockroach/issues/53170
// Cannot be nil when DO UPDATE is used.
ArbiterIndex Index
// Assignments are the expressions to update if there is a conflict.
// Cannot be nil.
Assignments []*Assignment
// ConflictFilter is a predicate that allows us to selectively
// update or raise an error if there is a conflict.
// Can be nil.
ConflictFilter Expression
// contains filtered or unexported fields
}
ConflictUpdate is a struct that represents the resolution of a conflict using DO UPDATE SET.
func (*ConflictUpdate) Accept ¶
func (s *ConflictUpdate) Accept(v Visitor) any
func (*ConflictUpdate) Children ¶
func (c *ConflictUpdate) Children() []Traversable
func (*ConflictUpdate) Equal ¶
func (c *ConflictUpdate) Equal(other Traversable) bool
func (*ConflictUpdate) Plans ¶
func (c *ConflictUpdate) Plans() []Plan
func (*ConflictUpdate) Relation ¶
func (c *ConflictUpdate) Relation() *Relation
func (*ConflictUpdate) String ¶
func (c *ConflictUpdate) String() string
type Delete ¶
type Delete struct {
// Child is the input to the delete.
Child Plan
// Table is the target table name.
// It will always be the table name and not an alias.
Table string
// contains filtered or unexported fields
}
Delete is a node that plans a delete operation.
func (*Delete) Children ¶
func (d *Delete) Children() []Traversable
func (*Delete) Equal ¶
func (d *Delete) Equal(t Traversable) bool
type Distinct ¶
type Distinct struct {
Child Plan
// contains filtered or unexported fields
}
func (*Distinct) Children ¶
func (d *Distinct) Children() []Traversable
func (*Distinct) Equal ¶
func (d *Distinct) Equal(other Traversable) bool
type EmptyScan ¶
type EmptyScan struct {
// contains filtered or unexported fields
}
func (*EmptyScan) Children ¶
func (n *EmptyScan) Children() []Traversable
func (*EmptyScan) Equal ¶
func (n *EmptyScan) Equal(other Traversable) bool
type ExprRef ¶
type ExprRef struct {
// Identified is the expression that is being referenced.
// It is a pointer to the actual expression.
Identified *IdentifiedExpr
}
ExprRef is a reference to an expression in the query. It is used when a part of the query is referenced in another. For example, SELECT SUM(a) FROM table1 GROUP BY a HAVING SUM(a) > 10, both SUM(a) expressions are the same, and will reference the same ExprRef (which would actually occur in the Aggregate node).
func (*ExprRef) Children ¶
func (e *ExprRef) Children() []Traversable
func (*ExprRef) Equal ¶
func (e *ExprRef) Equal(other Traversable) bool
type Expression ¶
type Expression interface {
LogicalNode
Field() *Field
}
type Field ¶
type Field struct {
Parent string // the parent relation name
Name string // the field name
// ReferenceID is the ID with which this field can be referenced.
// It can be empty if the field is not referenced.
ReferenceID string
// contains filtered or unexported fields
}
Field is a field in a relation. Parent and Name can be empty, if the expression is a constant. If this is the last expression in a relation, the "Name" field will be the name of the column in the result.
func (*Field) ResultString ¶
ResultString returns a string representation of the field that contains information as to how the field will be represented as a user-facing column in the result.
type FieldAccess ¶
type FieldAccess struct {
Object Expression
Key string
}
func (*FieldAccess) Accept ¶
func (s *FieldAccess) Accept(v Visitor) any
func (*FieldAccess) Children ¶
func (f *FieldAccess) Children() []Traversable
func (*FieldAccess) Equal ¶
func (f *FieldAccess) Equal(other Traversable) bool
func (*FieldAccess) Field ¶
func (f *FieldAccess) Field() *Field
func (*FieldAccess) Plans ¶
func (f *FieldAccess) Plans() []Plan
func (*FieldAccess) String ¶
func (f *FieldAccess) String() string
type Filter ¶
type Filter struct {
Condition Expression
Child Plan
// contains filtered or unexported fields
}
func (*Filter) Children ¶
func (f *Filter) Children() []Traversable
func (*Filter) Equal ¶
func (f *Filter) Equal(other Traversable) bool
type GetObjectFunc ¶
GetObjectFieldTypeFunc is a function that gets the type of a field in an object.
type GetTableFunc ¶
GetTableFunc is a function that gets a table by name. It can also be given a namespace to search in. If no namespace is given (passed as ""), it will search in the default namespace.
type GetVarTypeFunc ¶
GetVarTypeFunc is a function that gets the type of a variable.
type IdentifiedExpr ¶
type IdentifiedExpr struct {
// ID is the unique identifier for the expression.
ID string
// Expr is the expression that is being identified.
Expr Expression
}
IdentifiedExpr is an expression that can be referenced.
func (*IdentifiedExpr) Accept ¶
func (s *IdentifiedExpr) Accept(v Visitor) any
func (*IdentifiedExpr) Children ¶
func (i *IdentifiedExpr) Children() []Traversable
func (*IdentifiedExpr) Equal ¶
func (i *IdentifiedExpr) Equal(other Traversable) bool
func (*IdentifiedExpr) Field ¶
func (i *IdentifiedExpr) Field() *Field
func (*IdentifiedExpr) Plans ¶
func (i *IdentifiedExpr) Plans() []Plan
func (*IdentifiedExpr) String ¶
func (i *IdentifiedExpr) String() string
type Index ¶
Index is an interface that represents an index. Since Kwil's internal catalog does not individually name all indexes (e.g. UNIQUE and PRIMARY column constraints), we use this interface to represent an index.
type IndexColumnConstraint ¶
type IndexColumnConstraint struct {
// Table is the physical table that the index is on.
Table string
// Column is the column that the constraint is on.
Column string
// ConstraintType is the type of constraint that the index is.
ConstraintType IndexConstraintType
}
func (*IndexColumnConstraint) Equal ¶
func (i *IndexColumnConstraint) Equal(other Index) bool
func (*IndexColumnConstraint) String ¶
func (i *IndexColumnConstraint) String() string
type IndexConstraintType ¶
type IndexConstraintType uint8
const ( UniqueConstraintIndex IndexConstraintType = iota PrimaryKeyConstraintIndex )
func (IndexConstraintType) String ¶
func (i IndexConstraintType) String() string
type IndexNamed ¶
type IndexNamed struct {
// Name is the name of the index.
Name string
}
IndexNamed is any index that is specified explicitly and has a referenceable name.
func (*IndexNamed) Equal ¶
func (i *IndexNamed) Equal(other Index) bool
func (*IndexNamed) String ¶
func (i *IndexNamed) String() string
type Insert ¶
type Insert struct {
// Table is the physical table to insert into.
Table string
// ReferencedAs is how the table is referenced in the query.
// It is either a user-defined reference or the table name.
ReferencedAs string
// Columns are the columns to insert into.
Columns []*Field
// InsertionValues are the values to insert.
// These can be either values specified using VALUES or a subquery.
InsertionValues Plan
// ConflictResolution is the conflict resolution to use if there is a conflict.
ConflictResolution ConflictResolution
// contains filtered or unexported fields
}
Insert is a node that plans an insert operation.
func (*Insert) Children ¶
func (i *Insert) Children() []Traversable
func (*Insert) Equal ¶
func (i *Insert) Equal(t Traversable) bool
type IsActionFunc ¶
IsActionFunc returns true if the passed function is an action
type IsIn ¶
type IsIn struct {
// Left is the expression that is being compared.
Left Expression
Expressions []Expression
Subquery *SubqueryExpr
}
func (*IsIn) Children ¶
func (i *IsIn) Children() []Traversable
func (*IsIn) Equal ¶
func (i *IsIn) Equal(other Traversable) bool
type Join ¶
type Join struct {
Left Plan
Right Plan
JoinType JoinType
Condition Expression
// contains filtered or unexported fields
}
func (*Join) Children ¶
func (j *Join) Children() []Traversable
func (*Join) Equal ¶
func (j *Join) Equal(other Traversable) bool
type Limit ¶
type Limit struct {
Child Plan
Limit Expression
Offset Expression
// contains filtered or unexported fields
}
func (*Limit) Children ¶
func (l *Limit) Children() []Traversable
func (*Limit) Equal ¶
func (l *Limit) Equal(other Traversable) bool
type Literal ¶
Literal value
func (*Literal) Children ¶
func (l *Literal) Children() []Traversable
func (*Literal) Equal ¶
func (l *Literal) Equal(other Traversable) bool
type LogicalNode ¶
type LogicalNode interface {
fmt.Stringer
Traversable
}
func Rewrite ¶
func Rewrite(node LogicalNode, cfg *RewriteConfig) (lp LogicalNode, err error)
Rewrite rewrites a logical plan using the given configuration. It returns the rewritten plan, but it also modifies the original plan in place. The returned plan should always be used.
type LogicalOp ¶
type LogicalOp struct {
Left Expression
Right Expression
Op LogicalOperator
}
func (*LogicalOp) Children ¶
func (l *LogicalOp) Children() []Traversable
func (*LogicalOp) Equal ¶
func (l *LogicalOp) Equal(other Traversable) bool
type Plan ¶
type Plan interface {
LogicalNode
Relation() *Relation
// contains filtered or unexported methods
}
type ProcedureScanSource ¶
type ProcedureScanSource struct {
// ProcedureName is the name of the procedure being targeted.
ProcedureName string
// Args are the base arguments to the procedure.
Args []Expression
// ContextualArgs are the arguments that are passed in if
// the procedure is a foreign procedure.
ContextualArgs []Expression
// IsForeign is true if the function is a foreign procedure.
IsForeign bool
// contains filtered or unexported fields
}
ProcedureScanSource represents a scan of a function. It can call either a local procedure or foreign procedure that returns a table.
func (*ProcedureScanSource) Accept ¶
func (s *ProcedureScanSource) Accept(v Visitor) any
func (*ProcedureScanSource) Children ¶
func (f *ProcedureScanSource) Children() []Traversable
func (*ProcedureScanSource) Equal ¶
func (f *ProcedureScanSource) Equal(other Traversable) bool
func (*ProcedureScanSource) FormatScan ¶
func (f *ProcedureScanSource) FormatScan() string
func (*ProcedureScanSource) Plans ¶
func (f *ProcedureScanSource) Plans() []Plan
func (*ProcedureScanSource) Relation ¶
func (f *ProcedureScanSource) Relation() *Relation
type Project ¶
type Project struct {
// Expressions are the expressions that are projected.
Expressions []Expression
Child Plan
// contains filtered or unexported fields
}
func (*Project) Children ¶
func (p *Project) Children() []Traversable
func (*Project) Equal ¶
func (p *Project) Equal(other Traversable) bool
type QuerySection ¶
type QuerySection string
type Relation ¶
type Relation struct {
Fields []*Field
}
Relation is the current relation in the query plan.
func (*Relation) ColumnsByParent ¶
func (*Relation) FindReference ¶
FindReference finds a field by its reference ID. If there are many fields with the same reference ID, or no fields with the reference ID, an error is returned.
type Return ¶
type Return struct {
// Fields are the fields to return.
Fields []*Field
// Child is the input to the return.
Child Plan
// contains filtered or unexported fields
}
Return is a node that plans a return operation. It specifies columns to return from a query. This is similar to a projection, however it cannot be optimized using pushdowns, since it is at the top level (and therefore user requested).
func (*Return) Children ¶
func (r *Return) Children() []Traversable
func (*Return) Equal ¶
func (r *Return) Equal(t Traversable) bool
type RewriteConfig ¶
type RewriteConfig struct {
// ExprCallback is the function that will be called on each expression.
// It returns the new node, which will replace the old node,
// a boolean, which indicates whether the nodes children should be visited,
// and an error, which will be returned if an error occurs.
ExprCallback func(Expression) (Expression, bool, error)
// PlanCallback is the function that will be called on each plan
// It returns the new node, which will replace the old node,
// a boolean, which indicates whether the nodes children should be visited,
// and an error, which will be returned if an error occurs.
PlanCallback func(Plan) (Plan, bool, error)
// ScanSourceCallback is the function that will be called on each scan source
// It returns the new node, which will replace the old node,
// a boolean, which indicates whether the nodes children should be visited,
// and an error, which will be returned if an error occurs.
ScanSourceCallback func(ScanSource) (ScanSource, bool, error)
}
RewriteConfig is a configuration for the rewriter.
type ScalarFunctionCall ¶
type ScalarFunctionCall struct {
FunctionName string
Args []Expression
// contains filtered or unexported fields
}
Function call
func (*ScalarFunctionCall) Accept ¶
func (s *ScalarFunctionCall) Accept(v Visitor) any
func (*ScalarFunctionCall) Children ¶
func (f *ScalarFunctionCall) Children() []Traversable
func (*ScalarFunctionCall) Equal ¶
func (f *ScalarFunctionCall) Equal(other Traversable) bool
func (*ScalarFunctionCall) Field ¶
func (f *ScalarFunctionCall) Field() *Field
func (*ScalarFunctionCall) Plans ¶
func (f *ScalarFunctionCall) Plans() []Plan
func (*ScalarFunctionCall) String ¶
func (f *ScalarFunctionCall) String() string
type Scan ¶
type Scan struct {
Source ScanSource
// RelationName will always be set.
// If the scan is a table scan and no alias was specified,
// the RelationName will be the table name.
// All other scan types (functions and subqueries) require an alias.
RelationName string
// Filter holds the optional filter condition that can be
// pushed down to the scan operation. This allows filtering data
// during the scan, which can improve query performance by reducing
// the amount of data processed in subsequent operations.
// This field won't ever be set in the initial logical plan, but
// can be set during the optimization phase.
Filter Expression
// contains filtered or unexported fields
}
func (*Scan) Children ¶
func (s *Scan) Children() []Traversable
func (*Scan) Equal ¶
func (s *Scan) Equal(other Traversable) bool
type ScanSource ¶
type ScanSource interface {
Traversable
FormatScan() string
Relation() *Relation
}
ScanSource is a source of data that a Scan can be performed on. This is either a physical table, an action call that returns a table, or a subquery.
type SetOperation ¶
type SetOperation struct {
Left Plan
Right Plan
OpType SetOperationType
// contains filtered or unexported fields
}
func (*SetOperation) Children ¶
func (s *SetOperation) Children() []Traversable
func (*SetOperation) Equal ¶
func (s *SetOperation) Equal(other Traversable) bool
func (*SetOperation) Plans ¶
func (s *SetOperation) Plans() []Plan
func (*SetOperation) Relation ¶
func (s *SetOperation) Relation() *Relation
func (*SetOperation) String ¶
func (s *SetOperation) String() string
type SetOperationType ¶
type SetOperationType int
const ( Union SetOperationType = iota UnionAll Intersect Except )
func (SetOperationType) String ¶
func (s SetOperationType) String() string
type Sort ¶
type Sort struct {
SortExpressions []*SortExpression
Child Plan
// contains filtered or unexported fields
}
func (*Sort) Children ¶
func (s *Sort) Children() []Traversable
func (*Sort) Equal ¶
func (s *Sort) Equal(other Traversable) bool
type SortExpression ¶
type SortExpression struct {
Expr Expression
Ascending bool
NullsLast bool
}
func (*SortExpression) String ¶
func (s *SortExpression) String() string
type Subplan ¶
type Subplan struct {
Plan Plan
ID string
Type SubplanType
// contains filtered or unexported fields
}
func (*Subplan) Children ¶
func (s *Subplan) Children() []Traversable
func (*Subplan) Equal ¶
func (s *Subplan) Equal(other Traversable) bool
type SubplanType ¶
type SubplanType int
const ( SubplanTypeSubquery SubplanType = iota SubplanTypeCTE SubplanTypeRecursiveCTE )
func (SubplanType) String ¶
func (s SubplanType) String() string
type Subquery ¶
type Subquery struct {
// Plan is the logical plan for the subquery.
Plan *Subplan
// to the outer query. If empty, the subquery is uncorrelated.
Correlated []*Field
}
Subquery holds information for a subquery. It is a TableSource that can be used in a Scan, but also can be used within expressions. If ReturnsRelation is true, it is a TableSource. If false, it is a scalar subquery (used in expressions).
func (*Subquery) Children ¶
func (s *Subquery) Children() []Traversable
func (*Subquery) Equal ¶
func (s *Subquery) Equal(other Traversable) bool
func (*Subquery) FormatScan ¶
type SubqueryExpr ¶
type SubqueryExpr struct {
Query *Subquery
// If Exists is true, we are checking if the subquery returns any rows.
// Otherwise, the subquery will return a single value.
// If the query is a NOT EXISTS, a unary negation will wrap this expression.
Exists bool
}
func (*SubqueryExpr) Accept ¶
func (s *SubqueryExpr) Accept(v Visitor) any
func (*SubqueryExpr) Children ¶
func (s *SubqueryExpr) Children() []Traversable
func (*SubqueryExpr) Equal ¶
func (s *SubqueryExpr) Equal(other Traversable) bool
func (*SubqueryExpr) Field ¶
func (s *SubqueryExpr) Field() *Field
func (*SubqueryExpr) Plans ¶
func (s *SubqueryExpr) Plans() []Plan
func (*SubqueryExpr) String ¶
func (s *SubqueryExpr) String() string
type TableScanSource ¶
type TableScanSource struct {
// Namespace is the namespace of the table being scanned.
Namespace string
// TableName is the name of the table being scanned.
TableName string
Type TableSourceType
// contains filtered or unexported fields
}
TableScanSource represents a scan of a physical table or a CTE.
func (*TableScanSource) Accept ¶
func (s *TableScanSource) Accept(v Visitor) any
func (*TableScanSource) Children ¶
func (t *TableScanSource) Children() []Traversable
func (*TableScanSource) Equal ¶
func (t *TableScanSource) Equal(other Traversable) bool
func (*TableScanSource) FormatScan ¶
func (t *TableScanSource) FormatScan() string
func (*TableScanSource) Plans ¶
func (t *TableScanSource) Plans() []Plan
func (*TableScanSource) Relation ¶
func (t *TableScanSource) Relation() *Relation
type TableSourceType ¶
type TableSourceType int
const ( TableSourcePhysical TableSourceType = iota // physical table (default) TableSourceCTE // common table expression )
func (TableSourceType) String ¶
func (t TableSourceType) String() string
type TopLevelPlan ¶
type TopLevelPlan interface {
Plan
// contains filtered or unexported methods
}
TopLevelPlan is a logical plan that is at the top level of a query.
type Traversable ¶
type Traversable interface {
// Children returns the children of the node.
// These are all LogicalPlans and LogicalExprs that are
// referenced by the node.
Children() []Traversable
// Plans returns all the logical plans that are referenced
// by the node (or the nearest node that contains them).
Plans() []Plan
// Accept is used to traverse the node.
Accept(Visitor) any
}
Traversable is an interface for nodes that can be traversed.
type Tuples ¶
type Tuples struct {
Values [][]Expression
// contains filtered or unexported fields
}
Tuples is a list tuple being inserted into a table.
func (*Tuples) Children ¶
func (t *Tuples) Children() []Traversable
func (*Tuples) Equal ¶
func (t *Tuples) Equal(other Traversable) bool
type TypeCast ¶
type TypeCast struct {
Expr Expression
Type *types.DataType
}
func (*TypeCast) Children ¶
func (t *TypeCast) Children() []Traversable
func (*TypeCast) Equal ¶
func (t *TypeCast) Equal(other Traversable) bool
type UnaryOp ¶
type UnaryOp struct {
Expr Expression
Op UnaryOperator
}
func (*UnaryOp) Children ¶
func (u *UnaryOp) Children() []Traversable
func (*UnaryOp) Equal ¶
func (u *UnaryOp) Equal(other Traversable) bool
type UnaryOperator ¶
type UnaryOperator uint8
const ( Negate UnaryOperator = iota Not Positive )
func (UnaryOperator) String ¶
func (u UnaryOperator) String() string
type Update ¶
type Update struct {
// Child is the input to the update.
Child Plan
// Table is the target table name.
// It will always be the table name and not an alias.
Table string
// Assignments are the assignments to update.
Assignments []*Assignment
// contains filtered or unexported fields
}
Update is a node that plans an update operation.
func (*Update) Children ¶
func (u *Update) Children() []Traversable
func (*Update) Equal ¶
func (u *Update) Equal(t Traversable) bool
type Variable ¶
type Variable struct {
// name is something like $id, @caller, etc.
VarName string
// contains filtered or unexported fields
}
Variable reference
func (*Variable) Children ¶
func (v *Variable) Children() []Traversable
func (*Variable) Equal ¶
func (v *Variable) Equal(other Traversable) bool
type Visitor ¶
type Visitor interface {
VisitTableScanSource(*TableScanSource) any
VisitProcedureScanSource(*ProcedureScanSource) any
VisitSubquery(*Subquery) any
VisitEmptyScan(*EmptyScan) any
VisitScan(*Scan) any
VisitProject(*Project) any
VisitFilter(*Filter) any
VisitJoin(*Join) any
VisitSort(*Sort) any
VisitLimit(*Limit) any
VisitDistinct(*Distinct) any
VisitSetOperation(*SetOperation) any
VisitAggregate(*Aggregate) any
VisitWindow(*Window) any
VisitSubplan(*Subplan) any
VisitLiteral(*Literal) any
VisitVariable(*Variable) any
VisitColumnRef(*ColumnRef) any
VisitAggregateFunctionCall(*AggregateFunctionCall) any
VisitScalarFunctionCall(*ScalarFunctionCall) any
VisitArithmeticOp(*ArithmeticOp) any
VisitComparisonOp(*ComparisonOp) any
VisitLogicalOp(*LogicalOp) any
VisitUnaryOp(*UnaryOp) any
VisitTypeCast(*TypeCast) any
VisitAliasExpr(*AliasExpr) any
VisitArrayAccess(*ArrayAccess) any
VisitArrayConstructor(*ArrayConstructor) any
VisitFieldAccess(*FieldAccess) any
VisitSubqueryExpr(*SubqueryExpr) any
VisitCollate(*Collate) any
VisitIsIn(*IsIn) any
VisitCase(*Case) any
VisitExprRef(*ExprRef) any
VisitIdentifiedExpr(*IdentifiedExpr) any
VisitReturn(*Return) any
VisitCartesianProduct(*CartesianProduct) any
VisitUpdate(*Update) any
VisitDelete(*Delete) any
VisitInsert(*Insert) any
VisitConflictDoNothing(*ConflictDoNothing) any
VisitConflictUpdate(*ConflictUpdate) any
VisitTuples(*Tuples) any
VisitWindowFunction(*WindowFunction) any
}
type Window ¶
type Window struct {
// PartitionBy are the expressions used in the PARTITION BY clause.
PartitionBy []Expression
// OrderBy are the expressions used in the ORDER BY clause.
OrderBy []*SortExpression
// Functions are the window functions that are applied.
Functions []*IdentifiedExpr
// Frames are not yet supported, but when they are, they will
// be added here.
Child Plan
// contains filtered or unexported fields
}
Window is a logical plan node that represents a window function. It applies the window function to the input relation, and returns both the input relation and the window function result as a single relation.
func (*Window) Children ¶
func (w *Window) Children() []Traversable
type WindowFunction ¶
type WindowFunction struct {
// Name is the function being applied.
Name string
// Args are the arguments to the function.
Args []Expression
// Filter is the optional filter condition that can be applied to the function.
Filter Expression
// contains filtered or unexported fields
}
WindowFunction references a function being applied in a window.
func (*WindowFunction) Accept ¶
func (w *WindowFunction) Accept(v Visitor) any
func (*WindowFunction) Children ¶
func (w *WindowFunction) Children() []Traversable
func (*WindowFunction) Field ¶
func (w *WindowFunction) Field() *Field
func (*WindowFunction) Plans ¶
func (w *WindowFunction) Plans() []Plan
func (*WindowFunction) String ¶
func (w *WindowFunction) String() string