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(tdigest): add TDIGEST.MAX/MIN command #2811

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

Conversation

wyxxxcat
Copy link
Contributor

@wyxxxcat wyxxxcat commented Feb 28, 2025

This closes #2793.

@git-hulk git-hulk requested a review from Copilot February 28, 2025 03:03
Copilot

This comment was marked as duplicate.

@wyxxxcat wyxxxcat force-pushed the min_max branch 2 times, most recently from fa1c04c to d4d2c8f Compare February 28, 2025 03:08
@git-hulk git-hulk requested a review from Copilot February 28, 2025 03:08

Choose a reason for hiding this comment

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

PR Overview

This PR adds tests for the new TDIGEST.MAX and TDIGEST.MIN commands to validate their behavior, including error handling and correct value computation.

  • Introduces the error message constant errValueDoesNotExist for cases where a tdigest exists but contains no data.
  • Adds subtests for both TDIGEST.MAX and TDIGEST.MIN covering invalid arguments, empty digests, and digests with one or multiple values.

Reviewed Changes

File Description
tests/gocase/unit/type/tdigest/tdigest_test.go Added tests to cover TDIGEST.MAX and TDIGEST.MIN functionality

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

tests/gocase/unit/type/tdigest/tdigest_test.go:217

  • [nitpick] Consider reinitializing the tdigest or using a fresh key when transitioning from testing a single value to multiple values. This ensures that previous state does not affect the aggregation and makes each test case more isolated.
require.NoError(t, rdb.Do(ctx, "TDIGEST.CREATE", key, "compression", "100").Err())

tests/gocase/unit/type/tdigest/tdigest_test.go:212

  • [nitpick] Consider expanding the invalid argument tests by including cases with extra arguments for both TDIGEST.MAX and TDIGEST.MIN to further improve test coverage.
require.ErrorContains(t, rdb.Do(ctx, "TDIGEST.MAX").Err(), errMsgWrongNumberArg)
@git-hulk git-hulk requested a review from Copilot February 28, 2025 03:10

Choose a reason for hiding this comment

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

PR Overview

This PR adds tests for the new TDIGEST.MAX and TDIGEST.MIN commands to ensure their correct behavior with various arguments.

  • Added a new error constant for missing values.
  • Introduced test cases for TDIGEST.MAX and TDIGEST.MIN covering invalid arguments, empty digests, and digests with one or multiple values.

Reviewed Changes

File Description
tests/gocase/unit/type/tdigest/tdigest_test.go Added tests for TDIGEST.MAX and TDIGEST.MIN commands and a new error constant

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

tests/gocase/unit/type/tdigest/tdigest_test.go:39

  • [nitpick] Consider renaming 'errValueDoesNotExist' to 'errMsgValueDoesNotExist' for consistency with the other error constants defined in this file.
errValueDoesNotExist   = "no value exists for key"
Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

Code general LGTM, but suddenly I realized that TDigest.Add nan is invalid: https://github.com/RedisBloom/RedisBloom/blob/f68a72e463b84c2298990295c6a3db4719dc5c7a/src/rm_tdigest.c#L187

Would you mind also change that? ( Can be in another pr )

@wyxxxcat
Copy link
Contributor Author

Code general LGTM, but suddenly I realized that TDigest.Add nan is invalid: https://github.com/RedisBloom/RedisBloom/blob/f68a72e463b84c2298990295c6a3db4719dc5c7a/src/rm_tdigest.c#L187

Would you mind also change that? ( Can be in another pr )

I will fix

mapleFU
mapleFU previously approved these changes Feb 28, 2025
@@ -168,7 +168,71 @@ class CommandTDigestAdd : public Commander {
std::vector<double> values_;
};

Copy link
Member

Choose a reason for hiding this comment

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

By the way would you mind extract an:


struct MinMax {
   min, max
};
class CommandTDigestMinMaxImpl {
   StatusOr<MinMax> Execute(...)
};

? I just think this could eliminate some code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes!I will pick it

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
34.4% Duplication on New Code (required ≤ 20%)

See analysis details on SonarQube Cloud

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.

TDigest: Implement MIN MAX command for TDigest Algorithm
4 participants