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

Implement deep copies for the Operation subclasses. #1815

Merged
merged 17 commits into from
Feb 20, 2025

Conversation

RobinTF
Copy link
Collaborator

@RobinTF RobinTF commented Feb 17, 2025

The deep copies are implemented via an explicit clone methods.
The reason behind this explicit method is two-fold:

  • Currently the children of an operation are stored as shared_ptrs to make the query planning cheaper, so we need explicit logic to recursively deep clone all the children.
  • We need an explicit clone method anyway, because Operation is a virtual base class, where we need an explicit clone method (the socalled virtual copy constructor idiom, to create a copy of a pointer to the virtual base class.

Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 96.85864% with 6 lines in your changes missing coverage. Please review.

Project coverage is 90.19%. Comparing base (caaf76c) to head (59577dd).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/engine/Operation.cpp 76.92% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1815      +/-   ##
==========================================
+ Coverage   90.12%   90.19%   +0.06%     
==========================================
  Files         399      399              
  Lines       38220    38399     +179     
  Branches     4283     4294      +11     
==========================================
+ Hits        34446    34634     +188     
+ Misses       2483     2470      -13     
- Partials     1291     1295       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@RobinTF RobinTF force-pushed the cloneable-operation branch from 150a56b to 3f8f44a Compare February 18, 2025 08:46
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

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

Thank you very much.
I think there is some work to do to make this correct and to make it harder to break this in the future.

Haven't looked at all the tests yet, because they need some generalization (see my comments)

Comment on lines +211 to +214
auto newJoin = std::make_unique<ExistsJoin>(*this);
newJoin->left_ = left_->clone();
newJoin->right_ = right_->clone();
return newJoin;
Copy link
Member

Choose a reason for hiding this comment

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

How much does it break if you delete the copy constructor of the Operation base class, such that this pattern doesn't work anymore, and then always explicitly call appropriate constructors?


// _____________________________________________________________________________
std::unique_ptr<Operation> Minus::clone() const {
auto copy = std::make_unique<Minus>(*this);
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

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

I already like this much better, we are getting there!

}
return true;
};
AD_CORRECTNESS_CHECK(areChildrenDifferent());
Copy link
Member

Choose a reason for hiding this comment

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

Can also include expensive checks for the equality of variableToColumnMaps, sizeEstimates, multiplicities, whatNotElse

Copy link
Member

Choose a reason for hiding this comment

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

(have a look at the public interface of Operation for inspiration.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Many of these don't work because their public interface is not const (even though it seems like it could be const for most of them)

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

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

The really last request:

In the unit test matcher of clone,
you can assert that the varToColMaps and Multiplicities are equal, and that (most importantly) the getResult yields equal results.

Otherwise this is ready to merge (so you can rebase all your code that depens on it on this PR.

@sparql-conformance
Copy link

Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

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

Thank you very much.

@joka921 joka921 changed the title Implement clone for Operation class Implement deep copies for the Operation subclasses. Feb 20, 2025
@joka921 joka921 merged commit cc0e35b into ad-freiburg:master Feb 20, 2025
24 checks passed
@RobinTF RobinTF deleted the cloneable-operation branch February 20, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants