mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
* ID sql3 internal type representation is int64; fixed a bug that assumed incorrectly that it wasn't * refactored some names for clarity * primary: get nested loop joins to work; secondary get brute force aggregations for SUM working * added tests; removed debug output * review feedback * Update sql3/planner/compileselect.go review feedback Co-authored-by: Travis Turner <travis@pilosa.com> Co-authored-by: Travis Turner <travis@pilosa.com>
84 lines
1.9 KiB
Go
84 lines
1.9 KiB
Go
// Copyright 2022 Molecula Corp. All rights reserved.
|
|
|
|
package planner
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/molecula/featurebase/v3/sql3"
|
|
"github.com/molecula/featurebase/v3/sql3/planner/types"
|
|
)
|
|
|
|
// PlanOpRelAlias implements an alias for a relation
|
|
type PlanOpRelAlias struct {
|
|
ChildOp types.PlanOperator
|
|
alias string
|
|
warnings []string
|
|
}
|
|
|
|
func NewPlanOpRelAlias(alias string, child types.PlanOperator) *PlanOpRelAlias {
|
|
return &PlanOpRelAlias{
|
|
ChildOp: child,
|
|
alias: alias,
|
|
warnings: make([]string, 0),
|
|
}
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) Schema() types.Schema {
|
|
schema := p.ChildOp.Schema()
|
|
for _, s := range schema {
|
|
s.RelationName = p.alias
|
|
}
|
|
return schema
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) Iterator(ctx context.Context, row types.Row) (types.RowIterator, error) {
|
|
return p.ChildOp.Iterator(ctx, row)
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) Children() []types.PlanOperator {
|
|
return []types.PlanOperator{
|
|
p.ChildOp,
|
|
}
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) WithChildren(children ...types.PlanOperator) (types.PlanOperator, error) {
|
|
if len(children) != 1 {
|
|
return nil, sql3.NewErrInternalf("unexpected number of children '%d'", len(children))
|
|
}
|
|
return NewPlanOpRelAlias(p.alias, children[0]), nil
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) Plan() map[string]interface{} {
|
|
result := make(map[string]interface{})
|
|
result["_op"] = fmt.Sprintf("%T", p)
|
|
sc := make([]string, 0)
|
|
for _, e := range p.Schema() {
|
|
sc = append(sc, fmt.Sprintf("'%s', '%s', '%s'", e.ColumnName, e.RelationName, e.Type.TypeName()))
|
|
}
|
|
result["_schema"] = sc
|
|
|
|
result["alias"] = p.alias
|
|
result["child"] = p.ChildOp.Plan()
|
|
return result
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) String() string {
|
|
return ""
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) AddWarning(warning string) {
|
|
p.warnings = append(p.warnings, warning)
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) Warnings() []string {
|
|
var w []string
|
|
w = append(w, p.warnings...)
|
|
w = append(w, p.ChildOp.Warnings()...)
|
|
return w
|
|
}
|
|
|
|
func (p *PlanOpRelAlias) Name() string {
|
|
return p.alias
|
|
}
|