-
Notifications
You must be signed in to change notification settings - Fork 0
/
b_txn_executor.go
83 lines (68 loc) · 1.71 KB
/
b_txn_executor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package client
import (
batch "colexecdb/pkg/query_engine/c_batch"
parser "colexecdb/pkg/query_engine/d_parser"
process "colexecdb/pkg/query_engine/e_process"
catalog "colexecdb/pkg/query_engine/f_catalog"
logicalplan "colexecdb/pkg/query_engine/g_logical_plan"
physicalplan "colexecdb/pkg/query_engine/h_phyical_plan"
"context"
)
type txnExecutor struct {
s *sqlExecutor
ctx context.Context
}
func newTxnExecutor(
ctx context.Context,
s *sqlExecutor) (*txnExecutor, error) {
return &txnExecutor{s: s, ctx: ctx}, nil
}
func (exec *txnExecutor) Exec(sql string) (result Result, err error) {
// parse sql to ast statements
stmt, err := parser.Parse(sql)
if err != nil {
return Result{}, err
}
// get table def from catalog
tblDef := catalog.MockTableDef(2)
ctx := catalog.NewMockSchemaContext()
ctx.AppendTableDef("tbl1", tblDef)
// create logical plan (plan builder)
lp, err := logicalplan.BuildPlan(stmt, ctx)
if err != nil {
return Result{}, err
}
// TODO: implement later
lp.Optimize(nil)
// init physical_plan
p := process.New(exec.ctx)
pp := physicalplan.New(sql, exec.ctx, p, stmt)
// compiles query plan to physical plan
var batches []*batch.Batch
fillFn := func(a any, bat *batch.Batch) error {
if bat != nil {
rows, _ := bat.Dup()
batches = append(batches, rows)
}
return nil
}
err = pp.Compile(exec.ctx, lp, fillFn)
if err != nil {
return Result{}, err
}
// run the physical plan
runResult, err := pp.Run()
if err != nil {
return Result{}, err
}
// set output
result.Batches = batches
result.AffectedRows = runResult.AffectedRows
return
}
func (exec *txnExecutor) commit() error {
return nil
}
func (exec *txnExecutor) rollback(err error) error {
return nil
}