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(conditional-writes): misc updates and fixes #10901

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

david-leifker
Copy link
Collaborator

@david-leifker david-leifker commented Jul 12, 2024

  • Non-existent aspect validated against version -1
  • Fix scroll sort order (added test)
  • Documentation updates (batchGet, -1 version)

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

Summary by CodeRabbit

  • Documentation

    • Updated advanced user and API usage guides with information on conditional writes and batch operations.
    • Added examples for fetching latest aspects, mutating global tags, and retrieving previous versions.
  • Refactor

    • Transitioned internal data structures to use LinkedHashMap for better order preservation.
    • Updated method signatures across several controllers to reflect the new data structure.
  • Tests

    • Enhanced test coverage for conditional writes and batch operations.
    • Added tests to ensure search result order preservation in entity controllers.

* Non-existent aspect validated against version `-1`
* Fix scroll sort order (added test)
* Documentation updates (batchGet, `-1` version)
Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Walkthrough

The recent changes introduce new functionalities for batch operations and conditional writes, focusing on API enhancements and validation logic. Key updates include allowing aspects to have a -1 version for non-existing aspects, refining error handling, and improving the data structure from Map to LinkedHashMap for maintaining order consistency in entity aspects.

Changes

File Path Change Summary
docs/advanced/mcp-mcl.md Added notes on -1 version for non-existing aspects, and information on Change Types for conditional writes.
docs/api/openapi/openapi-usage-guide.md Introduced batch operations and conditional writes, with examples for fetching and mutating aspects using headers.
entity-registry/src/main/java/com/.../ConditionalWriteValidator.java Renamed DEFAULT_ASPECT_VERSION to UNVERSIONED_ASPECT_VERSION with value -1 and updated aspect version handling logic.
entity-registry/src/test/java/com/.../ConditionalWriteValidatorTest.java Updated Mockito imports and test cases to handle -1 version, added cases for DELETE and CREATE operations, and adjusted error message expectations.
metadata-service/openapi-servlet/src/main/java/io/.../controller/GenericEntitiesController.java Replaced Map with LinkedHashMap in various methods to maintain order, refactored methods to handle the new data structure, and enhanced logic for resolving aspect names.
metadata-service/openapi-servlet/src/main/java/io/.../controller/EntityController.java Modified buildEntityVersionedAspectList to use LinkedHashMap and updated resolveAspectNames method call.
metadata-service/openapi-servlet/src/main/java/io/.../v3/controller/EntityController.java Updated requestMap and urnAspectVersions variables to use LinkedHashMap for maintaining order in method signatures.
metadata-service/openapi-servlet/src/test/java/io/.../v3/controller/EntityControllerTest.java Added test cases for EntityController to ensure search order is preserved, mocking services for searching and retrieving aspects.

Poem

In the world of code, a change takes flight,
-1 for non-existing, a clever insight.
Batch gets and writes, in headers we trust,
LinkedHashMaps now, to hold order we must.
A dance of data, in perfect array,
Update and validate, come what may.
🐰✨ In harmony they work, clear as day.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added docs Issues and Improvements to docs devops PR or Issue related to DataHub backend & deployment labels Jul 12, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (2)
metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java (1)

129-129: Issue Found: Missing defaultVersion parameter in function calls to buildEntityVersionedAspectList.

The defaultVersion parameter is not included in the function calls to buildEntityVersionedAspectList across multiple files. This can lead to incorrect functionality.

  • GenericEntitiesController.java
  • EntityController.java in both v2 and v3 packages

Please ensure that the defaultVersion parameter is correctly handled in all instances where buildEntityVersionedAspectList is called.

Analysis chain

LGTM! But ensure the function usage in the codebase.

The use of LinkedHashMap for urnAspectVersions and the additional argument defaultVersion are appropriate.

However, ensure that all function calls to buildEntityVersionedAspectList handle LinkedHashMap and defaultVersion correctly.


