Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Explain cid & field attributes for dagScanNode #598

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: For the future (not) now, it might be worth refactoring explain-spans at some point, as it would be good to help encourage consistency here across all nodes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Perhaps we can initiate a ticket to put any specific kind of refactor you might have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever you prefer, I probably wound't bother with a ticket and just do it as the first commit in the next explain PR

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