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: Add ability to explain sumNode attribute(s). #559

Merged
merged 3 commits into from
Jun 30, 2022

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented Jun 24, 2022

Relevant issue(s)

Resolves #482.

Description

Adds the attributes for sumNode to be included in the returned explain graph response.
In this PR we are introducing 3 attributes:

  1. fieldName
  2. childFieldName
  3. filter

Example:

Request:

query @explain {
  author {
    name
    _key
    TotalPages: _sum(books: {field: pages})
  }
}

Response:

{
  "explain": {
    "selectTopNode": {
      "sumNode": {
        "sources": []{
		  {
		    "fieldName":      "books",
			"childFieldName": "pages",
			"filter":         nil,
		  }
		},
        "selectNode": {
          "filter": null,
          "typeIndexJoin": {
            "joinType": "typeJoinMany",
            "rootName": "author",
            "root": {
              "scanNode": {
                "collectionID":   "3",
                "collectionName": "author",
                "filter":         null,
                "spans": []{
                  {
                    "start": "/3",
                    "end":   "/4",
                  }
                }
              }
            }
            "subTypeName": "books",
            "subType": {
              "selectTopNode": {
                "selectNode": {
                  "filter": null,
                  "scanNode": {
                    "collectionID":   "2",
                    "collectionName": "book",
                    "filter":         null,
                    "spans": []{
                      {
                        "start": "/2",
                        "end":   "/3",
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Tasks

  • I made sure the code is well commented, particularly in hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Integration tests locally and only CI. Specifically make test.

Specify the platform(s) on which this was tested:

  • Manjaro Flavor of Arch Linux Running in WSL2 on Windows 11

@shahzadlone shahzadlone added feature New feature or request area/query Related to the query component action/no-benchmark Skips the action that runs the benchmark. labels Jun 24, 2022
@shahzadlone shahzadlone added this to the DefraDB v0.3 milestone Jun 24, 2022
@shahzadlone shahzadlone requested a review from a team June 24, 2022 07:08
@shahzadlone shahzadlone self-assigned this Jun 24, 2022
Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

Approving assuming you address the 2 points I've raised. Seems like you'll see those on all your explain PRs 😅.

tests/integration/query/explain/with_sum_test.go Outdated Show resolved Hide resolved
tests/integration/query/explain/with_sum_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

couple of minor comments on the tests, otherwise looks good!

tests/integration/query/explain/with_sum_test.go Outdated Show resolved Hide resolved
@shahzadlone shahzadlone force-pushed the lone/feat/explain-sum-node-attributes branch from 503e110 to 71aa2a5 Compare June 28, 2022 16:56
@shahzadlone shahzadlone requested a review from AndrewSisley June 28, 2022 16:58
@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Merging #559 (6b355fe) into develop (3957381) will increase coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #559      +/-   ##
===========================================
+ Coverage    56.58%   56.69%   +0.10%     
===========================================
  Files          121      121              
  Lines        14082    14104      +22     
===========================================
+ Hits          7969     7996      +27     
+ Misses        5421     5416       -5     
  Partials       692      692              
Impacted Files Coverage Δ
query/graphql/planner/sum.go 81.69% <100.00%> (+6.89%) ⬆️

Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Approved, and thanks for the test expansion. Added a small thought RE one of the props, but is optional

if source.ChildTarget.HasValue {
explainerMap["childFieldName"] = source.ChildTarget.Name
} else {
explainerMap["childFieldName"] = nil
Copy link
Contributor

Choose a reason for hiding this comment

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

thought (non-blocking): I'm not sure this should be present - it should only reach here if summing an inline array, which doesn't have this prop available in the query syntax. Your call though, no strong feelings.

@shahzadlone
Copy link
Member Author

thought (non-blocking): I'm not sure this should be present - it should only reach here if summing an inline array, which doesn't have this prop available in the query syntax. Your call though, no strong feelings.

That is a reasonable thought, I raised the same question in my head too while implementing it. Thinking about it a bit, I was still unsure what the best route was so I decided to go with this approach (leaving the empty child as nil) because of the following reasons:

  1. This would till accurately show if the child is empty or not(as you mentioned will be only for the inline array case).

  2. So far for every explained node the number of attributes that are dumped doesn't change depending on the underlying value of the attribute that is being dumped, so this keeps it consistent to always dump a specific number of attributes.

  3. Even though the current implementation is technically called Explain it is technically a Simple + Verbose explain (from the future roadmap) i.e. @explain(type: 'simple', verbose: true) which will also be the default explain: i.e. @explain. So in that light these varying attributes can be left for the work for the verbose: false feature which would omit the nil fields (here and in filter for example).

@shahzadlone shahzadlone force-pushed the lone/feat/explain-sum-node-attributes branch from 71aa2a5 to 6b355fe Compare June 29, 2022 06:59
@shahzadlone shahzadlone merged commit e8b86b1 into develop Jun 30, 2022
@shahzadlone shahzadlone deleted the lone/feat/explain-sum-node-attributes branch June 30, 2022 12:00
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
- Relevant issue(s): sourcenetwork#482.

- Description

Adds the attributes for `sumNode` to be included in the returned explain graph response.
In this PR we are introducing 3 attributes:
1) `fieldName`
2) `childFieldName`
3) `filter`

Example:

- Request:
```
query @Explain {
  author {
    name
    _key
    TotalPages: _sum(books: {field: pages})
  }
}
```

- Response:
```
{
  "explain": {
    "selectTopNode": {
      "sumNode": {
        "sources": []{
		  {
		    "fieldName":      "books",
			"childFieldName": "pages",
			"filter":         nil,
		  }
		},
        "selectNode": {
          "filter": null,
          "typeIndexJoin": {
            "joinType": "typeJoinMany",
            "rootName": "author",
            "root": {
              "scanNode": {
                "collectionID":   "3",
                "collectionName": "author",
                "filter":         null,
                "spans": []{
                  {
                    "start": "/3",
                    "end":   "/4",
                  }
                }
              }
            }
            "subTypeName": "books",
            "subType": {
              "selectTopNode": {
                "selectNode": {
                  "filter": null,
                  "scanNode": {
                    "collectionID":   "2",
                    "collectionName": "book",
                    "filter":         null,
                    "spans": []{
                      {
                        "start": "/2",
                        "end":   "/3",
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/query Related to the query component feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Explain the attributes of sumNode.
3 participants