git-hulk commented on code in PR #3054:
URL: https://github.com/apache/kvrocks/pull/3054#discussion_r2207730735
##########
src/commands/cmd_tdigest.cc:
##########
@@ -281,11 +284,103 @@ class CommandTDigestQuantile : public Commander {
std::string key_name_;
std::vector<double> quantiles_;
};
+
+class CommandTDigestMerge : public Commander {
+ Status Parse(const std::vector<std::string> &args) override {
+ CommandParser parser(args, 1);
+ dest_key_ = GET_OR_RET(parser.TakeStr());
+ auto numkeys = parser.TakeInt();
+ if (!numkeys) {
+ return {Status::RedisParseErr, errParsingNumkeys};
+ }
+
+ if (*numkeys <= 0) {
+ return {Status::RedisParseErr, errCompressionMustBePositive};
+ }
+
+ if (static_cast<int64_t>(args.size()) < (3 + *numkeys)) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+
+ std::set<std::string> unique_source_keys;
+
+ for (auto i = 3; i < (3 + *numkeys); i++) {
+ auto src_digest = GET_OR_RET(parser.TakeStr());
+ unique_source_keys.emplace(std::move(src_digest));
+ }
+ source_keys_ = ranges::to_vector(unique_source_keys);
+
+ if (!parser.Good()) {
+ return Status::OK();
+ }
+
+ auto keyword = GET_OR_RET(parser.TakeStr());
+ if (keyword == kCompressionArg) {
+ if (!parser.Good()) {
+ return {Status::RedisParseErr, errWrongNumOfArguments};
+ }
+ auto compression = parser.TakeInt<uint32_t>();
+ if (!compression) {
+ return {Status::RedisParseErr, errParseCompression};
+ }
+ if (*compression <= 0 || *compression > kTDigestMaxCompression) {
+ return {Status::RedisParseErr, errCompressionOutOfRange};
+ }
+ options_.compression = *compression;
+ } else if (keyword == kOverrideArg) {
+ options_.override_flag = true;
+ } else {
+ return {Status::RedisParseErr, errWrongKeyword};
+ }
+
+ if (!parser.Good()) {
+ return Status::OK();
+ }
+
+ if (options_.override_flag) {
+ return {Status::RedisParseErr, errWrongKeyword};
+ }
+
+ if (GET_OR_RET(parser.TakeStr()) != kOverrideArg) {
+ return {Status::RedisParseErr, errWrongKeyword};
+ }
+
+ options_.override_flag = true;
+
+ if (parser.Good()) {
Review Comment:
Could we use a while loop to improve this part?
--
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]