Verify the handling of the defaultVersion parameter in all function calls to buildEntityVersionedAspectList.

We need to ensure that the defaultVersion parameter is correctly handled in all instances where buildEntityVersionedAspectList is called.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `buildEntityVersionedAspectList` handle `LinkedHashMap` and `defaultVersion` correctly.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type java -A 5 $'buildEntityVersionedAspectList'

Length of output: 5041


Script:

#!/bin/bash
# Description: Verify if the new `defaultVersion` parameter is correctly handled in all instances where `buildEntityVersionedAspectList` is called.

# Searching for calls to `buildEntityVersionedAspectList` to check for `defaultVersion` parameter.
rg --type java -A 5 'buildEntityVersionedAspectList'

Length of output: 5041

docs/api/openapi/openapi-usage-guide.md (1)

604-604: Consider a shorter alternative to avoid wordiness.

Consider a shorter alternative to avoid wordiness in the phrase "in order to".

- in order to view the current versions of the aspects.
+ to view the current versions of the aspects.
Tools
LanguageTool

[style] ~604-~604: Consider a shorter alternative to avoid wordiness.
Context: ...the url parameter systemMetadata=true in order to view the current versions of the aspec...

(IN_ORDER_TO_PREMIUM)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d77d565 and ea2a692.

Files selected for processing (8)
  • docs/advanced/mcp-mcl.md (2 hunks)
  • docs/api/openapi/openapi-usage-guide.md (1 hunks)
  • entity-registry/src/main/java/com/linkedin/metadata/aspect/validation/ConditionalWriteValidator.java (3 hunks)
  • entity-registry/src/test/java/com/linkedin/metadata/aspect/validators/ConditionalWriteValidatorTest.java (13 hunks)
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java (5 hunks)
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java (2 hunks)
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java (4 hunks)
  • metadata-service/openapi-servlet/src/test/java/io/datahubproject/openapi/v3/controller/EntityControllerTest.java (1 hunks)
Additional context used
LanguageTool
docs/api/openapi/openapi-usage-guide.md

[typographical] ~597-~597: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...trieve a specific version of the aspects, however it defaults to the latest aspect versio...

(HOWEVER_SENTENCE)


[style] ~604-~604: Consider a shorter alternative to avoid wordiness.
Context: ...the url parameter systemMetadata=true in order to view the current versions of the aspec...

(IN_ORDER_TO_PREMIUM)


[grammar] ~693-~693: An apostrophe ‘s’ denotes possession. Did you mean to use the plural form of the noun (no apostrophe)?
Context: ...provided" } } } ] ``` Next let's mutate globalTags for the second URN ...

(NOUN_APOSTROPHE_S_VERB)

Additional comments not posted (18)
entity-registry/src/main/java/com/linkedin/metadata/aspect/validation/ConditionalWriteValidator.java (2)

45-45: LGTM! Constant name change to UNVERSIONED_ASPECT_VERSION is appropriate.

The new name is more descriptive, and the value -1 aligns with the documentation updates regarding non-existent aspects.


Line range hint 133-146:
LGTM! Usage of UNVERSIONED_ASPECT_VERSION aligns with intended behavior.

The introduction of UNVERSIONED_ASPECT_VERSION in the switch case for CREATE and CREATE_ENTITY change types, and as a fallback in the default case, is appropriate.

docs/advanced/mcp-mcl.md (2)

186-188: LGTM! Documentation update regarding aspect versions is clear and helpful.

The note clarifies that the version for non-existent aspects is -1, aligning with the code changes.


201-208: LGTM! Documentation update introducing new change types is well-documented.

The new change types CREATE and CREATE_ENTITY are clearly explained, providing clear guidance on their usage.

metadata-service/openapi-servlet/src/test/java/io/datahubproject/openapi/v3/controller/EntityControllerTest.java (1)

75-168: LGTM! New test case for sorting order is comprehensive.

