-
Notifications
You must be signed in to change notification settings - Fork 56
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: Allow querying of 9th, 19th, 29th, etc collections #2819
fix: Allow querying of 9th, 19th, 29th, etc collections #2819
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2819 +/- ##
===========================================
+ Coverage 78.60% 79.14% +0.54%
===========================================
Files 318 318
Lines 24128 24162 +34
===========================================
+ Hits 18965 19123 +158
+ Misses 3785 3662 -123
+ Partials 1378 1377 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 25 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
e00ddf8
to
fdeb99b
Compare
@@ -0,0 +1,315 @@ | |||
// Copyright 2024 Democratized Data Foundation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Praise: Thanks a bunch for documenting these! Really nice to see the issue narrowed down with the edge cases you highlighted.
fdeb99b
to
a62566a
Compare
@@ -101,8 +101,8 @@ query @explain { | |||
"collectionID": "3", | |||
"collectionName": "Author", | |||
"spans": [{ | |||
"start": "/3", | |||
"end": "/4" | |||
"start": "/\x8b", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: My eyes 😮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has been reverted - encoding is not json friendly, so explain must be pretty-printed anyway
@@ -34,86 +34,6 @@ func TestNewDataStoreKey_ReturnsEmptyStruct_GivenEmptyString(t *testing.T) { | |||
assert.ErrorIs(t, ErrEmptyKey, err) | |||
} | |||
|
|||
func TestNewDataStoreKey_ReturnsCollectionIdAndIndexIdAndDocIDAndFieldIdAndInstanceType_GivenFourItemsWithType( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Do we loose any coverage or paths that these tests were testing due to the removal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt it, in theory everything should be covered by integration tests anyway, and the new code has fewer branches IIRC.
}, nil | ||
} | ||
|
||
func EncodeDataStoreKey(key *DataStoreKey) []byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: A line documenting the Encoding type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add
- doc func
@@ -288,3 +288,81 @@ func EncodeIndexDataStoreKey(key *IndexDataStoreKey) []byte { | |||
|
|||
return b | |||
} | |||
|
|||
func DecodeDataStoreKey(data []byte) (DataStoreKey, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: A line documenting the decoding type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add
- doc func
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I left some clarifying comments.
tests/integration/utils2.go
Outdated
@@ -1301,6 +1300,7 @@ func createDocViaGQL( | |||
node client.DB, | |||
collections []client.Collection, | |||
) ([]*client.Document, error) { | |||
println(fmt.Sprint(collections)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is it left here intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not :) And I should have been more careful so soon after the mutation type bug :) Thanks for spotting
- remove print
internal/core/encoding.go
Outdated
} | ||
|
||
var docID string | ||
if len(data) > 40 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: please extract the magic number to a const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
- Rm magic number
} | ||
|
||
var instanceType InstanceType | ||
if len(data) > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: wouldn't it be better to do:
if len(data) <= 1 {
return ...
}
// check instance type ...
Currently if if len(data) > 1
is false the rest of the function is irrelevant, but is being executed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do prefer the simplicity of the current code, although it does have a small runtime cost. I'll have a quick look when I remove the magic number - do let me know if you have a strong preference though.
- Have quick look at early returns
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldn't call it a strong preference. Just following return-early best practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a play, whilst I like it hightlights the data flow a little more nicely, it ends up duplicating logic (or mutating, or a new func) and even without my gut prefers the feel of the current. Leaving as-is.
"start": "/3", | ||
"end": "/4", | ||
"start": "/\x8b", | ||
"end": "/\x8c", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though: this is pain. Would be nice to have it extracted so that if it changes again, we don't need to go through it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain was actually pretty easy considering how invasive they are by nature, the unit tests were much more of a pain.
This might get changed slightly before merge anyway - the http client does not like this encoding and it caught me out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been reverted, the encoding was not json friendly and needed to be prettied up in order to work with the http client.
testUtils "github.com/sourcenetwork/defradb/tests/integration" | ||
) | ||
|
||
func TestSimple_WithSevenDummyTypesBefore(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: would be nice to have "expectation" part in the test name:
TestSimple_WithSevenDummyTypesBefore_ShouldSucceed
or something like this.
type Type6 { | ||
f: String | ||
} | ||
|
||
type User { | ||
name: String | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: for these tests would be nice to have some more information (as a documentation or test description) explaining why these weird-looking tests are necessary and which edge-case they test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I'll add some in - thanks for pushing past my laziness here :)
- Add test docs
func TestNewDataStoreKey_GivenAStringWithExtraSuffix(t *testing.T) { | ||
instanceType := "anyType" | ||
fieldId := "f1" | ||
docID := "docID" | ||
collectionId := "1" | ||
inputString := "/db/data/" + collectionId + "/" + instanceType + "/" + docID + "/" + fieldId + "/version_number" | ||
|
||
_, err := NewDataStoreKey(inputString) | ||
|
||
assert.ErrorIs(t, ErrInvalidKey, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: you just removed the tests. Don't you plan to replace them with new ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think they had much value before, and even less so with the new code IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please double check when all tests are passing that the removed unit tests weren't testing any edge cases before merge, other than that all good! Thanks a bunch for sorting this out.
a62566a
to
8d69938
Compare
Broken out of prod code commit to not clutter primary changes.
8d69938
to
0488b30
Compare
…k#2819) ## Relevant issue(s) Resolves sourcenetwork#2810 ## Description Allows querying of 9th, 19th, 29th, etc collections. The fetcher calls `PrefixEnd` which causes the start prefix to be (e.g.) `"/9"` and the end `"/10"` causing nothing to be returned to the user. This PR fixes that by encoding the DataStore CollectionRootIDs as variable sized BigEndians. sourcenetwork#2818 has been broken out of this as it is not a user-visible issue atm and resolving it is a bit more involved due to some legacy tech. debt.
Relevant issue(s)
Resolves #2810
Description
Allows querying of 9th, 19th, 29th, etc collections.
The fetcher calls
PrefixEnd
which causes the start prefix to be (e.g.)"/9"
and the end"/10"
causing nothing to be returned to the user. This PR fixes that by encoding the DataStore CollectionRootIDs as variable sized BigEndians.#2818 has been broken out of this as it is not a user-visible issue atm and resolving it is a bit more involved due to some legacy tech. debt.