Skip to content

Commit

Permalink
feat: support for EXPLAIN statements (vesoft-inc#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaCage authored Mar 1, 2021
1 parent 1b7346e commit 75b9e5b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/prometheus/client_golang v1.9.0 // indirect
github.com/satori/go.uuid v1.2.0
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
github.com/vesoft-inc/nebula-go v1.1.1-0.20210107025320-8998c3593a59
github.com/vesoft-inc/nebula-go v1.1.1-0.20210225023903-c2ed782a5d6c
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20210105210732-16f7687f5001 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1
github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vesoft-inc/nebula-go v1.1.1-0.20210107025320-8998c3593a59 h1:CfNQMS/15aCwCBmG2V2uqnJyEosSEyYLr8EU4l177FE=
github.com/vesoft-inc/nebula-go v1.1.1-0.20210107025320-8998c3593a59/go.mod h1:wxhWNoVVP0+TLETNwaIa93H9tOECxlEv4XH+/do22Qk=
github.com/vesoft-inc/nebula-go v1.1.1-0.20210225023903-c2ed782a5d6c h1:rVe9Wejef5R3bLO94Anh/HPGGE8Mb8kCmWxikfqymHM=
github.com/vesoft-inc/nebula-go v1.1.1-0.20210225023903-c2ed782a5d6c/go.mod h1:wxhWNoVVP0+TLETNwaIa93H9tOECxlEv4XH+/do22Qk=
github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/gopher-lua v0.0.0-20171031051903-609c9cd26973/go.mod h1:aEV29XrmTYFr3CiRxZeGHpkvbwq+prZduBqMaascyCU=
Expand Down
28 changes: 28 additions & 0 deletions service/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,34 @@ func Execute(nsid string, gql string) (result ExecuteResult, err error) {
return result, response.Error
}
resp := response.Result
if resp.IsSetPlanDesc() {
format := string(resp.GetPlanDesc().GetFormat())
var rowValue = make(map[string]common.Any)
if format == "row" {
result.Headers = []string{"id", "name", "dependencies", "profiling data", "operator info"}
rows := resp.MakePlanByRow()
for i := 0; i < len(rows); i++ {
rowValue["id"] = rows[i][0]
rowValue["name"] = rows[i][1]
rowValue["dependencies"] = rows[i][2]
rowValue["profiling data"] = rows[i][3]
rowValue["operator info"] = rows[i][4]
result.Tables = append(result.Tables, rowValue)
}
return result, err
} else if format == "dot" {
result.Headers = append(result.Headers, "format")
rowValue["format"] = resp.MakeDotGraph()
result.Tables = append(result.Tables, rowValue)
return result, err
} else if format == "dot:struct" {
result.Headers = append(result.Headers, "format")
rowValue["format"] = resp.MakeDotGraphByStruct()
result.Tables = append(result.Tables, rowValue)
return result, err
}
}

if !resp.IsSucceed() {
log.Printf("ErrorCode: %v, ErrorMsg: %s", resp.GetErrorCode(), resp.GetErrorMsg())
return result, errors.New(string(resp.GetErrorMsg()))
Expand Down

0 comments on commit 75b9e5b

Please sign in to comment.