featurebase/sql3/planner/opdroptable.go
pokeeffe-molecula e24978c4a7 And now....INNER JOIN! (#2230)
* 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>
2022-09-30 11:25:27 -07:00

89 lines
2 KiB
Go

// Copyright 2021 Molecula Corp. All rights reserved.
package planner
import (
"context"
"fmt"
pilosa "github.com/featurebasedb/featurebase/v3"
"github.com/featurebasedb/featurebase/v3/sql3/planner/types"
)
// PlanOpDropTable plan operator to drop a table.
type PlanOpDropTable struct {
planner *ExecutionPlanner
index *pilosa.IndexInfo
warnings []string
}
func NewPlanOpDropTable(p *ExecutionPlanner, index *pilosa.IndexInfo) *PlanOpDropTable {
return &PlanOpDropTable{
planner: p,
index: index,
warnings: make([]string, 0),
}
}
func (p *PlanOpDropTable) Plan() map[string]interface{} {
result := make(map[string]interface{})
result["_op"] = fmt.Sprintf("%T", p)
ps := make([]string, 0)
for _, e := range p.Schema() {
ps = append(ps, fmt.Sprintf("'%s', '%s', '%s'", e.ColumnName, e.RelationName, e.Type.TypeName()))
}
result["_schema"] = ps
result["tableName"] = p.index.Name
return result
}
func (p *PlanOpDropTable) String() string {
return ""
}
func (p *PlanOpDropTable) AddWarning(warning string) {
p.warnings = append(p.warnings, warning)
}
func (p *PlanOpDropTable) Warnings() []string {
return p.warnings
}
func (p *PlanOpDropTable) Schema() types.Schema {
return types.Schema{}
}
func (p *PlanOpDropTable) Children() []types.PlanOperator {
return []types.PlanOperator{}
}
func (p *PlanOpDropTable) Iterator(ctx context.Context, row types.Row) (types.RowIterator, error) {
return &dropTableRowIter{
planner: p.planner,
index: p.index,
}, nil
}
func (p *PlanOpDropTable) WithChildren(children ...types.PlanOperator) (types.PlanOperator, error) {
return nil, nil
}
type dropTableRowIter struct {
planner *ExecutionPlanner
index *pilosa.IndexInfo
}
var _ types.RowIterator = (*dropTableRowIter)(nil)
func (i *dropTableRowIter) Next(ctx context.Context) (types.Row, error) {
err := i.planner.checkAccess(ctx, i.index.Name, accessTypeDropObject)
if err != nil {
return nil, err
}
err = i.planner.schemaAPI.DeleteIndex(ctx, i.index.Name)
if err != nil {
return nil, err
}
return nil, types.ErrNoMoreRows
}