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

Add the process of Relationship V2 in EbeanLocalRelationshipWriterDAO #467

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

hongliu2024
Copy link
Contributor

Summary

This PR is to support processLocalRelationshipUpdates for relationship model v2.

Details

Changes include:

  1. GraphUtils.java
  • Pass source asset urn in the checkSameUrn method for model v2.
  1. GraphUtilsTest.java
  • Add test cases of model v2 into all scenarios
  1. ModelUtils.java
  • Make isRelationshipInV2 methods public so they can be used in EbeanLocalRelationshipWriterDAO logic
  1. EbeanLocalRelationshipWriterDAO.java
  • Add new parameter source asset urn to methods addRelationships, addRelationshipGroup, and processRemovalOption. The logic for model v1 remains the same, but the logic changes to take the passed parameter for model v2.
  • Update documents
  • Remove unused constant strings
  1. EbeanLocalRelationshipWriterDAOTest.java
  • Add model v2 test cases to RemoveFromSource test cases, since that's the one to be supported for V2.
  1. ebean-local-relationship-dao-create-all.sql
  • Add new relationship table based on the V2 relationship
  1. ebean-local-relationship-create-all-with-non-dollar-virtual-column-names.sql
  • Add new relationship table based on the V2 relationship

Testing Done

  1. ./gradlew build

BUILD SUCCESSFUL in 58s
245 actionable tasks: 37 executed, 208 up-to-date
  1. Add V2 test cases

Checklist

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.95%. Comparing base (cf25612) to head (405a7f2).
Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #467      +/-   ##
============================================
+ Coverage     67.92%   67.95%   +0.03%     
- Complexity     1628     1635       +7     
============================================
  Files           143      143              
  Lines          6247     6260      +13     
  Branches        680      683       +3     
============================================
+ Hits           4243     4254      +11     
- Misses         1712     1714       +2     
  Partials        292      292              

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

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.

some comments. Thanks for adding this support!

*/
public static void checkSameUrn(@Nonnull final List<? extends RecordTemplate> relationships,
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, final String sourceField, final String destinationField) {
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, final String sourceField,
final String destinationField, Urn urn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: annotation for nullable params

// ToDo: how to handle this for Relationship V2?
final Urn sourceUrn = getSourceUrnFromRelationship(relationships.get(0));
Urn sourceUrn = urn;
if (!ModelUtils.isRelationshipInV2(relationships.get(0).schema())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

index check before .get(0) needed or no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a null check at the begining of this method, so the index check won't be necessary.

sourceUrn = getSourceUrnFromRelationship(relationships.get(0));
}
if (sourceUrn == null) {
throw new IllegalArgumentException("Source urn is needed 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.

The v1 v2 case is a little hard to follow. Could you add some comments or maybe consider this?

if (!ModelUtils.isRelationshipInV2(relationships.get(0).schema())) {
  // v1 case
} else {
  // v2 case
  if (urn == null) {
    throw new IllegalArgumentException("Source urn is needed for Relationship V2");
  }
  sourceUrn = urn;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Moved into a separate method and added comments.

public <RELATIONSHIP extends RecordTemplate> void addRelationships(@Nonnull List<RELATIONSHIP> relationships,
@Nonnull RemovalOption removalOption, boolean isTestMode) {
@Nonnull RemovalOption removalOption, boolean isTestMode, Urn urn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: @nullable Urn urn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

urn is nullable for V1

// For relationship model V1, this given urn can be source urn or destination urn.
// For relationship model V2, this given urn can only be source urn.
Urn source = urn;
if (!ModelUtils.isRelationshipInV2(relationship.schema())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate code... Maybe a helper function getSourceUrnFromEither(relationship, urn)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Put that logic into a separate method, and removed the dups.


if (removalOption == RemovalOption.REMOVE_NONE) {
return;
}

SqlUpdate deletionSQL = _server.createSqlUpdate(SQLStatementUtils.deleteLocalRelationshipSQL(tableName, removalOption));
Urn source = getSourceUrnFromRelationship(relationship);
Urn source = urn;
Copy link
Contributor

Choose a reason for hiding this comment

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

^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as the above. removed the dups. Thanks.

*/
public static void checkSameUrn(@Nonnull final List<? extends RecordTemplate> relationships,
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, final String sourceField, final String destinationField) {
@Nonnull final BaseGraphWriterDAO.RemovalOption removalOption, @Nonnull final String sourceField,
@Nonnull final String destinationField, Urn urn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: @nonnull or @nullable annotation for urn

* @return The source asset urn.
*/
public static <RELATIONSHIP extends RecordTemplate> Urn getSourceUrnBasedOnRelationshipVersion(
@Nonnull RELATIONSHIP relationship, Urn urn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: @nonnull or @nullable annotation for urn

private static void checkSameUrn(@Nonnull List<? extends RecordTemplate> records, @Nonnull String field,
@Nonnull Urn compare) {
for (RecordTemplate relation : records) {
if (ModelUtils.isRelationshipInV2(relation.schema()) && field == SOURCE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: string should use .equals comparison

});
}
@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: newline after closing curly brace

private <RELATIONSHIP extends RecordTemplate> void addRelationshipGroup(@Nonnull final List<RELATIONSHIP> relationshipGroup,
@Nonnull RemovalOption removalOption, boolean isTestMode) {
@Nonnull RemovalOption removalOption, boolean isTestMode, Urn urn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: @nonnull or @nullable annotation for urn

* Needed for Relationship V2 because source is not included in the relationshipV2 metadata.
*/
private <RELATIONSHIP extends RecordTemplate> void processRemovalOption(@Nonnull String tableName,
@Nonnull RELATIONSHIP relationship, @Nonnull RemovalOption removalOption, Urn urn) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: urn annotation

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

@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 the detailed PR description

@ybz1013 ybz1013 merged commit 5d60c0c into master Nov 6, 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.

4 participants