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(collections): quad collection #21090

Merged
merged 15 commits into from
Aug 11, 2024
Merged

Conversation

oren-lava
Copy link
Contributor

@oren-lava oren-lava commented Jul 26, 2024

Description

Closes: #21061

Implemented a Quad collection to allow composite keys of 4 parts.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced a new data structure, Quad, for managing composite keys with enhanced type safety.
    • Added functionality for creating Quad instances and accessing individual keys.
    • Implemented JSON encoding/decoding and efficient binary handling for Quad keys.
  • Tests

    • Added comprehensive unit tests to validate the behavior of Quad and its key management functionalities.

@oren-lava oren-lava requested a review from a team as a code owner July 26, 2024 11:28
Copy link
Contributor

coderabbitai bot commented Jul 26, 2024

Walkthrough

Walkthrough

The changes introduce a new Quad collection in the collections package, enabling the handling of composite keys composed of four elements. This enhancement allows for type-safe operations on multi-key collections, supporting various functionalities such as key access, JSON serialization, and efficient binary encoding. Additionally, unit tests are added to ensure proper functionality and correctness of the new features.

Changes

Files Change Summary
collections/quad.go Introduced a Quad type for composite keys of four elements. Added functions for creation, accessors, JSON encoding/decoding, buffer operations, size calculation, and range queries.
collections/quad_test.go Added unit tests for QuadKeyCodec and key operations, validating functionality with multiple types and prefix conditions.

Assessment against linked issues

