Skip to content

Commit

Permalink
feat: Explain cid & field attributes for dagScanNode (#598)
Browse files Browse the repository at this point in the history
## Relevant issue(s)
Resolves #597  

## Description
Adds two more attributes to be included in the explain graph for `dagScanNode`.
  • Loading branch information
shahzadlone authored Jul 7, 2022
1 parent 27abfd4 commit 7e90fbb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
24 changes: 20 additions & 4 deletions query/graphql/planner/dagscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,23 @@ 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) {
// explain the spans attribute.
explainerMap := map[string]interface{}{}

// Add the field attribute to the explaination if it exists.
if len(n.field) != 0 {
explainerMap["field"] = n.field
} else {
explainerMap["field"] = nil
}

// Add the cid attribute to the explaination if it exists.
if n.cid != nil && n.cid.Defined() {
explainerMap["cid"] = n.cid.Bytes()
} else {
explainerMap["cid"] = nil
}

// Build the explaination of 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 {
Expand All @@ -240,10 +256,10 @@ func (n *dagScanNode) Explain() (map[string]interface{}, error) {
)
}
}
// Add the built spans attribute, if it was valid.
explainerMap[spansLabel] = spansExplainer

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

func (n *dagScanNode) Next() (bool, error) {
Expand Down
47 changes: 47 additions & 0 deletions tests/integration/query/explain/dagscan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func TestExplainAllCommitsDagScan(t *testing.T) {
"filter": nil,
"commitSelectNode": dataMap{
"dagScanNode": dataMap{
"cid": nil,
"field": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
Expand Down Expand Up @@ -112,6 +114,8 @@ func TestExplainAllCommitsDagScanWithoutField(t *testing.T) {
"filter": nil,
"commitSelectNode": dataMap{
"dagScanNode": dataMap{
"cid": nil,
"field": "C",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/C",
Expand Down Expand Up @@ -208,6 +212,8 @@ func TestExplainLatestCommitsDagScan(t *testing.T) {
"filter": nil,
"commitSelectNode": dataMap{
"dagScanNode": dataMap{
"cid": nil,
"field": "1",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/1",
Expand Down Expand Up @@ -266,6 +272,8 @@ func TestExplainLatestCommitsDagScanWithoutField(t *testing.T) {
"filter": nil,
"commitSelectNode": dataMap{
"dagScanNode": dataMap{
"cid": nil,
"field": "C",
"spans": []dataMap{
{
"start": "/bae-41598f0c-19bc-5da6-813b-e80f14a10df3/C",
Expand Down Expand Up @@ -363,6 +371,45 @@ func TestExplainOneCommitDagScan(t *testing.T) {
"filter": nil,
"commitSelectNode": dataMap{
"dagScanNode": dataMap{
"cid": []uint8{
0x01,
0x70,
0x12,
0x20,
0x98,
0x96,
0xeb,
0xf9,
0xa1,
0x8f,
0xd0,
0xb4,
0xae,
0x2a,
0x30,
0x23,
0x92,
0x00,
0x7c,
0x82,
0x80,
0x00,
0x88,
0xd6,
0x65,
0xfa,
0xdd,
0xf4,
0x80,
0xfa,
0xe1,
0xa7,
0x44,
0x09,
0xea,
0xdd,
},
"field": nil,
"spans": []dataMap{},
},
},
Expand Down

0 comments on commit 7e90fbb

Please sign in to comment.