Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |