Skip to content

Commit

Permalink
Simplifying inspection code
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Dec 19, 2019
1 parent ace9f79 commit 332edf6
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions engine/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,57 +81,50 @@ func PipelineStepOutputs(stmts []*gripql.GraphStatement) map[string][]string {
out := map[string][]string{}
for i := len(stmts) - 1; i >= 0; i-- {
gs := stmts[i]
if onLast {
switch gs.GetStatement().(type) {
case *gripql.GraphStatement_Count:
onLast = false
case *gripql.GraphStatement_Select:
switch gs.GetStatement().(type) {
case *gripql.GraphStatement_Count:
onLast = false
case *gripql.GraphStatement_Select:
if onLast {
sel := gs.GetSelect().Marks
for _, s := range sel {
if a, ok := asMap[s]; ok {
out[a] = []string{"*"}
}
}
onLast = false
case *gripql.GraphStatement_Distinct:
//if there is a distinct step, we need to load data, but only for requested fields
fields := protoutil.AsStringList(gs.GetDistinct())
for _, f := range fields {
n := jsonpath.GetNamespace(f)
if a, ok := asMap[n]; ok {
out[a] = []string{"*"}
}
}
case *gripql.GraphStatement_Distinct:
//if there is a distinct step, we need to load data, but only for requested fields
fields := protoutil.AsStringList(gs.GetDistinct())
for _, f := range fields {
n := jsonpath.GetNamespace(f)
if a, ok := asMap[n]; ok {
out[a] = []string{"*"}
}
case *gripql.GraphStatement_V, *gripql.GraphStatement_E,
*gripql.GraphStatement_Out, *gripql.GraphStatement_In,
*gripql.GraphStatement_OutE, *gripql.GraphStatement_InE,
*gripql.GraphStatement_Both, *gripql.GraphStatement_BothE:
out[steps[i]] = []string{"*"}
onLast = false
case *gripql.GraphStatement_LookupVertsIndex:
}
case *gripql.GraphStatement_V, *gripql.GraphStatement_E,
*gripql.GraphStatement_Out, *gripql.GraphStatement_In,
*gripql.GraphStatement_OutE, *gripql.GraphStatement_InE,
*gripql.GraphStatement_Both, *gripql.GraphStatement_BothE:
if onLast {
out[steps[i]] = []string{"*"}
onLast = false
}
} else {
switch gs.GetStatement().(type) {
case *gripql.GraphStatement_HasLabel:
if x, ok := out[steps[i]]; ok {
out[steps[i]] = append(x, "_label")
} else {
out[steps[i]] = []string{"_label"}
}
case *gripql.GraphStatement_Has:
onLast = false
case *gripql.GraphStatement_LookupVertsIndex:
if onLast {
out[steps[i]] = []string{"*"}
case *gripql.GraphStatement_Distinct:
//if there is a distinct step, we need to load data, but only for requested fields
fields := protoutil.AsStringList(gs.GetDistinct())
for _, f := range fields {
n := jsonpath.GetNamespace(f)
if a, ok := asMap[n]; ok {
out[a] = []string{"*"}
}
}
}
onLast = false

case *gripql.GraphStatement_HasLabel:
if x, ok := out[steps[i]]; ok {
out[steps[i]] = append(x, "_label")
} else {
out[steps[i]] = []string{"_label"}
}
case *gripql.GraphStatement_Has:
out[steps[i]] = []string{"*"}
}
}
return out
Expand Down

0 comments on commit 332edf6

Please sign in to comment.