Skip to content

Commit

Permalink
Add a new method to the planner to allow distinguishing what type of …
Browse files Browse the repository at this point in the history
…plan it generates
  • Loading branch information
xllora committed Jul 8, 2017
1 parent 76d3cfe commit abce26b
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions bql/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type Executor interface {

// String returns a readable description of the execution plan.
String() string

// Type returns the type of plan used by the executor.
Type() string
}

// trace attempts to write a trace if a valid writer is provided. The
Expand All @@ -71,6 +74,11 @@ type createPlan struct {
tracer io.Writer
}

// Type returns the type of plan used by the executor.
func (p *createPlan) Type() string {
return "CREATE"
}

// Execute creates the indicated graphs.
func (p *createPlan) Execute(ctx context.Context) (*table.Table, error) {
t, err := table.New([]string{})
Expand Down Expand Up @@ -105,6 +113,11 @@ type dropPlan struct {
tracer io.Writer
}

// Type returns the type of plan used by the executor.
func (p *dropPlan) Type() string {
return "DROP"
}

// Execute drops the indicated graphs.
func (p *dropPlan) Execute(ctx context.Context) (*table.Table, error) {
t, err := table.New([]string{})
Expand Down Expand Up @@ -139,6 +152,11 @@ type insertPlan struct {
tracer io.Writer
}

// Type returns the type of plan used by the executor.
func (p *insertPlan) Type() string {
return "INSERT"
}

type updater func(storage.Graph, []*triple.Triple) error

func update(ctx context.Context, ts []*triple.Triple, gbs []string, store storage.Store, f updater) error {
Expand Down Expand Up @@ -212,6 +230,11 @@ type deletePlan struct {
tracer io.Writer
}

// Type returns the type of plan used by the executor.
func (p *deletePlan) Type() string {
return "DELETE"
}

// Execute deletes the provided data into the indicated graphs.
func (p *deletePlan) Execute(ctx context.Context) (*table.Table, error) {
t, err := table.New([]string{})
Expand Down Expand Up @@ -257,6 +280,11 @@ type queryPlan struct {
tracer io.Writer
}

// Type returns the type of plan used by the executor.
func (p *queryPlan) Type() string {
return "SELECT"
}

// newQueryPlan returns a new query plan ready to be executed.
func newQueryPlan(ctx context.Context, store storage.Store, stm *semantic.Statement, chanSize int, w io.Writer) (*queryPlan, error) {
bs := []string{}
Expand Down Expand Up @@ -799,6 +827,11 @@ type constructPlan struct {
queryPlan *queryPlan
}

// Type returns the type of plan used by the executor.
func (p *constructPlan) Type() string {
return "CONSTRUCT"
}

func (p *constructPlan) processConstructClause(cc *semantic.ConstructClause, tbl *table.Table, r table.Row) (*triple.Triple, error) {
var err error
sbj, prd, obj := cc.S, cc.P, cc.O
Expand Down

0 comments on commit abce26b

Please sign in to comment.