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

fix: Error if group select contains non-group-by fields #898

Merged
merged 8 commits into from
Oct 18, 2022

Conversation

AndrewSisley
Copy link
Contributor

Relevant issue(s)

Resolves #680

Description

Errors if group select contains non-group-by fields instead of yielding the last doc in the group's values.

Also migrates some parse unit tests to integration tests, as an internal func that it was dependent on change its signature.

Deliberately avoids complicating things too much RE validation, it is easy to move off the parser.Select object if/when we add similar validation for other query types.

@AndrewSisley AndrewSisley added bug Something isn't working area/parser Related to the parser components action/no-benchmark Skips the action that runs the benchmark. labels Oct 14, 2022
@AndrewSisley AndrewSisley added this to the DefraDB v0.4 milestone Oct 14, 2022
@AndrewSisley AndrewSisley requested a review from a team October 14, 2022 16:04
@AndrewSisley AndrewSisley self-assigned this Oct 14, 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.

LGTM with two minor things I'd like covered before you merge.

client/errors.go Outdated
@@ -13,24 +13,30 @@ package client
import "github.com/sourcenetwork/defradb/errors"

const (
errFieldNotExist string = "The given field does not exist"
errFieldNotExist string = "The given field does not exist"
errSelectOfNonGroupField string = "Cannot select a non-group-by field at group-level"
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: The linter will flag this when we merge #901. If you don't mind changing Cannot to cannot that would be great.

Copy link
Contributor Author

@AndrewSisley AndrewSisley Oct 18, 2022

Choose a reason for hiding this comment

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

Not a problem

  • lowercase error

Comment on lines +94 to +97
switch typedChildSelection := childSelection.(type) {
case *Select:
result = append(result, typedChildSelection.validateShallow()...)
default:
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Do you foresee having more than *Select in that switch statement? If not

if typedChildSelection, ok := childSelection.(*Select); ok {
    result = append(result, typedChildSelection.validateShallow()...)
}

would be more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, same code block could handle commit, create, update etc - I prefer the switch here

Comment on lines +30 to 34
name
_group {
age
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: I'm surprised that this worked before. I guess this PR helps with flagging stuff like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in develop branch these fields just yield the value of the last record in the group, as explain tests dont assert the actual values returned these never failed - explain tests do however check for errors, which is why they started to fail in this branch (before fixing them)

These tests are already covered by existing integration tests and can be removed without loss of coverage.
I really dont think we support this anyway, and I cant see how the feature would work (updating a list of docs, with a provided list of docs)
These tests contained invalid queries and will fall foul of the soon-to-be-added validation rule
@AndrewSisley AndrewSisley force-pushed the sisley/fix/I680-group-validation branch from 7e17fa5 to b5cce32 Compare October 18, 2022 20:19
@AndrewSisley AndrewSisley force-pushed the sisley/fix/I680-group-validation branch from b5cce32 to 2539e39 Compare October 18, 2022 20:25
@codecov
Copy link

codecov bot commented Oct 18, 2022

Codecov Report

Merging #898 (2539e39) into develop (98d2e09) will increase coverage by 0.10%.
The diff coverage is 88.05%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #898      +/-   ##
===========================================
+ Coverage    59.68%   59.78%   +0.10%     
===========================================
  Files          156      156              
  Lines        17306    17358      +52     
===========================================
+ Hits         10329    10378      +49     
- Misses        6042     6044       +2     
- Partials       935      936       +1     
Impacted Files Coverage Δ
query/graphql/parser/query.go 83.07% <86.66%> (+3.63%) ⬆️
client/errors.go 100.00% <100.00%> (ø)
query/graphql/planner/executor.go 79.06% <100.00%> (+2.14%) ⬆️
query/graphql/parser/mutation.go 80.43% <0.00%> (-3.27%) ⬇️

@AndrewSisley AndrewSisley merged commit 91cd7a3 into develop Oct 18, 2022
@AndrewSisley AndrewSisley deleted the sisley/fix/I680-group-validation branch October 18, 2022 20:37
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…k#898)

* Remove unit tests with existing int. tests

These tests are already covered by existing integration tests and can be removed without loss of coverage.

* Migrate create empty unit test

* Migrate invalid mutation test

* Remove unsupported unit test

I really dont think we support this anyway, and I cant see how the feature would work (updating a list of docs, with a provided list of docs)

* Migrate underscored schema name test

* Correct explain query tests

These tests contained invalid queries and will fall foul of the soon-to-be-added validation rule

* Error on select of fields not in group
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/parser Related to the parser components bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GroupBy invalid fields outside of _group
2 participants