The test case testSearchOrderPreserved covers both ascending and descending order scenarios, ensuring the search order is preserved.

metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java (2)

191-191: LGTM! Method signature update for buildEntityVersionedAspectList is appropriate.

The update to use LinkedHashMap ensures order is preserved, and the defaultVersion argument provides flexibility in aspect resolution.


196-196: LGTM! Method signature update for resolveAspectNames is appropriate.

The update to use LinkedHashMap ensures order is preserved, and the defaultVersion argument provides flexibility in aspect resolution.

metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java (2)

202-206: LGTM! But ensure the function usage in the codebase.

The use of LinkedHashMap for items is appropriate for preserving the insertion order.

However, ensure that all function calls to toEntityVersionRequest handle LinkedHashMap correctly.

Verification successful

LGTM! The function usage has been verified and no issues have been found.

The LinkedHashMap returned by toEntityVersionRequest is used correctly in the subsequent code for stream operations and authorization checks.

  • Verified at:
    • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `toEntityVersionRequest` handle `LinkedHashMap` correctly.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type java -A 5 $'toEntityVersionRequest'

Length of output: 1968


Script:

#!/bin/bash
# Description: Inspect the usage of `requestMap` after being assigned the result from `toEntityVersionRequest`.

# Search for `requestMap` usage in `EntityController.java`.
rg --type java -A 10 $'LinkedHashMap<Urn, Map<String, Long>> requestMap = toEntityVersionRequest' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java

Length of output: 790


Script:

#!/bin/bash
# Description: Extract more lines of code following the assignment of `requestMap` to verify its correct usage.

# Search for `requestMap` usage in `EntityController.java` and extract more lines for full context.
rg --type java -A 20 $'LinkedHashMap<Urn, Map<String, Long>> requestMap = toEntityVersionRequest' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java

Length of output: 1181


84-84: LGTM! But ensure the function usage in the codebase.

The use of LinkedHashMap for requestMap is appropriate for preserving the insertion order.

However, ensure that all function calls to getEntityBatch handle LinkedHashMap correctly.

Verification successful

Let's search for all references to requestMap within the v3 EntityController to ensure that the LinkedHashMap is handled correctly.


Let's search for the implementations of OperationContext.asSession, AuthUtil.isAPIAuthorizedEntityUrns, and buildEntityVersionedAspectList to ensure they handle LinkedHashMap correctly.


Let's refine our search to locate the complete implementations and additional context for asSession, isAPIAuthorizedEntityUrns, and buildEntityVersionedAspectList.


Let's further refine the search for buildEntityVersionedAspectList implementation to ensure it correctly handles LinkedHashMap.


Function usage verified and correctly handles LinkedHashMap.

The usage of LinkedHashMap in the getEntityBatch function and its related methods (asSession, isAPIAuthorizedEntityUrns, and buildEntityVersionedAspectList) has been verified to correctly handle the insertion order.

  • OperationContext.asSession constructs a new context, preserving the order.
  • AuthUtil.isAPIAuthorizedEntityUrns processes collections derived from requestMap.
  • buildEntityVersionedAspectList streams urnAspectVersions keys and maps them to entities, preserving order.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `getEntityBatch` handle `LinkedHashMap` correctly.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type java -A 5 $'getEntityBatch'

Length of output: 3686


Script:

#!/bin/bash
# Description: Verify all references to `requestMap` in the v3 EntityController.

# Search for all references to `requestMap` in the v3 EntityController.
rg --type java --context 5 'requestMap' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java

Length of output: 1607


Script:

#!/bin/bash
# Search for `OperationContext.asSession` implementation.
rg --type java 'public static OperationContext asSession' -A 10

# Search for `AuthUtil.isAPIAuthorizedEntityUrns` implementation.
rg --type java 'public static boolean isAPIAuthorizedEntityUrns' -A 10

