jihuayu commented on code in PR #3551:
URL: https://github.com/apache/kvrocks/pull/3551#discussion_r3577269637


##########
src/commands/cmd_tdigest.cc:
##########
@@ -556,6 +556,45 @@ class CommandTDigestTrimmedMean : public Commander {
   double high_cut_quantile_;
 };
 
+class CommandTDigestCDF : public Commander {
+  Status Parse(const std::vector<std::string> &args) override {
+    if (args.size() == 2) return {Status::RedisParseErr, 
errWrongNumOfArguments};
+    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};
+      }
+      if (std::isnan(*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());
+    TDigestCDFResult result;
+    auto s = tdigest.CDF(ctx, key_name_, inputs_, &result);
+    if (!s.ok()) {
+      if (s.IsNotFound()) {
+        return {Status::RedisExecErr, errKeyNotFound};
+      }
+      return {Status::RedisExecErr, s.ToString()};
+    }
+
+    *output =
+        conn->MultiBulkString(result.cdf_values | 
ranges::views::transform(util::Float2String) | ranges::to_vector);

Review Comment:
   Please use conn->Double()
   
   <img width="1181" height="452" alt="Image" 
src="https://github.com/user-attachments/assets/b54953d7-b314-4b78-bd6e-948c89f4d4b4";
 />
   https://redis.io/docs/latest/commands/tdigest.cdf/



-- 
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]

Reply via email to