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

support relationship v2 #462

Merged
merged 6 commits into from
Nov 5, 2024
Merged

Conversation

hongliu2024
Copy link
Contributor

@hongliu2024 hongliu2024 commented Oct 28, 2024

Summary

This PR is to ensure the EbeanLocalWriterDAO can support both relationship V1 and relationship V2.
The changes are in Schema Validation for Relationship v2, RecordUtils, ModelUtils, and GraphUtils.

Question though is checkSameUrn logic in GraphUtils.java. They are related to the removal option, and for some options, they check for source Urn. But in Relationship model v2, there is no source field. Should it just skip the check for source field for V2, or should it look at the belonging aspect to find the source Urn? I feel looking at belonging aspect can have problems too because one relationship can be included in multiple different aspects.

Testing Done

Unit test cases added.

Checklist

*/
static boolean isRelationshipInV2(@Nonnull RecordDataSchema schema) {
// check the data type of the source and destination fields in schema and see if it's a union type
return schema.getFields().stream().anyMatch(
Copy link
Contributor

Choose a reason for hiding this comment

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

Yang is saying we should instead keep the source in the base RelationshipV2.proto model. and then specific types of relationships will have 'destination' field only. Check: #456 (comment)

What do you think? The issue with keeping "source" in the relationship model, which is part of the aspect model now is that the source could be different from the asset urn of the aspect.

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 discussed offline, I removed the source field from the v2 model

if (dataMap == null) {
ValidationUtils.throwNullFieldException(fieldName);
}
return dataMap.keySet().iterator().next();
Copy link
Contributor

Choose a reason for hiding this comment

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

QQ: does this always work because the iterator will only have 1 item?

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 field is translated from proto oneOf, which should have only 1 item.

.getField(fieldName)
.getType()
.getMembers()
.get(0)
Copy link
Contributor

Choose a reason for hiding this comment

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

can there be index out of bounds exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this logic.

});

validatePairings(schema);
// Relationship V2 uses AuditStamp class, instead of primitive types
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC we also need to replace usages of com.linkedin.common.Time with int64. Does this PR cover 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.

I'm thinking to use AuditStamp class to replace the AuditStampActor and AuditStampTimeAt

Example TestRelationship.proto

Please let me know wdyt

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 70.37037% with 8 lines in your changes missing coverage. Please review.

Project coverage is 67.99%. Comparing base (efa96e0) to head (06849d9).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...va/com/linkedin/metadata/dao/utils/ModelUtils.java 77.77% 2 Missing and 2 partials ⚠️
...a/com/linkedin/metadata/dao/utils/RecordUtils.java 50.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #462      +/-   ##
============================================
+ Coverage     67.61%   67.99%   +0.38%     
- Complexity     1604     1626      +22     
============================================
  Files           143      143              
  Lines          6207     6237      +30     
  Branches        675      678       +3     
============================================
+ Hits           4197     4241      +44     
+ Misses         1726     1707      -19     
- Partials        284      289       +5     

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

@hongliu2024 hongliu2024 marked this pull request as ready for review October 30, 2024 07:37
if (!relationshipInV2) {
// if V1, get the urn from the given field name, "source" or "destination"
urn = RecordUtils.getRecordTemplateField(relationship, fieldName, urnClassForRelationship(relationship.getClass(), fieldName));
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we validate that fieldName = 'destination' in this case?

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.

@@ -25,6 +24,7 @@ public static void checkSameUrn(@Nonnull final List<? extends RecordTemplate> re
return;
}

// ToDo: how to handle this for Relationship V2?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it just skip the check for source field for V2, or should it look at the belonging aspect to find the source Urn? I feel looking at belonging aspect can have problems too because one relationship can be included in multiple different aspects.

We can just check during runtime if the source urn in the relationship(s) match the asset urn being ingested. I will add it in my followup PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. Should I keep this ToDo here?

/**
* For unit tests
*/
aspect_with_relationship: AspectWithRelationship
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use camelcase

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

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.

One question

@@ -306,7 +318,11 @@ private static <RELATIONSHIP extends RecordTemplate> Urn getUrnFromRelationship(
@Nonnull
public static <RELATIONSHIP extends RecordTemplate> Urn getSourceUrnFromRelationship(
Copy link
Contributor

Choose a reason for hiding this comment

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

EbeanLocalRelationshipWriterDAO.addRelationshipGroup invokes this for each relationship groups when create sql updates.

Since here it will throw exceptions, how are the relationship updates are fired?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great question. I was trying to handle it but it needs to come from aspect.
@jsdonn - I'd like to discuss about this.
For now I think it's ok to push this PR out since V1 isn't impacted by this.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline, Hong will help add logic to propagate the source urn passed in during ingestion to the EbeanLocalRelationshipWriterDAO

Copy link
Contributor

@jsdonn jsdonn left a comment

Choose a reason for hiding this comment

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

LGTM thanks for doing this. Let's address the concerns around not including the source field in relationship 2.0 models in a fast-follow PR

@hongliu2024 hongliu2024 merged commit 9ea5af8 into master Nov 5, 2024
1 of 2 checks passed
@hongliu2024 hongliu2024 deleted the hongliu/support_relationship_v2 branch November 5, 2024 19:30
@hongliu2024 hongliu2024 restored the hongliu/support_relationship_v2 branch November 5, 2024 21:09
@hongliu2024 hongliu2024 deleted the hongliu/support_relationship_v2 branch November 5, 2024 21:51
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.

4 participants