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 sortNode attribute(s). #558

Merged
merged 5 commits into from
Jul 5, 2022

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented Jun 24, 2022

Relevant issue(s)

Resolves #481.
Fixes #584 ([2] case).

Description

Adds the attributes for sortNode to be included in the returned explain graph response.
So far, we are only introducing 1 attribute, which represents a list containing all the orderings of each field requested to be sorted, with its corresponding direction.

Example:

Request:

query @explain {
  author(order: {age: ASC}) {
    name
    age
    verified
  }
}

Response:

{
  "explain": {
    "selectTopNode": {
      "sortNode": {
        "selectNode": {
          "filter": null,
          "scanNode": {
            "filter":         null,
            "collectionID":   "3",
            "collectionName": "author",
            "spans": []{
              {
                "start": "/3",
                "end":   "/4",
              }
            }
          }
        }
        "orderings": []{
          {
            "direction": "ASC",
            "fields":     [ "age" ],
          }
        }
      }
    }
  }
}

Limitations:

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 06:38
@shahzadlone shahzadlone self-assigned this Jun 24, 2022
@shahzadlone shahzadlone force-pushed the lone/explain-sort-node-attributes branch 2 times, most recently from 4572a28 to 3512e0c Compare June 24, 2022 06:46
@codecov
Copy link

codecov bot commented Jun 24, 2022

Codecov Report

Merging #558 (4857a7b) into develop (70c8363) will increase coverage by 0.13%.
The diff coverage is 90.47%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #558      +/-   ##
===========================================
+ Coverage    55.95%   56.08%   +0.13%     
===========================================
  Files          121      121              
  Lines        14191    14231      +40     
===========================================
+ Hits          7940     7982      +42     
+ Misses        5553     5549       -4     
- Partials       698      700       +2     
Impacted Files Coverage Δ
query/graphql/planner/planner.go 73.58% <0.00%> (ø)
query/graphql/planner/sort.go 83.50% <86.95%> (+7.50%) ⬆️
core/doc.go 94.39% <100.00%> (+0.77%) ⬆️
query/graphql/mapper/targetable.go 58.62% <100.00%> (+8.62%) ⬆️

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 formatting points I've raised.

tests/integration/query/explain/with_sort_test.go Outdated Show resolved Hide resolved
tests/integration/query/explain/with_sort_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.

Got a couple of comments on the tests but nothing too serious. Looks good!

@shahzadlone shahzadlone force-pushed the lone/explain-sort-node-attributes branch 3 times, most recently from 3512e0c to 596f6fd Compare July 2, 2022 06:10
todo: Still have to add the test where you can sort/order the parent by its child.
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.

I think #584 should be solved here as it looks like an explain bug, but otherwise looks good

@@ -106,6 +106,13 @@ type OrderCondition struct {
Direction SortDirection
}

func (oc OrderCondition) IsEmpty() bool {
if oc.Direction == "" && len(oc.FieldIndexes) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: I think oc.Direction == "" is not useful and this should only check len(oc.FieldIndexes). If it is impossible for only one of these to be true, then it is misleading and wasteful, if it is possible for direction to be empty and field indexes to be populated then that IMO is something that the sortNode could handle (could be a default direction for example).

Copy link
Member Author

@shahzadlone shahzadlone Jul 5, 2022

Choose a reason for hiding this comment

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

I would like to check for Direction because if it is not empty then would like to have it dumped, this check was mainly put because I noticed that sortNode.ordering has a bunch of empty elements (i.e. elements in ordering having both Direction == "" and len(FieldIndexes) == 0). Can be handled inside sortNode for sure, I find more clarity having this IsEmpty function handle that but don't mind moving it into sortNode if you have a strong preference for it.

core/doc.go Outdated Show resolved Hide resolved
tests/integration/query/explain/with_sort_test.go Outdated Show resolved Hide resolved
function also look and ChildMappings to find the name of the index, Add
the test that was failing before, also make `TryToFindNameFromIndex` now
follow the boolean try pattern instead of returning error.
@shahzadlone shahzadlone force-pushed the lone/explain-sort-node-attributes branch from 556cd1c to 4857a7b Compare July 5, 2022 13:29
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.

Looks good Shahzad. I do still disagree RE the IsEmpty stuff, but that is unimportant. I alse see tracking down why there are empties there as out of scope.

@@ -455,7 +455,7 @@ func (p *Planner) explainRequest(

explainGraph, err := buildExplainGraph(plan)
if err != nil {
return nil, err
return nil, multiErr(err, plan.Close())
Copy link
Contributor

Choose a reason for hiding this comment

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

:) This smells like the similar Close issue I saw a while ago. Good find

@shahzadlone shahzadlone merged commit c3c6495 into develop Jul 5, 2022
@shahzadlone shahzadlone deleted the lone/explain-sort-node-attributes branch July 5, 2022 15:11
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
)

- Relevant issue(s):
  Resolves sourcenetwork#481.
  Fixes sourcenetwork#584 ([2] case).

- Description
Adds the attributes for `sortNode` to be included in the returned explain graph response.
So far, we are only introducing 1 attribute, which represents a list containing all the `orderings` of each field requested to be sorted, with its corresponding direction.

- Request:
```
query @Explain {
  author(order: {age: ASC}) {
    name
    age
    verified
  }
}
```

- Response:
```
{
  "explain": {
    "selectTopNode": {
      "sortNode": {
        "selectNode": {
          "filter": null,
          "scanNode": {
            "filter":         null,
            "collectionID":   "3",
            "collectionName": "author",
            "spans": []{
              {
                "start": "/3",
                "end":   "/4",
              }
            }
          }
        }
        "orderings": []{
          {
            "direction": "ASC",
            "fields":     [ "age" ],
          }
        }
      }
    }
  }
}
```
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.

bug: Panic upon explain request of parent being ordered by child Explain the attributes of sortNode.
3 participants