Objective Addressed Explanation
Implement a Quad collection for composite keys of four elements. (#21061)

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 Configuration 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.

@julienrbrt julienrbrt changed the title feat: Quad collection feat(collections): quad collection Jul 26, 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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5c90246 and 7edcf7a.

Files selected for processing (2)
  • collections/quad.go (1 hunks)
  • collections/quad_test.go (1 hunks)
Additional context used
Path-based instructions (2)
collections/quad_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/quad.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (25)
collections/quad_test.go (2)

13-18: LGTM!

The TestQuad function correctly tests the conformance of the QuadKeyCodec. The use of colltest.TestKeyCodec ensures that the codec is tested comprehensively.


21-60: LGTM!

The TestQuadRange function comprehensively tests the range operations for the Quad collection. The test covers various scenarios, including prefix and super prefix queries.

collections/quad.go (23)

11-17: LGTM!

The Quad struct is well-defined and follows best practices for defining multipart keys.


19-22: LGTM!

The Join4 function is correctly implemented and follows best practices for instantiating a new Quad instance.


24-30: LGTM!

The K1 function is correctly implemented and follows best practices for returning the first part of the key.


32-38: LGTM!

The K2 function is correctly implemented and follows best practices for returning the second part of the key.


40-46: LGTM!

The K3 function is correctly implemented and follows best practices for returning the third part of the key.


56-59: LGTM!

The QuadPrefix function is correctly implemented and follows best practices for creating a new Quad instance composed only of the first part of the key.


61-64: LGTM!

The QuadSuperPrefix function is correctly implemented and follows best practices for creating a new Quad instance composed only of the first two parts of the key.


66-69: LGTM!

The QuadSuperPrefix3 function is correctly implemented and follows best practices for creating a new Quad instance composed only of the first three parts of the key.


71-80: LGTM!

The QuadKeyCodec function is correctly implemented and follows best practices for instantiating a new KeyCodec instance that can encode the Quad.


91-113: LGTM!

The EncodeJSON function is correctly implemented and follows best practices for encoding the Quad into JSON format.


115-143: LGTM!

The DecodeJSON function is correctly implemented and follows best practices for decoding the Quad from JSON format.


145-185: LGTM!

The Stringify function is correctly implemented and follows best practices for converting the Quad into a string representation.


187-189: LGTM!

The KeyType function is correctly implemented and follows best practices for returning the type of the key.


191-221: LGTM!

The Encode function is correctly implemented and follows best practices for encoding the Quad into a byte buffer.


224-247: LGTM!

The Decode function is correctly implemented and follows best practices for decoding the Quad from a byte buffer.


249-264: LGTM!

The Size function is correctly implemented and follows best practices for returning the size of the Quad key.


266-296: LGTM!

The EncodeNonTerminal function is correctly implemented and follows best practices for encoding the Quad into a byte buffer, excluding the terminal key.


299-321: LGTM!

The DecodeNonTerminal function is correctly implemented and follows best practices for decoding the Quad from a byte buffer, excluding the terminal key.


324-339: LGTM!

The SizeNonTerminal function is correctly implemented and follows best practices for returning the size of the Quad key, excluding the terminal key.


341-348: LGTM!

The NewPrefixUntilQuadRange function is correctly implemented and follows best practices for defining a collection query which ranges until the provided Quad prefix.


350-358: LGTM!

The NewPrefixedQuadRange function is correctly implemented and follows best practices for providing a Range for all keys prefixed with the given first part of the Quad key.


360-368: LGTM!

The NewSuperPrefixedQuadRange function is correctly implemented and follows best practices for providing a Range for all keys prefixed with the given first and second parts of the Quad key.


370-378: LGTM!

The NewSuperPrefixedQuadRange3 function is correctly implemented and follows best practices for providing a Range for all keys prefixed with the given first, second, and third parts of the Quad key.

collections/quad.go Outdated 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: 1

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5c90246 and 7edcf7a.

Files selected for processing (2)
  • collections/quad.go (1 hunks)
  • collections/quad_test.go (1 hunks)
Additional context used
Path-based instructions (2)
collections/quad_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

collections/quad.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

Additional comments not posted (13)
collections/quad_test.go (2)

13-18: LGTM!

The TestQuad function correctly tests the conformance of the QuadKeyCodec using a sample key.


21-60: LGTM!

The TestQuadRange function comprehensively tests the range functionality of the Quad collection, covering multiple range queries and validating the results.

collections/quad.go (11)

19-22: LGTM!

The Join4 function correctly creates a new Quad instance with four keys.


24-29: LGTM!

The K1 function correctly returns the first part of the key or the zero value if nil.


32-37: LGTM!

The K2 function correctly returns the second part of the key or the zero value if nil.


40-45: LGTM!

The K3 function correctly returns the third part of the key or the zero value if nil.


56-59: LGTM!

The QuadPrefix function correctly creates a new Quad instance with only the first part of the key.


61-64: LGTM!

The QuadSuperPrefix function correctly creates a new Quad instance with the first two parts of the key.


66-69: LGTM!

The QuadSuperPrefix3 function correctly creates a new Quad instance with the first three parts of the key.


71-79: LGTM!

The QuadKeyCodec function correctly creates a new KeyCodec instance for the Quad key.


91-112: LGTM!

The EncodeJSON method correctly encodes a Quad key to JSON format.


115-142: LGTM!

The DecodeJSON method correctly decodes a Quad key from JSON format.


145-185: LGTM!

The Stringify method correctly converts a Quad key to a string representation.

collections/quad.go Outdated 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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7edcf7a and d3c6245.

Files selected for processing (1)
  • collections/quad.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • collections/quad.go

collections/quad.go Outdated Show resolved Hide resolved
oren-lava and others added 2 commits July 29, 2024 16:41
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
@oren-lava oren-lava requested a review from facundomedica July 29, 2024 13:41
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: 0

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d3c6245 and 20d474b.

Files selected for processing (1)
  • collections/quad.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • collections/quad.go

@testinginprod testinginprod self-requested a review August 8, 2024 07:18
Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

lgtm

@tac0turtle tac0turtle enabled auto-merge August 11, 2024 08:56
@tac0turtle tac0turtle added this pull request to the merge queue Aug 11, 2024
Merged via the queue into cosmos:main with commit e30dc06 Aug 11, 2024
70 of 72 checks passed
@julienrbrt
Copy link
Member

We should add a changelog

julienrbrt added a commit that referenced this pull request Aug 14, 2024
@amaury1093
Copy link
Contributor

amaury1093 commented Oct 1, 2024

Any chance we can tag a new cosmossdk.io/collections tag with this feature, that's compatible with 0.50?

(hi everyone btw 👋 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Quad Collection
7 participants