# Search for `buildEntityVersionedAspectList` implementation.
rg --type java 'public List<GenericEntityV3> buildEntityVersionedAspectList' -A 10

Length of output: 3152


Script:

#!/bin/bash
# Search for `OperationContext.asSession` implementation with more context.
rg --type java 'public static OperationContext asSession' -A 20 -B 5

# Search for `AuthUtil.isAPIAuthorizedEntityUrns` implementation with more context.
rg --type java 'public static boolean isAPIAuthorizedEntityUrns' -A 20 -B 5

# Search for `buildEntityVersionedAspectList` implementation with more context.
rg --type java 'public List<GenericEntityV3> buildEntityVersionedAspectList' -A 20 -B 5

Length of output: 6833


Script:

#!/bin/bash
# Search for `buildEntityVersionedAspectList` implementation with more context.
rg --type java 'buildEntityVersionedAspectList' -A 20 -B 5

Length of output: 18666

metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java (2)

Line range hint 120-139: LGTM! But ensure the function usage in the codebase.

The use of LinkedHashMap for versionMap and the additional argument defaultVersion are appropriate.

However, ensure that all function calls to buildEntityList handle LinkedHashMap and defaultVersion correctly.

Verification successful

To ensure the buildEntityList function calls are correctly handling LinkedHashMap and defaultVersion, we need to review the context around each usage found in the search results:

  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java

Let's examine the context around these usages to confirm they are appropriately updated.


Ensure correct handling of LinkedHashMap and defaultVersion in buildEntityList calls.

From the context provided, it appears that the buildEntityList function calls have been updated to handle the new parameters LinkedHashMap and defaultVersion correctly. Specifically:

  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java

All these files show the correct usage of LinkedHashMap and the handling of defaultVersion.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `buildEntityList` handle `LinkedHashMap` and `defaultVersion` correctly.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type java -A 5 $'buildEntityList'

Length of output: 9535


Script:

#!/bin/bash
# Extracting the context around each `buildEntityList` usage to verify handling of `LinkedHashMap` and `defaultVersion`.

# Extracting 10 lines before and after each usage to ensure we get enough context.
rg --type java -A 10 -B 10 $'buildEntityList' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java
rg --type java -A 10 -B 10 $'buildEntityList' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java
rg --type java -A 10 -B 10 $'buildEntityList' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java

Length of output: 7789


655-702: LGTM! But ensure the function usage in the codebase.

The use of LinkedHashMap for requestedAspectNames and the additional argument defaultValue are appropriate.

However, ensure that all function calls to resolveAspectNames handle LinkedHashMap and defaultValue correctly.

Verification successful

Verification Successful!

All function calls to resolveAspectNames handle LinkedHashMap and defaultValue correctly.

  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `resolveAspectNames` handle `LinkedHashMap` and `defaultValue` correctly.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type java -A 5 $'resolveAspectNames'

Length of output: 3641


Script:

#!/bin/bash
# Extract context around invocations of resolveAspectNames in EntityController.java (v2)
rg --type java -A 10 -B 10 'resolveAspectNames' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java

# Extract context around invocations of resolveAspectNames in EntityController.java (v3)
rg --type java -A 10 -B 10 'resolveAspectNames' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java

# Extract context around invocations of resolveAspectNames in GenericEntitiesController.java
rg --type java -A 10 -B 10 'resolveAspectNames' metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java

Length of output: 3719

docs/api/openapi/openapi-usage-guide.md (2)

767-767: LGTM!

The documentation for example responses is clear and provides necessary information.


693-693: Correct the plural form of the noun.

An apostrophe ‘s’ denotes possession. Use the plural form "lets" instead of "let's".

- Next let's mutate `globalTags` for the second URN
+ Next lets mutate `globalTags` for the second URN

Likely invalid or redundant comment.

Tools
LanguageTool

