Permalink
Browse files

Add planner, though it's so simple.

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...
1 parent c9253e9 commit 6d51b012f9a1ae6807f428b550128086025e9c3a @umitanuki committed Feb 5, 2013
Showing with 67 additions and 0 deletions.
  1. +67 −0 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.