mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
// Copyright 2022 Molecula Corp. All rights reserved.
|
|
|
|
package planner
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/sql3/planner/types"
|
|
)
|
|
|
|
// PlanOpTop implements the TOP operator
|
|
type PlanOpTop struct {
|
|
ChildOp types.PlanOperator
|
|
expr types.PlanExpression
|
|
warnings []string
|
|
}
|
|
|
|
func NewPlanOpTop(expr types.PlanExpression, child types.PlanOperator) *PlanOpTop {
|
|
return &PlanOpTop{
|
|
ChildOp: child,
|
|
expr: expr,
|
|
}
|
|
}
|
|
|
|
func (p *PlanOpTop) Schema() types.Schema {
|
|
return p.ChildOp.Schema()
|
|
}
|
|
|
|
func (p *PlanOpTop) Iterator(ctx context.Context, row types.Row) (types.RowIterator, error) {
|
|
return p.ChildOp.Iterator(ctx, row)
|
|
}
|
|
|
|
func (p *PlanOpTop) Children() []types.PlanOperator {
|
|
return []types.PlanOperator{
|
|
p.ChildOp,
|
|
}
|
|
}
|
|
|
|
func (p *PlanOpTop) WithChildren(children ...types.PlanOperator) (types.PlanOperator, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (p *PlanOpTop) 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.Name, e.Table, e.Type.TypeName()))
|
|
}
|
|
result["_schema"] = sc
|
|
|
|
result["expr"] = p.expr
|
|
result["child"] = p.ChildOp.Plan()
|
|
return result
|
|
}
|
|
|
|
func (p *PlanOpTop) String() string {
|
|
return ""
|
|
}
|
|
|
|
func (p *PlanOpTop) AddWarning(warning string) {
|
|
p.warnings = append(p.warnings, warning)
|
|
}
|
|
|
|
func (p *PlanOpTop) Warnings() []string {
|
|
var w []string
|
|
w = append(w, p.warnings...)
|
|
w = append(w, p.ChildOp.Warnings()...)
|
|
return w
|
|
}
|