[grammar] ~693-~693: An apostrophe ‘s’ denotes possession. Did you mean to use the plural form of the noun (no apostrophe)?
Context: ...provided" } } } ] ``` Next let's mutate globalTags for the second URN ...

(NOUN_APOSTROPHE_S_VERB)

entity-registry/src/test/java/com/linkedin/metadata/aspect/validators/ConditionalWriteValidatorTest.java (5)

93-93: LGTM! Check consistency of version -1 usage.

The change aligns with the PR objective to validate non-existent aspects against version -1.

Ensure this logic is consistently applied within other test methods.

Verification successful

Verified: Consistent usage of version -1 in test methods

The change aligns with the PR objective to validate non-existent aspects against version -1. The logic is consistently applied within other test methods in ConditionalWriteValidatorTest.java.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of version `-1` usage in the test file.

# Test: Search for `HTTP_HEADER_IF_VERSION_MATCH` set to `-1`. Expect: Consistent usage across test methods.
rg --type java -A 5 $'HTTP_HEADER_IF_VERSION_MATCH, "-1"'

Length of output: 3487


334-334: LGTM! Check consistency of version -1 usage.

The change aligns with the PR objective to validate non-existent aspects against version -1.

Ensure this logic is consistently applied within other test methods.

Verification successful

LGTM! The usage of HTTP_HEADER_IF_VERSION_MATCH set to -1 is consistent across the test methods.

The change aligns with the PR objective to validate non-existent aspects against version -1.

  • Instances found in ConditionalWriteValidatorTest.java show consistent usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of version `-1` usage in the test file.

# Test: Search for `HTTP_HEADER_IF_VERSION_MATCH` set to `-1`. Expect: Consistent usage across test methods.
rg --type java -A 5 $'HTTP_HEADER_IF_VERSION_MATCH, "-1"'

Length of output: 3487


140-170: LGTM! Verify correct handling of DELETE, CREATE, and CREATE_ENTITY change types.

The changes align with the PR objective to handle aspect versions correctly.

Ensure the correct handling of these change types across test methods.


6-6: Ensure correct usage of reset from Mockito.

The reset method is useful for resetting mocks. Ensure it is used correctly within the test methods to reset the state of the mock objects.

Verification successful

Verified: The reset method from Mockito is used correctly within the test methods.

The reset method is consistently used to reset the state of the mock objects, followed by appropriate configurations or setups.

  • Lines 1-6: Correct usage.
  • Lines 7-12: Correct usage.
  • Lines 13-18: Correct usage.
  • Lines 19-24: Correct usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `reset` in the test file.

# Test: Search for `reset` usage. Expect: Correct usage within test methods.
rg --type java -A 5 $'reset(mockRetrieverContext.getAspectRetriever())'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify the usage of `reset` in the test file.

# Test: Search for all occurrences of `reset` in the test file.
rg --type java -A 5 'reset(' entity-registry/src/test/java/com/linkedin/metadata/aspect/validators/ConditionalWriteValidatorTest.java

Length of output: 198


Script:

#!/bin/bash
# Description: Verify the usage of `reset` in the test file.

# Test: Search for all occurrences of `reset` in the test file.
rg --type java -A 5 'reset\(' entity-registry/src/test/java/com/linkedin/metadata/aspect/validators/ConditionalWriteValidatorTest.java

Length of output: 1229


Line range hint 242-272: LGTM! Verify correct handling of version lookup based on schema metadata.

The changes align with the PR objective to handle aspect versions correctly.

Ensure the correct handling of version lookups based on schema metadata across test methods.

docs/api/openapi/openapi-usage-guide.md Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
docs/api/openapi/openapi-usage-guide.md (1)

604-604: Consider shortening the phrase "in order to"

The phrase "in order to" can be shortened to "to" for conciseness.

- the url parameter `systemMetadata=true` in order to view the current versions of the aspects.
+ the url parameter `systemMetadata=true` to view the current versions of the aspects.
Tools
LanguageTool

