mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
* implemented distinct
* implemented distinct
* uses first cut of a buffer pool, and extendible hashing with thresholded spill to disk
* tests
* cleaned up some stuff around query plan output to make developing tooling easier
* added optimization to call PQL Distinct()
* fixed test
* fix for passing wrong index name in orchestrator
* back out change to DistinctTimestamp
* fix other instance of wrong table name being passed
* use full index name instead of abbreviated one for translation. sigh.
* removed some unused code
Co-authored-by: Matthew Jaffee <jaffee@pilosa.com>
(cherry picked from commit f030d58d95)
111 lines
2.6 KiB
Go
111 lines
2.6 KiB
Go
// Copyright 2022 Molecula Corp. All rights reserved.
|
|
|
|
package planner
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/featurebasedb/featurebase/v3/sql3/planner/types"
|
|
)
|
|
|
|
// PlanOpPQLMultiAggregate plan operator handles executing multiple 'sibling' pql aggregate queries
|
|
type PlanOpPQLMultiAggregate struct {
|
|
planner *ExecutionPlanner
|
|
operators []*PlanOpPQLAggregate
|
|
warnings []string
|
|
}
|
|
|
|
func NewPlanOpPQLMultiAggregate(p *ExecutionPlanner, operators []*PlanOpPQLAggregate) *PlanOpPQLMultiAggregate {
|
|
return &PlanOpPQLMultiAggregate{
|
|
planner: p,
|
|
operators: operators,
|
|
warnings: make([]string, 0),
|
|
}
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) Plan() map[string]interface{} {
|
|
result := make(map[string]interface{})
|
|
result["_op"] = fmt.Sprintf("%T", p)
|
|
result["_schema"] = p.Schema().Plan()
|
|
ps := make([]interface{}, 0)
|
|
for _, e := range p.operators {
|
|
ps = append(ps, e.Plan())
|
|
}
|
|
result["operators"] = ps
|
|
return result
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) String() string {
|
|
return ""
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) AddWarning(warning string) {
|
|
p.warnings = append(p.warnings, warning)
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) Warnings() []string {
|
|
return p.warnings
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) Schema() types.Schema {
|
|
result := make(types.Schema, len(p.operators))
|
|
for idx, aggOp := range p.operators {
|
|
s := &types.PlannerColumn{
|
|
ColumnName: aggOp.aggregate.String(),
|
|
RelationName: "",
|
|
Type: aggOp.aggregate.Type(),
|
|
}
|
|
result[idx] = s
|
|
}
|
|
return result
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) Children() []types.PlanOperator {
|
|
return []types.PlanOperator{}
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) Iterator(ctx context.Context, row types.Row) (types.RowIterator, error) {
|
|
iterators := make([]types.RowIterator, 0)
|
|
|
|
for _, op := range p.operators {
|
|
iter, err := op.Iterator(ctx, row)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
iterators = append(iterators, iter)
|
|
}
|
|
|
|
return &pqlMultiAggregateRowIter{
|
|
planner: p.planner,
|
|
iterators: iterators,
|
|
}, nil
|
|
}
|
|
|
|
func (p *PlanOpPQLMultiAggregate) WithChildren(children ...types.PlanOperator) (types.PlanOperator, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type pqlMultiAggregateRowIter struct {
|
|
planner *ExecutionPlanner
|
|
iterators []types.RowIterator
|
|
doneLatch bool
|
|
}
|
|
|
|
var _ types.RowIterator = (*pqlMultiAggregateRowIter)(nil)
|
|
|
|
func (i *pqlMultiAggregateRowIter) Next(ctx context.Context) (types.Row, error) {
|
|
if !i.doneLatch {
|
|
var row = make(types.Row, len(i.iterators))
|
|
for idx, iter := range i.iterators {
|
|
irow, err := iter.Next(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
row[idx] = irow[0]
|
|
}
|
|
i.doneLatch = true
|
|
return row, nil
|
|
}
|
|
return nil, types.ErrNoMoreRows
|
|
}
|