Permalink
Browse files

Add executor. SeqScan is the only node ATM...

  • Loading branch information...
1 parent 6d51b01 commit 031be58479793835caa4b2c42caaf22bf0e95397 @umitanuki committed Feb 5, 2013
Showing with 112 additions and 11 deletions.
  1. +60 −0 src/bigpot/executor/main.go
  2. +52 −0 src/bigpot/executor/seqscan.go
  3. +0 −11 src/bigpot/planner/planner.go
@@ -0,0 +1,60 @@
+package executor
+
+import "fmt"
+import "bigpot/access"
+import "bigpot/planner"
+
+type Executor interface {
+ Start()
+ Execute()
+ End()
+}
+
+type ExecutorImpl struct {
+ planRoot *planner.PlanRoot
+ TupleDesc *access.TupleDesc
+ execRoot Node
+}
+
+func NewExecutor(planRoot *planner.PlanRoot) *ExecutorImpl {
+ return &ExecutorImpl{
+ planRoot: planRoot,
+ }
+}
+
+func (exec *ExecutorImpl) initExecNode(node planner.Node) Node{
+ switch node.(type) {
+ case *planner.SeqScan:
+ scan := &SeqScan{}
+ scan.SeqScan = *(node.(*planner.SeqScan))
+ scan.executor = exec
+ scan.Init()
+ /* TODO: return Exec node */
+
+ return Node(scan)
+ }
+ panic("unknown node type")
+}
+
+func (exec *ExecutorImpl) Start() {
+ exec.execRoot = exec.initExecNode(exec.planRoot.Plan)
+}
+
+func (exec *ExecutorImpl) Execute() {
+ for {
+ tuple := exec.execRoot.Exec()
+ if tuple == nil {
+ break
+ }
+ /* TODO: Receiver */
+ for attnum, _ := range exec.TupleDesc.Attrs {
+ datum := tuple.Get(int32(attnum + 1))
+ fmt.Printf("%s ", datum.ToString())
+ }
+ fmt.Println("")
+ }
+}
+
+func (exec *ExecutorImpl) End() {
+ exec.execRoot.End()
+}
@@ -0,0 +1,52 @@
+package executor
+
+import "bigpot/access"
+import "bigpot/planner"
+
+type Node interface {
+ Init()
+ Exec() access.HeapTuple
+ End()
+}
+
+type Scan interface {
+ GetNext() access.HeapTuple
+}
+
+type SeqScan struct {
+ planner.SeqScan
+ relation *access.Relation
+ scan *access.RelationScan
+ executor Executor
+}
+
+func (scan *SeqScan) Init() {
+ var err error
+ scan.relation, err = access.HeapOpen(scan.RangeTable.RelId)
+ if err != nil {
+ /* TODO: do stuff */
+ }
+ emptykeys := []access.ScanKey{}
+ scan.scan, err = scan.relation.BeginScan(emptykeys)
+ if err != nil {
+ /* TODO: do stuff */
+ }
+}
+
+func (scan *SeqScan) Exec() access.HeapTuple {
+ /* TODO: projection */
+ return scan.GetNext()
+}
+
+func (scan *SeqScan) GetNext() access.HeapTuple {
+ if tuple, err := scan.scan.Next(); err == nil {
+ return tuple
+ }
+
+ return nil
+}
+
+func (scan *SeqScan) End() {
+ scan.scan.EndScan()
+ scan.relation.Close()
+}
@@ -6,7 +6,6 @@ import (
)
type Node interface {
- Visit(func(Node))
}
type PlanRoot struct {
@@ -55,13 +54,3 @@ func makeSeqScan(tlist []*parser.TargetEntry, rte *parser.RangeTblEntry) *SeqSca
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 031be58

Please sign in to comment.