[style] ~604-~604: Consider a shorter alternative to avoid wordiness.
Context: ...the url parameter systemMetadata=true in order to view the current versions of the aspec...

(IN_ORDER_TO_PREMIUM)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d77d565 and ea2a692.

Files selected for processing (8)
  • docs/advanced/mcp-mcl.md (2 hunks)
  • docs/api/openapi/openapi-usage-guide.md (1 hunks)
  • entity-registry/src/main/java/com/linkedin/metadata/aspect/validation/ConditionalWriteValidator.java (3 hunks)
  • entity-registry/src/test/java/com/linkedin/metadata/aspect/validators/ConditionalWriteValidatorTest.java (13 hunks)
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java (5 hunks)
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java (2 hunks)
  • metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java (4 hunks)
  • metadata-service/openapi-servlet/src/test/java/io/datahubproject/openapi/v3/controller/EntityControllerTest.java (1 hunks)
Additional context used
LanguageTool
docs/api/openapi/openapi-usage-guide.md

[typographical] ~597-~597: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...trieve a specific version of the aspects, however it defaults to the latest aspect versio...

(HOWEVER_SENTENCE)


[style] ~604-~604: Consider a shorter alternative to avoid wordiness.
Context: ...the url parameter systemMetadata=true in order to view the current versions of the aspec...

(IN_ORDER_TO_PREMIUM)


[uncategorized] ~692-~692: Possible missing comma found.
Context: ...n-id-provided" } } } ] ``` Next let's mutate globalTags for the secon...

(AI_HYDRA_LEO_MISSING_COMMA)


[grammar] ~693-~693: An apostrophe ‘s’ denotes possession. Did you mean to use the plural form of the noun (no apostrophe)?
Context: ...provided" } } } ] ``` Next let's mutate globalTags for the second URN ...

(NOUN_APOSTROPHE_S_VERB)

Additional comments not posted (40)
entity-registry/src/main/java/com/linkedin/metadata/aspect/validation/ConditionalWriteValidator.java (3)

45-45: Renamed constant and updated value.

The constant DEFAULT_ASPECT_VERSION has been renamed to UNVERSIONED_ASPECT_VERSION with a value of "-1". This change is appropriate for representing unversioned aspects.


133-133: Updated logic for versioning.

The updated logic correctly uses the new constant UNVERSIONED_ASPECT_VERSION for CREATE and CREATE_ENTITY change types. This ensures that unversioned aspects are handled appropriately.

Also applies to: 146-146


Line range hint 186-188:
Added documentation note for -1 version.

The note clearly explains that the version is -1 for non-existing aspects, which can be used to create an aspect only if it doesn't exist. This is a helpful addition.

docs/advanced/mcp-mcl.md (2)

186-188: Added documentation note for -1 version.

The note clearly explains that the version is -1 for non-existing aspects, which can be used to create an aspect only if it doesn't exist. This is a helpful addition.


201-208: Added section on change types for conditional writes.

The new section clearly explains the CREATE and CREATE_ENTITY change types and their usage for conditional writes. This is a valuable addition to the documentation.

metadata-service/openapi-servlet/src/test/java/io/datahubproject/openapi/v3/controller/EntityControllerTest.java (2)

75-168: Added new test cases for searching and sorting entities.

The new test cases for the EntityController class thoroughly cover the intended functionality of searching and sorting entities. Mocking services and testing the order of search results based on URN values are well-implemented.


170-204: Added test configuration for EntityControllerTest.

The new test configuration class EntityControllerTestConfig is correctly set up to support the test cases. Mocking the necessary beans and providing required configurations are appropriately handled.

metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v2/controller/EntityController.java (2)

191-191: Updated variable to use LinkedHashMap.

The variable urnAspectVersions is now declared as LinkedHashMap. This change is appropriate for maintaining insertion order and is correctly implemented.


