Skip to content

Commit

Permalink
feat: Add ability to explain dagScanNode attribute(s). (#560)
Browse files Browse the repository at this point in the history
- Relevant issue: Resolves #479 

- Description: Adds the `spans` attribute for `dagScanNode` to be included in the returned explain graph response.

- Request:
```
query @Explain {
  allCommits (dockey: "test-key", field: "1") {
    links {
      cid
    }
  }
}
```

- Response:
```
{
  "explain": {
    "selectTopNode": {
      "selectNode": {
        "filter": null,
        "commitSelectNode": {
          "dagScanNode": {
            "spans": []{
              {
                "start": "/test-key/1",
                "end":   "/test-key/2",
              }
            }
          }
        }
      }
    }
  }
}
```
  • Loading branch information
shahzadlone authored Jul 7, 2022
1 parent 2c920a1 commit 27abfd4
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 6 deletions.
25 changes: 19 additions & 6 deletions query/graphql/planner/dagscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,6 @@ type dagScanNode struct {

headset *headsetScanNode
parsed *mapper.CommitSelect

// previousScanNode planNode
// linksScanNode planNode

// block blocks.Block
}

func (p *Planner) DAGScan(parsed *mapper.CommitSelect) *dagScanNode {
Expand All @@ -178,6 +173,7 @@ func (n *dagScanNode) Init() error {
}
return nil
}

func (n *dagScanNode) Start() error {
if n.headset != nil {
return n.headset.Start()
Expand Down Expand Up @@ -230,7 +226,24 @@ func (n *dagScanNode) Source() planNode { return n.headset }
// Explain method returns a map containing all attributes of this node that
// are to be explained, subscribes / opts-in this node to be an explainablePlanNode.
func (n *dagScanNode) Explain() (map[string]interface{}, error) {
return map[string]interface{}{}, nil
// explain the spans attribute.
spansExplainer := []map[string]interface{}{}
// Note: n.headset is `nil` for single commit selection query, so must check for it.
if n.headset != nil && n.headset.spans.HasValue {
for _, span := range n.headset.spans.Value {
spansExplainer = append(
spansExplainer,
map[string]interface{}{
"start": span.Start().ToString(),
"end": span.End().ToString(),
},
)
}
}

return map[string]interface{}{
spansLabel: spansExplainer,
}, nil
}

func (n *dagScanNode) Next() (bool, error) {
Expand Down
Loading

0 comments on commit 27abfd4

Please sign in to comment.