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: Allow relation alias on create and update #1609

Merged

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented Jul 4, 2023

Relevant issue(s)

Resolves #1279

Description

Here are the main tasks that were done in this PR:

  • Add some tests that are might not be directly related
  • Before implementation add more tests for non-alias behavior while creating document.
  • Add implementation for aliasing on related object link while creating document.
  • Add 1-1 tests for aliasing on related object while creating document.
  • Add 1-M tests for aliasing on related object while creating document.
  • Before implementation add tests for non-alias behavior while updating document.
  • Add implementation for aliasing on related object link while updating document.
  • Add 1-1 tests for aliasing on related object while updating document.
  • Add 1-M tests for aliasing on related object while updating document.

In addition, I had to resolve a circular dependency but making the core/cid.go stuff it's own modular package. Refactored manual uses of cid.Prefix and dockey generation so that it's consistent.

For Reviewers

  • This commit PR(FIX): Squash the dockey verification + diff bug undoes some work in the commit PR(CORE): Implement the alias logic for create to fix a bug. Other than that should be "cleanish" history.

How has this been tested?

  • Integration tests.

@shahzadlone shahzadlone added the feature New feature or request label Jul 4, 2023
@shahzadlone shahzadlone added this to the DefraDB v0.6 milestone Jul 4, 2023
@shahzadlone shahzadlone self-assigned this Jul 4, 2023
@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Patch coverage: 79.07% and project coverage change: +0.09 🎉

Comparison is base (ce28685) 75.56% compared to head (48e3f45) 75.65%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1609      +/-   ##
===========================================
+ Coverage    75.56%   75.65%   +0.09%     
===========================================
  Files          199      200       +1     
  Lines        20769    20808      +39     
===========================================
+ Hits         15693    15741      +48     
+ Misses        3997     3990       -7     
+ Partials      1079     1077       -2     
Flag Coverage Δ
all-tests 75.65% <79.07%> (+0.09%) ⬆️

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

Impacted Files Coverage Δ
client/errors.go 57.14% <ø> (-2.86%) ⬇️
planner/create.go 65.66% <57.14%> (-2.05%) ⬇️
db/collection.go 70.62% <70.00%> (-0.29%) ⬇️
client/document.go 66.24% <73.91%> (+0.76%) ⬆️
client/request/errors.go 100.00% <100.00%> (ø)
client/request/select.go 100.00% <100.00%> (ø)
core/cid/cid.go 100.00% <100.00%> (ø)
db/collection_update.go 76.14% <100.00%> (+3.24%) ⬆️
db/errors.go 87.74% <100.00%> (+0.16%) ⬆️

... and 8 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 ce28685...48e3f45. Read the comment docs.

@shahzadlone shahzadlone marked this pull request as ready for review July 13, 2023 18:04
@shahzadlone shahzadlone requested a review from a team July 13, 2023 18:09
@shahzadlone shahzadlone added the area/query Related to the query component label Jul 13, 2023
db/collection.go Outdated
Comment on lines 877 to 883
fieldKey, isAliasKey, fieldExists := c.tryGetFieldKey(primaryKey, k)
// Overwrite the aliased key with the internal related object name.
if isAliasKey {
oldKey := k
k = oldKey + request.RelatedObjectID
doc.Fields()[k] = v
delete(doc.Fields(), oldKey)
Copy link
Member Author

Choose a reason for hiding this comment

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

tip-for-reviewer: This implementation and some other parts or this commit were removed and implemented elsewhere while fixing a bug in the commit [PR(FIX): Squash the dockey verification + diff bug]

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.

Great work here Shahzad! Very nicely executed.

core/cid/cid.go Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Should the date be changed to 2023?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's fine IMO

@@ -875,6 +866,7 @@ func (c *collection) save(

if val.IsDirty() {
fieldKey, fieldExists := c.tryGetFieldKey(primaryKey, k)

Copy link
Collaborator

Choose a reason for hiding this comment

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

question: Was this extra line accidental?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's when I undid the changes mentioned in the PR description lol.

Comment on lines +128 to +135
Request: fmt.Sprintf(
`mutation {
update_Book(id: "%s", data: "{\"author_id\": \"%s\"}") {
name
}
}`,
bookKey,
invalidAuthorKey,
Copy link
Collaborator

Choose a reason for hiding this comment

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

thought (Out of scope): This should probably return an error no document for the given key exists like it does on the 1-to-1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I see a few tests before this PR that note adding that in. Not sure if there is a ticket for that yet.

@shahzadlone shahzadlone merged commit f02e2cd into sourcenetwork:develop Jul 17, 2023
10 checks passed
@shahzadlone shahzadlone deleted the feat/alias-mutation-relation branch July 17, 2023 19:04
@islamaliev
Copy link
Contributor

bug bash results:
ran locally a defradb node with Author, Book, Article and others.
Using Altair GraphLQ client ran different create and update mutations with and without aliases. Worked fine.
Also ran queries with filters. Worked fine.

@shahzadlone shahzadlone mentioned this pull request Jan 9, 2024
4 tasks
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
## Relevant issue(s)
Resolves sourcenetwork#1279 

## Description
Here are the main tasks that were done in this PR:
- [x] Add some tests that are might not be directly related
- [x] Before implementation add more tests for non-alias behavior while
creating document.
- [x] Add implementation for aliasing on related object link while
creating document.
- [x] Add 1-1 tests for aliasing on related object while creating
document.
- [x] Add 1-M tests for aliasing on related object while creating
document.
- [x] Before implementation add tests for non-alias behavior while
updating document.
- [x] Add implementation for aliasing on related object link while
updating document.
- [x] Add 1-1 tests for aliasing on related object while updating
document.
- [x] Add 1-M tests for aliasing on related object while updating
document.

In addition, I had to resolve a circular dependency but making the
`core/cid.go` stuff it's own modular package. Refactored manual uses of
`cid.Prefix` and dockey generation so that it's consistent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Allow using object as an alias for object_id in relationships
3 participants