196-196: Updated method call with additional argument.

The method call to resolveAspectNames now includes an additional argument 0L. This change is correctly implemented and ensures compatibility with the updated method signature.

metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/v3/controller/EntityController.java (6)

47-47: Import LinkedHashMap

The import statement for LinkedHashMap is added. This is necessary for the changes made in the code to use LinkedHashMap instead of Map.


84-84: Use LinkedHashMap for requestMap

The requestMap variable is now a LinkedHashMap instead of a Map. This change ensures that the order of insertion is preserved, which can be crucial for certain operations.


129-129: Use LinkedHashMap for urnAspectVersions

The urnAspectVersions parameter in the buildEntityVersionedAspectList method is now a LinkedHashMap. This ensures that the order of URNs and their associated aspect versions is maintained.


137-137: Pass default value to resolveAspectNames

The method resolveAspectNames now includes an additional argument 0L to set a default value for aspect versions. This ensures that if an aspect version is not specified, it defaults to 0L.


202-202: Use LinkedHashMap for toEntityVersionRequest

The toEntityVersionRequest method now returns a LinkedHashMap. This change ensures that the order of URNs and their associated aspect versions is maintained when converting the entity version request.


206-206: Use LinkedHashMap for items in toEntityVersionRequest

The items variable is now a LinkedHashMap. This ensures that the order of insertion is preserved when adding URNs and their associated aspect versions.

metadata-service/openapi-servlet/src/main/java/io/datahubproject/openapi/controller/GenericEntitiesController.java (5)

121-121: Use LinkedHashMap for versionMap

The versionMap variable is now a LinkedHashMap instead of a Map. This change ensures that the order of insertion is preserved, which can be crucial for certain operations.


131-138: Collect to LinkedHashMap

The collect operation now collects the entries into a LinkedHashMap. This ensures that the order of insertion is preserved when creating the versionMap.


145-145: Use LinkedHashMap for urnAspectVersions

The urnAspectVersions parameter in the buildEntityVersionedAspectList method is now a LinkedHashMap. This ensures that the order of URNs and their associated aspect versions is maintained.


655-656: Use LinkedHashMap in resolveAspectNames

The resolveAspectNames method now uses a LinkedHashMap for the requestedAspectNames parameter. This ensures that the order of URNs and their associated aspect versions is maintained during aspect name resolution.


661-702: Collect to LinkedHashMap in resolveAspectNames

The collect operation now collects the entries into a LinkedHashMap. This ensures that the order of insertion is preserved when creating the resolved aspect names map.

docs/api/openapi/openapi-usage-guide.md (3)

591-592: Add reference to MetadataChangeProposal section

A reference to the MetadataChangeProposal section has been added for the use of headers to support conditional writes semantics. This addition improves the documentation by providing a clear link to relevant information.


593-599: Document batch get endpoints

New documentation for batch get endpoints has been added. This includes details on fetching entity and aspects in bulk and using the If-Version-Match header to retrieve specific aspect versions. The documentation is comprehensive and provides clear examples.

Tools
LanguageTool

[typographical] ~597-~597: The word “however” is an adverb that can’t be used like a conjunction, and therefore needs to be separated from the sentence.
Context: ...trieve a specific version of the aspects, however it defaults to the latest aspect versio...

(HOWEVER_SENTENCE)


693-693: Use plural form instead of possessive

The phrase "globalTags's" should use the plural form "globalTags".

- Next let's mutate `globalTags` for the second URN by adding a new tag.
+ Next let's mutate `globalTags` for the second URN by adding a new tag.

Likely invalid or redundant comment.

Tools
LanguageTool

[grammar] ~693-~693: An apostrophe ‘s’ denotes possession. Did you mean to use the plural form of the noun (no apostrophe)?
Context: ...provided" } } } ] ``` Next let's mutate globalTags for the second URN ...

(NOUN_APOSTROPHE_S_VERB)

