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

PM- added testing case for sorting data from storage #1458

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

pm-dimagi
Copy link

@pm-dimagi pm-dimagi commented Feb 4, 2025

Product Description

Test cases to test the sorting of an table from the storage through SQL query

Technical Summary

Sort function take the field through which sorting need to be done and take value ASC or DESC to describe the order of the sorting

Safety Assurance

Safety story

there is the test case written so it is all passed so there is no safety threat in this

Automated test coverage

Local test cases written

QA Plan

Special deploy instructions

  • This PR can be deployed after merge with no further considerations.

Rollback instructions

  • This PR can be reverted after deploy with no further considerations.

Review

  • The set of people pinged as reviewers is appropriate for the level of risk of the change.

Duplicate PR

Automatically duplicate this PR as defined in contributing.md.

Summary by CodeRabbit

  • New Features

    • Introduced enhanced record retrieval capabilities that allow users to fetch data sorted by specified fields. Sorting can be done in ascending or descending order based on provided criteria, offering more flexible data management.
  • Tests

    • Updated automated tests to validate the new sorting functionality and ensure consistent, correct ordering of records in various scenarios.

Copy link

coderabbitai bot commented Feb 4, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request adds a new method, getSortedRecordsForValues, to the IStorageUtilityIndexed interface and its implementation in the DummyIndexedStorageUtility class. The method accepts metadata field names, corresponding values, and an order-by string to return sorted records. Additionally, a helper method using reflection is introduced to retrieve field values, and the test suite is updated with a new array of Shoe instances and assertions to verify the sorted retrieval functionality.

Changes

File Change Summary
src/main/.../IStorageUtilityIndexed.java Added the method getSortedRecordsForValues(String[] metaFieldNames, Object[] values, String orderby) to the interface.
src/main/.../DummyIndexedStorageUtility.java Implemented getSortedRecordsForValues with Java reflection for ordering and introduced the private helper method getFieldValue for field retrieval.
src/test/.../IndexedStorageUtilityTests.java Added a new array fiveSortedSizesOfMensAddidas of Shoe objects, updated test methods to verify sorted records retrieval, and included storage writes for the new data.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Interface as IStorageUtilityIndexed
    participant Dummy as DummyIndexedStorageUtility
    participant Reflect as Reflection (getFieldValue)

    Test->>Interface: call getSortedRecordsForValues(metaFieldNames, values, orderby)
    Interface->>Dummy: delegate call to getSortedRecordsForValues
    Dummy->>Reflect: retrieve field values for each record
    Reflect-->>Dummy: return field value
    Dummy-->>Test: return sorted record list
Loading

Poem

I'm a little rabbit with a code-filled heart,
Hopping through records and sorting each part.
Carrots of metadata, lined up just right,
Reflecting on fields in the soft moonlight.
I celebrate these changes with a joyful leap and delight!


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@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: 6

🧹 Nitpick comments (1)
src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java (1)

132-133: Add assertion message for better test failure diagnostics.

The assertion message incorrectly references "vans" instead of "adidas".

-        Assert.assertArrayEquals("Failed index match [brand,style][vans,mens]", fiveSortedSizesOfMensAddidas,matchedSortedRecords.toArray());
+        Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", fiveSortedSizesOfMensAdidas,matchedSortedRecords.toArray());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9e7c69 and 92395b2.

📒 Files selected for processing (3)
  • src/main/java/org/javarosa/core/services/storage/IStorageUtilityIndexed.java (1 hunks)
  • src/main/java/org/javarosa/core/services/storage/util/DummyIndexedStorageUtility.java (2 hunks)
  • src/test/java/org/javarosa/core/storage/IndexedStorageUtilityTests.java (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed

@pm-dimagi
Copy link
Author

@coderabbitai I pushed a fix in commit f2a04ae, please review it

Copy link

coderabbitai bot commented Feb 4, 2025

@pm-dimagi The changes look good! You've made several improvements:

  1. Enhanced documentation and parameter validation
  2. Added proper null handling in the comparator
  3. Improved error handling
  4. Fixed the "Adidas" spelling
  5. Added more test coverage for ascending sort and invalid parameters

(`∇´ゞ)

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch the commit changes
git show f2a04ae77250dd9a01efcb27581957efec7dc44c

Length of output: 8288

✅ Actions performed

Comments resolved.

@@ -251,6 +251,32 @@ public interface IStorageUtilityIndexed<E extends Externalizable> {
* they may need to clean up if the bulk read doesn't complete
*/

Vector<E> getSortedRecordsForValues(String[] metaFieldNames, Object[] values,String orderby);
Copy link
Contributor

Choose a reason for hiding this comment

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

Java docs are out of order

Comment on lines 219 to 221
} catch (Exception e) {
// Log error and continue with no ordering
System.err.println("Failed to compare records: " + e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

we should not be catching generic exceptions

@@ -126,6 +128,15 @@ public void testBulkMetaMatching() {

Vector<Shoe> matchedRecords = storage.getRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"nike", "mens"});
Assert.assertEquals("Failed index match [brand,style][nike,mens]", getIdsFromModels(tenSizesOfMensNikes), getIdsFromModels(matchedRecords.toArray(new Shoe[]{})));

Vector<Shoe> matchedSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"adidas", "mens"},Shoe.META_SIZE+" DESC");
Copy link
Contributor

Choose a reason for hiding this comment

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

what is the expected outcome for function calls without select params - storage.getSortedRecordsForValues(new String[]{}, new String[]{},Shoe.META_SIZE+" DESC"); ?

Copy link
Author

Choose a reason for hiding this comment

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

revert the array as it is

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test case for it.

Vector<Shoe> matchedAscSortedRecords = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASC");
Assert.assertArrayEquals("Failed index match [brand,style][adidas,mens]", matchedAscSortedRecords.toArray(),fiveSizesOfMensVans);

Vector<Shoe> matchedAscSortedRecordsTest = storage.getSortedRecordsForValues(new String[]{Shoe.META_BRAND, Shoe.META_STYLE}, new String[]{"vans", "mens"},Shoe.META_SIZE+" ASSC");
Copy link
Contributor

Choose a reason for hiding this comment

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

this call should fail right given ASSC is not the right keyword ?

Copy link
Author

Choose a reason for hiding this comment

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

revert the array is asc order as default value is ascending

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be allowing for incorrrect keywords in this method and should do a strict match and else throw an error.

@pm-dimagi pm-dimagi requested a review from shubham1g5 February 5, 2025 15:49
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