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(relationship 2.0): add aspect column to relationship tables and fix soft deletion #479

Merged
merged 9 commits into from
Nov 26, 2024

Conversation

jsdonn
Copy link
Contributor

@jsdonn jsdonn commented Nov 21, 2024

Summary

Add aspect column to relationship tables so that during relationship deletion, only the relationships derived from the same aspect that is being ingested can be deleted. This is to prevent accidental deletion of relationships which can be derived from multiple aspects.

Added a flag useAspectColumnForRelationshipRemoval which defaults to false to be backwards compatible.

Updated relationship soft deletion so it always works now whenever an aspect is soft-deleted.

Did some code cleanup of the RelationshipSource enum which is no longer needed since it will always try to get relationships from relationship builders first before looking in the aspect.

Testing Done

add unit tests

Checklist

Copy link
Contributor

@ybz1013 ybz1013 left a comment

Choose a reason for hiding this comment

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

overall looks good. Some comments on maintainability and stuff. Good work!

deletionSQL.setParameter(CommonColumnName.SOURCE, source.toString());
if (_useAspectColumnForRelationshipRemoval) {
deletionSQL.setParameter(CommonColumnName.ASPECT, aspectClass.getCanonicalName());
Copy link
Contributor

Choose a reason for hiding this comment

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

if _useAspectColumnForRelationshipRemoval is default to false, wouldn't that cause the sql update here to have 2 less cols?

In what case will we use the default false value?

Copy link
Contributor

Choose a reason for hiding this comment

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

or I guess this is a GMS level config, and once its set to true it will always be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you clarify what you mean by 2 less cols? It should just have 1 less col aspect right?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah sorry 1

ASPECT_METADATA, // Look at the aspect model and extract any relationship from its fields
RELATIONSHIP_BUILDERS // Use the relationship registry, which relies on relationship builders
}
private boolean _useAspectColumnForRelationshipRemoval = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this will make my dual write PR obsolete. I will close that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah, I guess we are not doing that anymore. But it's not wasted work, eventually if we need to migrate v1 to v2 we will need it again and we can reference the old PR.

Copy link
Contributor

@ybz1013 ybz1013 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@yangyangv2 yangyangv2 left a comment

Choose a reason for hiding this comment

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

LGTM overall, fix it and ship it.

List<RELATIONSHIP> relationships = new ArrayList<>();
localRelationshipUpdates.forEach(localRelationshipUpdate -> relationships.addAll(localRelationshipUpdate.getRelationships()));
_localRelationshipWriterDAO.removeRelationships(urn, aspectClass, relationships);
return Collections.emptyList();
Copy link
Contributor

Choose a reason for hiding this comment

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

From the comments

  • @return List of LocalRelationshipUpdates that were executed

should the return be a list of removed relationships?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to clarify - it will return nothing when soft-deleting only

String insertTemplate = "INSERT INTO %s (metadata, source, source_type, destination, destination_type, lastmodifiedon, lastmodifiedby)"
+ " VALUES ('{\"metadata\": true}', '%s', '%s', '%s', '%s', '1970-01-01 00:00:01', 'unknown')";
if (_useAspectColumnForRelationshipRemoval) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the migration plan for making all the relationship tables to include the aspect column? the shorter we finish this migration, the better. And the new relationships should by default to include the aspect column

Copy link
Contributor Author

Choose a reason for hiding this comment

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

current local relationship cases are AIM tables and downstreamof.

For AIM, we have to wait until they deprecate their current local relationship tables and onboard new ones.

For downstreamof, it should be relatively straightforward to add the new column, index, and set all aspect values to UpstreamLineage.

ALTER TABLE metadata_relationship_downstreamof ADD COLUMN aspect VARCHAR(300);
CREATE INDEX idx_aspect ON metadata_relationship_downstreamof (aspect);
UPDATE metadata_relationship_downstreamof SET aspect = 'com.linkedin.common.UpstreamLineage';

Copy link
Contributor

@yangyangv2 yangyangv2 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jsdonn jsdonn merged commit 5261abf into linkedin:master Nov 26, 2024
2 checks passed
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.

3 participants