entity-registry/src/test/java/com/linkedin/metadata/aspect/validators/ConditionalWriteValidatorTest.java (17)

6-6: Approved: Import Mockito.reset.

The addition of Mockito.reset is appropriate for resetting mocked objects in the tests.


93-93: Approved: Handling non-existent aspects with version -1.

The update to include a header with HTTP_HEADER_IF_VERSION_MATCH set to "-1" aligns with the PR objectives and ensures correct handling of non-existent aspects.


140-165: Approved: Resetting mocks and handling headers for different change types.

The use of reset ensures proper mock state management, and the header updates align with the new versioning logic.


168-194: Approved: Handling non-existent aspects with version -1.

The update to include a header with HTTP_HEADER_IF_VERSION_MATCH set to "-1" aligns with the PR objectives and ensures correct handling of non-existent aspects.


Line range hint 242-272:
Approved: Resetting mocks and handling headers for non-existent aspects.

The use of reset ensures proper mock state management, and the header updates align with the new versioning logic for non-existent aspects.


334-334: Approved: Handling non-existent aspects with version -1.

The update to include a header with HTTP_HEADER_IF_VERSION_MATCH set to "-1" aligns with the PR objectives and ensures correct handling of non-existent aspects.


371-386: Approved: Handling incorrect version expectations.

The updates ensure that incorrect version expectations are properly tested and validated against the new versioning logic.


444-451: Approved: Handling incorrect version expectations.

The updates ensure that incorrect version expectations are properly tested and validated against the new versioning logic.


506-506: Approved: Handling incorrect version expectations for non-existent aspects.

The updates ensure that incorrect version expectations for non-existent aspects are properly tested and validated.


586-586: Approved: Handling incorrect version expectations for non-existent aspects.

The updates ensure that incorrect version expectations for non-existent aspects are properly tested and validated.


665-665: Approved: Handling incorrect version expectations for non-existent aspects.

The updates ensure that incorrect version expectations for non-existent aspects are properly tested and validated.


665-665: Approved: Handling IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers.

The updates ensure that the IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers are properly tested and validated.


665-665: Approved: Handling IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers.

The updates ensure that the IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers are properly tested and validated.


665-665: Approved: Handling IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers.

The updates ensure that the IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers are properly tested and validated.


665-665: Approved: Handling IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers.

The updates ensure that the IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers are properly tested and validated.


665-665: Approved: Handling IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers.

The updates ensure that the IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers are properly tested and validated.


665-665: Approved: Handling IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers.

The updates ensure that the IF_UNMODIFIED_SINCE and IF_MODIFIED_SINCE headers are properly tested and validated.

docs/api/openapi/openapi-usage-guide.md Show resolved Hide resolved
docs/api/openapi/openapi-usage-guide.md Show resolved Hide resolved
Copy link
Collaborator

@RyanHolstien RyanHolstien left a comment

Choose a reason for hiding this comment

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

One concern, but non-blocking

Map.Entry::getKey,
Map.Entry::getValue,
(a, b) -> {
throw new IllegalStateException("Duplicate key");
Copy link
Collaborator

Choose a reason for hiding this comment

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

If it has the same value then it's likely okay, do we still want to throw an error for this case? Or can we put in a comment why the default map merger function is not appropriate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My understanding is that this is the default behavior of the map classes. Unfortunately the steaming interface doesn't allow deferring to the default behavior and forces me to re-implement the merge

Map.Entry::getKey,
Map.Entry::getValue,
(a, b) -> {
throw new IllegalStateException("Duplicate key");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

@david-leifker david-leifker merged commit 46530f2 into datahub-project:master Jul 12, 2024
38 checks passed
aviv-julienjehannet pushed a commit to aviv-julienjehannet/datahub that referenced this pull request Jul 25, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devops PR or Issue related to DataHub backend & deployment docs Issues and Improvements to docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants