You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "skyitachi (via GitHub)" <gi...@apache.org> on 2023/12/09 13:51:16 UTC

[PR] support JSON.MGET command [kvrocks]

skyitachi opened a new pull request, #1930:
URL: https://github.com/apache/kvrocks/pull/1930

   #1816 


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.MGET command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#discussion_r1421735093


##########
src/types/redis_json.cc:
##########
@@ -512,4 +512,85 @@ rocksdb::Status Json::ObjLen(const std::string &user_key, const std::string &pat
   return rocksdb::Status::OK();
 }
 
+std::vector<rocksdb::Status> Json::MGet(const std::vector<std::string> &user_keys, const std::string &path,
+                                        std::vector<JsonValue> &results) {
+  std::vector<Slice> ns_keys;
+  std::vector<std::string> ns_keys_string;
+  ns_keys.resize(user_keys.size());
+  ns_keys_string.resize(user_keys.size());
+
+  for (size_t i = 0; i < user_keys.size(); i++) {
+    ns_keys_string[i] = AppendNamespacePrefix(user_keys[i]);
+    ns_keys[i] = Slice(ns_keys_string[i]);
+  }
+
+  std::vector<JsonValue> json_vals;
+  json_vals.resize(ns_keys.size());
+  auto statuses = readMulti(ns_keys, json_vals);
+
+  results.resize(ns_keys.size());
+  for (size_t i = 0; i < ns_keys.size(); i++) {
+    if (!statuses[i].ok()) {
+      continue;
+    }
+    auto res = json_vals[i].Get(path);
+
+    if (!res) {
+      statuses[i] = rocksdb::Status::Corruption(res.Msg());
+    } else {
+      results[i] = *std::move(res);
+    }
+  }
+  return statuses;
+}
+
+std::vector<rocksdb::Status> Json::readMulti(const std::vector<Slice> &ns_keys, std::vector<JsonValue> &values) {
+  std::vector<std::string> raw_values;
+  std::vector<JsonMetadata> meta_data;
+  raw_values.resize(ns_keys.size());
+  meta_data.resize(ns_keys.size());
+
+  auto statuses = getRawMetaData(ns_keys, meta_data, &raw_values);
+  for (size_t i = 0; i < ns_keys.size(); i++) {
+    if (!statuses[i].ok()) continue;
+    if (meta_data[i].format == JsonStorageFormat::JSON) {
+      auto res = JsonValue::FromString(raw_values[i]);
+      if (!res) {
+        statuses[i] = rocksdb::Status::Corruption(res.Msg());
+        continue;
+      }
+      values[i] = *std::move(res);
+    } else if (meta_data[i].format == JsonStorageFormat::CBOR) {
+      auto res = JsonValue::FromCBOR(raw_values[i]);
+      if (!res) {
+        rocksdb::Status::Corruption(res.Msg());

Review Comment:
   ```suggestion
           statuses[i] = rocksdb::Status::Corruption(res.Msg());
   ```



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.MGET command [kvrocks]

Posted by "PragmaTwice (via GitHub)" <gi...@apache.org>.
PragmaTwice commented on code in PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#discussion_r1421736324


##########
src/types/redis_json.cc:
##########
@@ -512,4 +512,85 @@ rocksdb::Status Json::ObjLen(const std::string &user_key, const std::string &pat
   return rocksdb::Status::OK();
 }
 
+std::vector<rocksdb::Status> Json::MGet(const std::vector<std::string> &user_keys, const std::string &path,
+                                        std::vector<JsonValue> &results) {
+  std::vector<Slice> ns_keys;
+  std::vector<std::string> ns_keys_string;
+  ns_keys.resize(user_keys.size());
+  ns_keys_string.resize(user_keys.size());
+
+  for (size_t i = 0; i < user_keys.size(); i++) {
+    ns_keys_string[i] = AppendNamespacePrefix(user_keys[i]);
+    ns_keys[i] = Slice(ns_keys_string[i]);
+  }
+
+  std::vector<JsonValue> json_vals;
+  json_vals.resize(ns_keys.size());
+  auto statuses = readMulti(ns_keys, json_vals);
+
+  results.resize(ns_keys.size());
+  for (size_t i = 0; i < ns_keys.size(); i++) {
+    if (!statuses[i].ok()) {
+      continue;
+    }
+    auto res = json_vals[i].Get(path);
+
+    if (!res) {
+      statuses[i] = rocksdb::Status::Corruption(res.Msg());
+    } else {
+      results[i] = *std::move(res);
+    }
+  }
+  return statuses;
+}
+
+std::vector<rocksdb::Status> Json::readMulti(const std::vector<Slice> &ns_keys, std::vector<JsonValue> &values) {
+  std::vector<std::string> raw_values;
+  std::vector<JsonMetadata> meta_data;
+  raw_values.resize(ns_keys.size());
+  meta_data.resize(ns_keys.size());
+
+  auto statuses = getRawMetaData(ns_keys, meta_data, &raw_values);
+  for (size_t i = 0; i < ns_keys.size(); i++) {
+    if (!statuses[i].ok()) continue;
+    if (meta_data[i].format == JsonStorageFormat::JSON) {
+      auto res = JsonValue::FromString(raw_values[i]);
+      if (!res) {
+        statuses[i] = rocksdb::Status::Corruption(res.Msg());
+        continue;
+      }
+      values[i] = *std::move(res);
+    } else if (meta_data[i].format == JsonStorageFormat::CBOR) {
+      auto res = JsonValue::FromCBOR(raw_values[i]);
+      if (!res) {
+        rocksdb::Status::Corruption(res.Msg());
+        continue;
+      }

Review Comment:
   ```suggestion
         } else {
           ... // for unknow format
         }
   ```



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.MGET command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#issuecomment-1849725568

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1930)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930) No Coverage information  
   [![1.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '1.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930&metric=new_duplicated_lines_density&view=list) [1.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.MGET command [kvrocks]

Posted by "skyitachi (via GitHub)" <gi...@apache.org>.
skyitachi commented on code in PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#discussion_r1422234117


##########
src/types/redis_json.cc:
##########
@@ -512,4 +512,85 @@ rocksdb::Status Json::ObjLen(const std::string &user_key, const std::string &pat
   return rocksdb::Status::OK();
 }
 
+std::vector<rocksdb::Status> Json::MGet(const std::vector<std::string> &user_keys, const std::string &path,
+                                        std::vector<JsonValue> &results) {
+  std::vector<Slice> ns_keys;
+  std::vector<std::string> ns_keys_string;
+  ns_keys.resize(user_keys.size());
+  ns_keys_string.resize(user_keys.size());
+
+  for (size_t i = 0; i < user_keys.size(); i++) {
+    ns_keys_string[i] = AppendNamespacePrefix(user_keys[i]);
+    ns_keys[i] = Slice(ns_keys_string[i]);
+  }
+
+  std::vector<JsonValue> json_vals;
+  json_vals.resize(ns_keys.size());
+  auto statuses = readMulti(ns_keys, json_vals);
+
+  results.resize(ns_keys.size());
+  for (size_t i = 0; i < ns_keys.size(); i++) {
+    if (!statuses[i].ok()) {
+      continue;
+    }
+    auto res = json_vals[i].Get(path);
+
+    if (!res) {
+      statuses[i] = rocksdb::Status::Corruption(res.Msg());
+    } else {
+      results[i] = *std::move(res);
+    }
+  }
+  return statuses;
+}
+
+std::vector<rocksdb::Status> Json::readMulti(const std::vector<Slice> &ns_keys, std::vector<JsonValue> &values) {
+  std::vector<std::string> raw_values;
+  std::vector<JsonMetadata> meta_data;
+  raw_values.resize(ns_keys.size());
+  meta_data.resize(ns_keys.size());
+
+  auto statuses = getRawMetaData(ns_keys, meta_data, &raw_values);
+  for (size_t i = 0; i < ns_keys.size(); i++) {
+    if (!statuses[i].ok()) continue;
+    if (meta_data[i].format == JsonStorageFormat::JSON) {
+      auto res = JsonValue::FromString(raw_values[i]);
+      if (!res) {
+        statuses[i] = rocksdb::Status::Corruption(res.Msg());
+        continue;
+      }
+      values[i] = *std::move(res);
+    } else if (meta_data[i].format == JsonStorageFormat::CBOR) {
+      auto res = JsonValue::FromCBOR(raw_values[i]);
+      if (!res) {
+        rocksdb::Status::Corruption(res.Msg());

Review Comment:
   fixed



-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add the support of JSON.MGET command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#issuecomment-1855470157

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1930) **Quality Gate passed**  
   The SonarCloud Quality Gate passed, but some issues were introduced.
   
   [1 New issue](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&inNewCodePeriod=true)  
   [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&inNewCodePeriod=true)  
   No data about Coverage  
   [1.6% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1930)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add the support of JSON.MGET command [kvrocks]

Posted by "git-hulk (via GitHub)" <gi...@apache.org>.
git-hulk merged PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add the support of JSON.MGET command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#issuecomment-1855330787

   ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1930) **Quality Gate passed**  
   The SonarCloud Quality Gate passed, but some issues were introduced.
   
   [1 New issue](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&inNewCodePeriod=true)  
   [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&inNewCodePeriod=true)  
   No data about Coverage  
   [1.6% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930&metric=new_duplicated_lines_density&view=list)  
     
   [See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1930)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] support JSON.MGET command [kvrocks]

Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #1930:
URL: https://github.com/apache/kvrocks/pull/1930#issuecomment-1848415923

   Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=apache_kvrocks&pullRequest=1930)
   
   [![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=BUG)  
   [![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=VULNERABILITY)  
   [![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_kvrocks&pullRequest=1930&resolved=false&types=SECURITY_HOTSPOT)  
   [![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=apache_kvrocks&pullRequest=1930&resolved=false&types=CODE_SMELL)
   
   [![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930) No Coverage information  
   [![1.6%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '1.6%')](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930&metric=new_duplicated_lines_density&view=list) [1.6% Duplication](https://sonarcloud.io/component_measures?id=apache_kvrocks&pullRequest=1930&metric=new_duplicated_lines_density&view=list)
   
   


-- 
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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org