donghao526 commented on code in PR #3130:
URL: https://github.com/apache/kvrocks/pull/3130#discussion_r2467726449
##########
src/commands/cmd_tdigest.cc:
##########
@@ -176,6 +176,49 @@ class CommandTDigestAdd : public Commander {
std::vector<double> values_;
};
+class CommandTDigestRevRank : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ key_name_ = args[1];
+ inputs_.reserve(args.size() - 2);
+ for (size_t i = 2; i < args.size(); i++) {
+ auto value = ParseFloat(args[i]);
+ if (!value) {
+ return {Status::RedisParseErr, errValueIsNotFloat};
+ }
+ inputs_.push_back(*value);
+ }
+ return Status::OK();
+ }
+ Status Execute(engine::Context &ctx, Server *srv, Connection *conn,
std::string *output) override {
+ TDigest tdigest(srv->storage, conn->GetNamespace());
+ std::vector<int> result;
+ result.reserve(inputs_.size());
+ if (const auto s = tdigest.RevRank(ctx, key_name_, inputs_, result);
!s.ok()) {
+ if (s.IsNotFound()) {
+ return {Status::RedisExecErr, errKeyNotFound};
+ }
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ if (!result.empty()) {
+ std::vector<std::string> rev_ranks;
+ rev_ranks.reserve(result.size());
+ for (const auto v : result) {
+ rev_ranks.push_back(redis::Integer(v));
+ }
+ *output = redis::Array(rev_ranks);
+ } else {
+ *output = redis::BulkString("nan");
Review Comment:
This logic has implemented in the tdigest.RevRank. So if tdigest.RevRank
returns Status::OK(), the result can not be empty, I removed the the
conditional judgment here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]