mapleFU commented on code in PR #2803:
URL: https://github.com/apache/kvrocks/pull/2803#discussion_r1970079109
##########
src/commands/cmd_tdigest.cc:
##########
@@ -131,6 +131,54 @@ class CommandTDigestInfo : public Commander {
std::string key_name_;
};
+class CommandTDigestAdd : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ key_name_ = args[1];
+
+ for (size_t i = 2; i < args.size(); i++) {
+ auto value = parseFloat(args[i]);
+ if (!value) {
+ return {Status::RedisParseErr, errValueIsNotFloat};
+ }
+ values_.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());
+
+ auto s = tdigest.Add(ctx, key_name_, values_);
+ if (!s.ok()) {
+ if (s.IsNotFound()) {
+ return {Status::RedisExecErr, errKeyNotFound};
+ }
+ return {Status::RedisExecErr, s.ToString()};
+ }
+
+ *output = redis::RESP_OK;
+ return Status::OK();
+ }
+
+ private:
+ std::string key_name_;
+ std::vector<double> values_;
+
+ static StatusOr<double> parseFloat(const std::string &str) {
Review Comment:
Why not call
https://github.com/apache/kvrocks/blob/e00fcf10621f242f6de4bf4602d79da8b9cfcc10/src/common/parse_util.h#L198
?
##########
src/commands/cmd_tdigest.cc:
##########
@@ -131,6 +131,54 @@ class CommandTDigestInfo : public Commander {
std::string key_name_;
};
+class CommandTDigestAdd : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ key_name_ = args[1];
Review Comment:
why store the key_name rather than just uses args[1]?
##########
src/commands/cmd_tdigest.cc:
##########
@@ -131,6 +131,54 @@ class CommandTDigestInfo : public Commander {
std::string key_name_;
};
+class CommandTDigestAdd : public Commander {
+ public:
+ Status Parse(const std::vector<std::string> &args) override {
+ if (args.size() < 3) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ key_name_ = args[1];
+
+ for (size_t i = 2; i < args.size(); i++) {
+ auto value = parseFloat(args[i]);
+ if (!value) {
+ return {Status::RedisParseErr, errValueIsNotFloat};
+ }
+ values_.push_back(*value);
Review Comment:
Reserve firstly since it's likely to success
--
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]