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: Handle the querying of secondary relation id fields #1768

Merged

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Aug 10, 2023

Relevant issue(s)

Resolves #1654

Description

Handles the querying of secondary relation id fields.

It does this by joining the related object and copying the dockey value into the secondary related id field.

@AndrewSisley AndrewSisley added bug Something isn't working area/query Related to the query component action/no-benchmark Skips the action that runs the benchmark. labels Aug 10, 2023
@AndrewSisley AndrewSisley added this to the DefraDB v0.7 milestone Aug 10, 2023
@AndrewSisley AndrewSisley requested a review from a team August 10, 2023 16:16
@AndrewSisley AndrewSisley self-assigned this Aug 10, 2023
@AndrewSisley AndrewSisley force-pushed the 1654-2ndary-related-id branch 4 times, most recently from adf203b to d3874c1 Compare August 10, 2023 16:37
@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage: 80.67% and project coverage change: +0.01% 🎉

Comparison is base (a6e7669) 75.74% compared to head (65c1844) 75.75%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1768      +/-   ##
===========================================
+ Coverage    75.74%   75.75%   +0.01%     
===========================================
  Files          209      209              
  Lines        22035    22106      +71     
===========================================
+ Hits         16690    16745      +55     
- Misses        4194     4204      +10     
- Partials      1151     1157       +6     
Flag Coverage Δ
all-tests 75.75% <80.67%> (+0.01%) ⬆️

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

Files Changed Coverage Δ
planner/mapper/mapper.go 85.71% <76.47%> (-0.92%) ⬇️
planner/planner.go 75.96% <76.92%> (+0.23%) ⬆️
planner/type_join.go 75.94% <100.00%> (+0.75%) ⬆️

... and 2 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 a6e7669...65c1844. Read the comment docs.

Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Can you please add a test in one_to_one_to_one with a query on Book joining both Author and Publisher?

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'm curious, not argumentative - how do you see that breaking/being-relevant?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I want a test confirming that two or more joins on the one object works as expected. Pretty much to ensure makeTypeJoinOne works in these kinds of situations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As-in work in general? I hope we already have tests that properly cover one-one-one joins

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Confirmed, we already cover all possible direction combinations for one-one-one joins.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Book {
  name
  publisher {
    name
  }
  author {
    name
  }
}

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 okay spreading out from the middle obj? I'll add that in another PR/branch real quick. But not here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well it's the "middle obj" in this case but what matters to me is the dual join on the one object. I think it's quite relevant here so I would like to see it added.

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 PR doesn't change any of the join mechanics. It uses a join, but it doesn't change how they work.

If a bug is found in the test gap you spotted it should not block or impact the merging of this work.

#1792

Copy link
Collaborator

Choose a reason for hiding this comment

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

fair enough :)

@@ -928,6 +906,131 @@ sourceLoop:
return newFields, nil
}

// constructDummyJoin constructs a valid empty join with no requested fields.
func constructDummyJoin(
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: I think we should avoid using the work Dummy as it feels more like something you'd use just for testing purposes. In this case this is a function that is used in a critical path. Maybe constructEmptyJoin 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 good shout - I'll change it

  • Rename Dummy func

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 with one nitpick.

Tests have been added with two different test name format. I don't want to force you to change that but keep in mind for the future that we agreed to try to have TestName_Details_Error as the test name format.

Whilst other existing tests do document the issue, this is the simplest use-case and needs coverage and will be useful when implementing the fix
It will be called from a second location shortly
Within this commit there is no way to test this, as groupBy clauses cannot traverse relations boundaries at the moment. However it is required to handle secondary relation ids (via joins), which will be added shortly.  It is also a likely step towards supporting the traversal of relations in groupBy clauses in the future.
@AndrewSisley AndrewSisley merged commit ffec14b into sourcenetwork:develop Aug 15, 2023
12 checks passed
@AndrewSisley AndrewSisley deleted the 1654-2ndary-related-id branch August 15, 2023 21:58
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…rk#1768)

## Relevant issue(s)

Resolves sourcenetwork#1654

## Description

Handles the querying of secondary relation id fields.

It does this by joining the related object and copying the dockey value
into the secondary related id field.
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 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Secondary relation id is unavailable when querying one-one relations
2 participants