forked from alpacahq/marketstore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
explainstatement.go
54 lines (46 loc) · 983 Bytes
/
explainstatement.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
package SQLParser
import (
"encoding/json"
"github.com/alpacahq/marketstore/utils/io"
)
type ExplainStatement struct {
ExecutableStatement
QueryText string
}
func NewExplainStatement(ctx *StatementParse, queryText string) (es *ExplainStatement) {
es = new(ExplainStatement)
es.QueryText = queryText
es.AddChild(ctx)
return es
}
func (es *ExplainStatement) Materialize() (cs *io.ColumnSeries, err error) {
result := Explain(es.GetChild(0))
cs = io.NewColumnSeries()
cs.AddColumn("explain-output", result)
return cs, nil
}
func (es *ExplainStatement) Explain() string {
if es != nil {
jsonStruct, _ := json.Marshal(*es)
return string(jsonStruct)
} else {
return "{}"
}
}
func (es *ExplainStatement) GetLeft() IMSTree {
if es.GetChildCount() == 0 {
return nil
} else {
return es.GetChild(0)
}
}
func (es *ExplainStatement) GetRight() IMSTree {
if es.GetChildCount() < 2 {
return nil
} else {
return es.GetChild(1)
}
}
/*
Utility Structures
*/