-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
*/ | ||
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ReportAttention: Patch coverage is
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. |
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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use camelcase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
There was a problem hiding this 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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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
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