Refactor SQL planner to inside Server

This commit is contained in:
Ben Johnson 2021-08-16 13:12:16 -06:00
parent 9b8dc3d7e6
commit 5122c2decc
3 changed files with 10 additions and 13 deletions

View file

@ -100,7 +100,7 @@ func (p *Planner) planAggregateSelectStatement(ctx context.Context, stmt *sql2.S
}
func (p *Planner) planNonAggregateSelectStatement(ctx context.Context, stmt *sql2.SelectStatement) (_ StmtNode, err error) {
panic("TODO: Implement non-aggregate SELECT")
return nil, fmt.Errorf("cannot plan non-aggregate SELECT query")
}
type Stmt struct {

View file

@ -16,11 +16,9 @@ package pilosa_test
import (
"context"
"strings"
"testing"
"github.com/molecula/featurebase/v2"
"github.com/molecula/featurebase/v2/sql2"
"github.com/molecula/featurebase/v2/test"
)
@ -51,13 +49,7 @@ func TestPlanner_Count(t *testing.T) {
// Parse SQL into AST.
q := `SELECT COUNT(*) AS "count" FROM i`
st, err := sql2.NewParser(strings.NewReader(q)).ParseStatement()
if err != nil {
t.Fatal(err)
}
// Generate a prepared statement with the execution plan.
stmt, err := pilosa.NewPlanner(c.GetNode(0).Server.Executor()).PlanStatement(context.Background(), st)
stmt, err := c.GetNode(0).Server.PlanSQL(context.Background(), q)
if err != nil {
t.Fatal(err)
}

View file

@ -35,6 +35,7 @@ import (
pnet "github.com/molecula/featurebase/v2/net"
rbfcfg "github.com/molecula/featurebase/v2/rbf/cfg"
"github.com/molecula/featurebase/v2/roaring"
"github.com/molecula/featurebase/v2/sql2"
"github.com/molecula/featurebase/v2/stats"
"github.com/molecula/featurebase/v2/storage"
"github.com/molecula/featurebase/v2/topology"
@ -1346,9 +1347,13 @@ func (srv *Server) GetTransaction(ctx context.Context, id string, remote bool) (
return trns, nil
}
// Executor returns the executor attached to the server. For testing only.
func (s *Server) Executor() *executor {
return s.executor
// PlanSQL parses and prepares a SQL statement.
func (s *Server) PlanSQL(ctx context.Context, q string) (*Stmt, error) {
st, err := sql2.NewParser(strings.NewReader(q)).ParseStatement()
if err != nil {
return nil, err
}
return NewPlanner(s.executor).PlanStatement(ctx, st)
}
// countOpenFiles on operating systems that support lsof.