Skip to content

feat(tdigest): add the support of TDIGEST.BYRANK and TDIGEST.BYREVRANK command#3296

Merged
LindaSummer merged 57 commits intoapache:unstablefrom
donghao526:feature/tdigest-byrank
Dec 19, 2025
Merged

feat(tdigest): add the support of TDIGEST.BYRANK and TDIGEST.BYREVRANK command#3296
LindaSummer merged 57 commits intoapache:unstablefrom
donghao526:feature/tdigest-byrank

Conversation

@donghao526
Copy link
Contributor

This PR close #3064 and #3065

  1. Add TDIGEST.BYRANK and TDIGEST.BYREVRANK command implementation
  2. Add Related cpp and go unit tests

donghao526 and others added 30 commits November 20, 2025 21:29
Co-authored-by: Edward Xu <xuxiangad@foxmail.com>
@LindaSummer
Copy link
Member

Hi @donghao526 ,

Thanks very much for your great effort! ❤️

I will review this PR in two days. 😊

Best Regards,
Edward

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements the TDIGEST.BYRANK and TDIGEST.BYREVRANK commands, which provide the inverse operation of the existing RANK and REVRANK commands - they return the value at a given rank position rather than the rank of a given value. The implementation follows established patterns in the codebase by using template parameters to differentiate between normal and reverse operations, and includes comprehensive test coverage for both C++ and Go test suites.

Key Changes

  • Adds core algorithm implementation for retrieving values by rank with support for both forward and reverse iteration
  • Implements command handlers with proper input validation (non-negative rank requirement) and deduplication
  • Adds comprehensive test coverage including edge cases (empty sketches, duplicates, out-of-range ranks) with support for both RESP2 and RESP3 protocols

Reviewed changes

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

Show a summary per file
File Description
src/types/tdigest.h Adds TDigestByRank template function implementing the core algorithm for rank-to-value lookup
src/types/redis_tdigest.h Declares ByRank and ByRevRank methods in the TDigest class
src/types/redis_tdigest.cc Implements ByRank and ByRevRank methods with proper error handling for empty sketches
src/commands/cmd_tdigest.cc Adds command handlers for TDIGEST.BYRANK and TDIGEST.BYREVRANK with input validation and deduplication
src/commands/error_constants.h Adds error message constant for invalid (negative) rank values
tests/cppunit/types/tdigest_test.cc Adds C++ unit tests covering empty sketches, populated data, and boundary conditions
tests/gocase/unit/type/tdigest/tdigest_test.go Adds Go tests for empty/non-empty sketches, duplicates, and RESP2/RESP3 protocol handling; enhances toTdigestInfo to support both RESP formats

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

donghao526 and others added 4 commits December 15, 2025 10:54
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Hi @donghao526 ,

Left some comments.
Generally LGTM. 😊
Thanks for your effort!

@donghao526
Copy link
Contributor Author

donghao526 commented Dec 17, 2025

Hi @donghao526 ,

Left some comments. Generally LGTM. 😊 Thanks for your effort!

Hi @LindaSummer
Thanks for you review. I have resolved these comments. ❤️

@LindaSummer
Copy link
Member

Hi @donghao526 ,

Left some comments. Generally LGTM. 😊 Thanks for your effort!

Hi @LindaSummer

Thanks for you review. I have resolved these comments. ❤️

got it!🚀
I will go through this PR later today.

Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Left one comment.
Generally LGTM.
Thanks very much for your effort! 😊

TotalCompressions: v["Total compressions"].(int64),
// Handle both RESP2 (map) and RESP3 (array) formats
switch v := value.(type) {
case map[interface{}]interface{}:
Copy link
Member

Choose a reason for hiding this comment

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

This seems a little tricky, we'd better pass a parameter explicitly. Or we could provide two versions and let the test case choose which version should use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. I've reverted this part since the RESP3 test only applies to byrank commands. It was an oversight that I didn't remove it before.

Copy link
Member

@LindaSummer LindaSummer left a comment

Choose a reason for hiding this comment

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

Hi @donghao526 ,
LGTM.
Thanks very much for your contribution!❤️

@LindaSummer LindaSummer enabled auto-merge (squash) December 19, 2025 02:11
@LindaSummer LindaSummer merged commit e51d2cc into apache:unstable Dec 19, 2025
35 checks passed
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@donghao526 donghao526 deleted the feature/tdigest-byrank branch December 19, 2025 05:47
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 TDIGEST.BYRANK command

5 participants