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

[feat] add findRelationshipsV3 API (impl + unit tests) #504

Merged
merged 5 commits into from
Mar 7, 2025

Conversation

ybz1013
Copy link
Contributor

@ybz1013 ybz1013 commented Mar 6, 2025

Summary

To support Relationship 2.0 models, which doesnt have source in the relationship itself, we need a new API to return the source in a wrapper class along with the relationship2.0 model.

The internal use is AssetRelationship = source + relationship2.0 (destination only). I didn't want to hardcode the class here, so I left it extendable. User can pass it any RecordTemplate as wrapper class, but the implementation is only for AssetRelationship now.

I added a wrapOptions map in case we want to have other wrapper types in the future. Currently, it acts as a guard to prevent people who doesn't know this API to accidentally use it.

Testing Done

./gradlew build
unit tests with relationship1.0 and 2.0

Checklist

@ybz1013 ybz1013 force-pushed the yanbzhao/find-relationships-v3 branch from 22e2d21 to edc45e1 Compare March 6, 2025 23:46
* @return A list of relationship records in SqlRow (col: source, destination, metadata, etc).
*/
@Nonnull
public <RELATIONSHIP extends RecordTemplate> List<SqlRow> findRelationshipsV2V3Core(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: does this need to be public?

@Nonnull Class<ASSET_RELATIONSHIP> assetRelationshipClass, @Nullable Map<String, Object> wrapOptions,
int offset, int count) {
if (wrapOptions == null) {
throw new IllegalArgumentException("Please check your use of the findRelationshipsV3 method. wrapOptions cannot be null.");
Copy link
Contributor

Choose a reason for hiding this comment

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

If it can't be null why is it @Nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me make a change here to better guard this API.

This is more of a way to alert (potential) user if they dont know what this API does. If someone thinks they can pass in any thing as a wrapper and get a result, I would rather throw them an error here instead of letting it fail randomly later.

private <ASSET_RELATIONSHIP extends RecordTemplate, RELATIONSHIP extends RecordTemplate> ASSET_RELATIONSHIP createAssetRelationshipWrapperForRelationship(
@Nonnull Class<RELATIONSHIP> relationshipType, @Nonnull Class<ASSET_RELATIONSHIP> assetRelationshipClass,
@Nonnull String metadata, @Nonnull String sourceUrn, @Nullable Map<String, Object> wrapOptions) {
// TODO: if other type of ASSET_RELATIONSHIP is needed, we need to distinguish it with wrapOptions and handles differently.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by this? What "other type of ASSET_RELATIONSHIP" can there be? Can you share an example of a wrapOption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since AssetRelationship is an LI internal model, we need to pass it here, so why not make the API params more flexible.

say in the future, we have a AssetRelationshipV2, we can still reuse this API and change the code to handle differently.

the wrapOption can have something like { "relationship.version": "2.0" }, then we check and do parsing differently. Or just anything we may want to use in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

my main concern is we cant keep making new versions of the same API, so adding a map for params can make it more flexible if we want to pass in something new later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that makes sense.

public static final String RELATED_TO = "relatedTo";
public static final String SOURCE = "source";
public static final String METADATA = "metadata";
public static final String ASSET_RELATIONSHIP_TYPE = "asset.relationship.type";
Copy link
Contributor

Choose a reason for hiding this comment

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

what if we just call this something like relationship.return.type? make it more clear

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

@ybz1013 ybz1013 merged commit c59ae86 into linkedin:master Mar 7, 2025
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.

2 participants