LindaSummer commented on code in PR #2799:
URL: https://github.com/apache/kvrocks/pull/2799#discussion_r1966493859


##########
src/commands/cmd_tdigest.cc:
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "command_parser.h"
+#include "commander.h"
+#include "server/redis_reply.h"
+#include "server/server.h"
+#include "status.h"
+#include "types/redis_tdigest.h"
+
+namespace redis {
+namespace {
+constexpr auto kCompressionArg = "compression";
+
+constexpr auto kInfoCompression = "Compression";
+constexpr auto kInfoCapacity = "Capacity";
+constexpr auto kInfoMergedNodes = "Merged nodes";
+constexpr auto kInfoUnmergedNodes = "Unmerged nodes";
+constexpr auto kInfoMergedWeight = "Merged weight";
+constexpr auto kInfoUnmergedWeight = "Unmerged weight";
+constexpr auto kInfoObservations = "Observations";
+constexpr auto kInfoTotalCompressions = "Total compressions";
+}  // namespace
+
+class CommandTDigestCreate : public Commander {
+ public:
+  Status Parse(const std::vector<std::string> &args) override {
+    CommandParser parser(args, 1);
+    key_name_ = GET_OR_RET(parser.TakeStr());
+    options_.compression = 100;
+    if (parser.EatEqICase(kCompressionArg)) {
+      if (!parser.Good()) {
+        return {Status::RedisParseErr, errWrongNumOfArguments};
+      }
+      auto status = parser.TakeInt<int32_t>();
+      if (!status) {
+        return {Status::RedisParseErr, errParseCompression};
+      }
+      auto compression = *status;
+      if (compression <= 0) {
+        return {Status::RedisParseErr, errCompressionMustBePositive};
+      }
+      if (compression < 1 || compression > 
static_cast<int32_t>(kTDigestMaxCompression)) {
+        return {Status::RedisParseErr, errCompressionOutOfRange};
+      }
+      options_.compression = static_cast<uint32_t>(compression);
+    }
+    if (parser.Good()) {
+      parser.RawTake();

Review Comment:
   Hi @PragmaTwice ,
   
   Thanks very much for your warm help and patience! 😊
   
   Best Regards,
   Edward



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