Skip to content

Commit

Permalink
Add planner, though it's so simple.
Browse files Browse the repository at this point in the history
One of the biggest concerns at the moment is about circlic imports.  We
(will) have tightly coupled sub-systems, and it makes convenient to separate
name spaces.  However, Go doesn't allow circlic imports, which may be hit
as the system gets complicated.
  • Loading branch information
umitanuki committed Feb 5, 2013
1 parent c9253e9 commit 6d51b01
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/bigpot/planner/planner.go
@@ -0,0 +1,67 @@
package planner

import (
"bigpot/parser"
// "bigpot/system"
)

type Node interface {
Visit(func(Node))
}

type PlanRoot struct {
CommandType parser.CommandType
Plan Node
RangeTables []*parser.RangeTblEntry
}

type Planner interface {
Plan(query parser.Query) *PlanRoot
}

type PlannerImpl struct {

}

type Plan struct {
LeftTree Node
RightTree Node
}

type SeqScan struct {
Plan
TargetList []*parser.TargetEntry
RangeTable *parser.RangeTblEntry
rel uint32
}

func (planner *PlannerImpl) Plan(query parser.Query) *PlanRoot {
root := PlanRoot{}

root.CommandType = query.CommandType

root.Plan = Node(makeSeqScan(query.TargetList, query.RangeTables[0]))
/* TODO: deep copy */
root.RangeTables = query.RangeTables

return &root
}

func makeSeqScan(tlist []*parser.TargetEntry, rte *parser.RangeTblEntry) *SeqScan {
scan := &SeqScan{
TargetList: tlist,
RangeTable: rte,
}

return scan
}

func (node *Plan) Visit(callBack func(node Node)) {
callBack(node)
if node.LeftTree != nil {
node.LeftTree.Visit(callBack)
}
if node.RightTree != nil {
node.RightTree.Visit(callBack)
}
}

0 comments on commit 6d51b01

Please sign in to comment.