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: Change GetCollectionBySchemaFoo funcs to return many #1984

Merged

Conversation

AndrewSisley
Copy link
Contributor

Relevant issue(s)

Resolves #1963

Description

Changes GetCollectionBySchemaFoo function signatures to return many Collections, instead of single values.

Conceptually these functions were broken and relied on the fact that we cannot yet link multiple collections to the same schema(version)(s). This changes their signatures and the code that calls them to reflect what they should do long term.

The code that calls these functions now hosts the 'broken' code. These will still need to change once we add global IDs.

The implementation of these functions will change later in #1964.

@AndrewSisley AndrewSisley added feature New feature or request area/collections Related to the collections system code quality Related to improving code quality labels Oct 19, 2023
@AndrewSisley AndrewSisley added this to the DefraDB v0.8 milestone Oct 19, 2023
@AndrewSisley AndrewSisley requested a review from a team October 19, 2023 18:01
@AndrewSisley AndrewSisley self-assigned this Oct 19, 2023
Conceptually many collections can share the same schema. The implementation of this func can change later once things are stored correctly to actually allow this.
Conceptually many collections can share the same schema. The implementation of this func can change later once things are stored correctly to actually allow this.

// WARNING: This will become incorrect once we allow multiple collections to share the same schema
// todo: link to tickets.
// We should instead fetch the collection be global collection ID:
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: by global...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I managed to leave half the todo text in there too..., thanks for spotting Fred :)

  • Fix warning text

Comment on lines 66 to 75
if name != "" {
fetchedCols := cols
cols = nil
for _, c := range fetchedCols {
if c.Name() == name {
cols = append(cols, c)
break
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought: This seems superfluous. If name != "", there will be exactly one collection anyways.

thought (out-of-scope): We should eventually ensure that the flags that are part of the switch statement are mutually exclusive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems superfluous. If name != "", there will be exactly one collection anyways.

There will be one collection, but the user may have requested it at a specific schema version (by providing both a name, and schema version param). So we need to fetch by schema version and then filter by name.

I'll add a comment.

  • Add comment

We should eventually ensure that the flags that are part of the switch statement are mutually exclusive.

I disagree with this, for the use case above.

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Attention: 94 lines in your changes are missing coverage. Please review.

Comparison is base (9e1ad62) 74.46% compared to head (bee1b8b) 74.18%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1984      +/-   ##
===========================================
- Coverage    74.46%   74.18%   -0.29%     
===========================================
  Files          246      246              
  Lines        24309    24426     +117     
===========================================
+ Hits         18101    18118      +17     
- Misses        5010     5095      +85     
- Partials      1198     1213      +15     
Flag Coverage Δ
all-tests 74.18% <43.37%> (-0.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
net/peer_collection.go 58.04% <100.00%> (ø)
net/server.go 74.48% <57.14%> (-0.29%) ⬇️
cli/errors.go 0.00% <0.00%> (ø)
planner/commit.go 76.00% <40.00%> (-2.08%) ⬇️
db/collection.go 69.37% <77.50%> (+0.01%) ⬆️
client/errors.go 50.00% <0.00%> (-14.71%) ⬇️
http/handler_store.go 77.06% <0.00%> (-1.62%) ⬇️
cli/collection.go 58.90% <55.17%> (+0.21%) ⬆️
http/client.go 41.48% <0.00%> (-1.27%) ⬇️
db/txn_db.go 53.01% <40.62%> (-2.34%) ⬇️

... and 5 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e1ad62...bee1b8b. Read the comment docs.

Comment on lines 67 to 71
// Multiple params may have been specified, and in some cases both are needed.
// For example if a schema version and a collection name have been provided,
// we need to ensure tha a collection at the requested version is returned.
// Likewise we need to ensure that if a name and schema id are provided, but
// there are none matching both, that nothing is returned.
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 don't think this comment reflect what happens in the switch statement. Only one of the three will ever be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but that is due to how they interact.

If name and another param is provided, the other param will be used and name applied after.
If schema version is provided, schema does not matter. We could check that the schema version fetched is actually of the given schema though in case someone provides impossible params.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yes ok I see what you mean 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

// we need to ensure **that** a collection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes ok I see what you mean

Am adding an error for that schema-schema version id clash

  • add error

we need to ensure that a collection

Cheers, will change :)

  • collection name

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!

@AndrewSisley AndrewSisley merged commit e0e1779 into sourcenetwork:develop Oct 19, 2023
29 checks passed
@AndrewSisley AndrewSisley deleted the 1963-detangle-col-fetch-funcs branch October 19, 2023 19:30
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…work#1984)

## Relevant issue(s)

Resolves sourcenetwork#1963

## Description

Changes GetCollectionBySchemaFoo function signatures to return many
Collections, instead of single values.

Conceptually these functions were broken and relied on the fact that we
cannot yet link multiple collections to the same schema(version)(s).
This changes their signatures and the code that calls them to reflect
what they should do long term.

The code that calls these functions now hosts the 'broken' code. These
will still need to change once we add global IDs.

The implementation of these functions will change later in
sourcenetwork#1964.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/collections Related to the collections system code quality Related to improving code quality feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Detangle collection fetching features
2 participants