From 349034cf6954201cbfab11e8c6010d79701c2403 Mon Sep 17 00:00:00 2001 From: mazhao Date: Tue, 27 Jun 2023 12:00:43 +0800 Subject: [PATCH 1/5] fix crash bug Signed-off-by: mazhao --- .../src/oh_adapter/src/json_object.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 5130029d..1be20531 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -146,17 +146,17 @@ int JsonObject::GetDeep(cJSON *cjson) int JsonObject::CheckNumber(cJSON *item, int &errCode) { - if (item != NULL && cJSON_IsNumber(item)) { - double value = cJSON_GetNumberValue(item); - if (value > __DBL_MAX__ || value < -__DBL_MAX__) { - errCode = -E_INVALID_ARGS; + while (item != nullptr) { + if (item != NULL && cJSON_IsNumber(item)) { + double value = cJSON_GetNumberValue(item); + if (value > __DBL_MAX__ || value < -__DBL_MAX__) { + errCode = -E_INVALID_ARGS; + } } - } - if (item->child != nullptr) { - return CheckNumber(item->child, errCode); - } - if (item->next != nullptr) { - return CheckNumber(item->next, errCode); + if (item->child != nullptr) { + return CheckNumber(item->child, errCode); + } + item = item->next; } return E_OK; } -- Gitee From 14ef239d3230a633e37cb2a31ea3dfca9c9ab897 Mon Sep 17 00:00:00 2001 From: mazhao Date: Tue, 27 Jun 2023 16:49:07 +0800 Subject: [PATCH 2/5] Reduce recursive functions Signed-off-by: mazhao --- .../gaussdb_rd/src/common/src/json_common.cpp | 44 ++++++++++--------- .../src/executor/document/check_common.cpp | 2 +- .../src/oh_adapter/src/json_object.cpp | 19 +++++--- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 171c1fcb..357c0052 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -14,6 +14,8 @@ */ #include "json_common.h" +#include + #include "doc_errno.h" #include "log_print.h" @@ -82,26 +84,27 @@ std::vector JsonCommon::GetLeafValue(const JsonObject &node) bool JsonCommon::CheckNode(JsonObject &node) { - while (!node.IsNull()) { + std::queue jsonQueue; + jsonQueue.push(node); + while (!jsonQueue.empty()) { std::set fieldSet; bool isFieldNameExist = true; int ret = E_OK; - std::string fieldName = node.GetItemField(ret); + JsonObject item = jsonQueue.front(); + jsonQueue.pop(); + std::string fieldName = item.GetItemField(ret); if (ret != E_OK) { isFieldNameExist = false; } - if (fieldSet.find(fieldName) != fieldSet.end()) { return false; } - if (isFieldNameExist) { fieldSet.insert(fieldName); if (fieldName.empty()) { return false; } } - for (size_t i = 0; i < fieldName.size(); i++) { if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || fieldName[i] == '_')) { return false; @@ -110,14 +113,12 @@ bool JsonCommon::CheckNode(JsonObject &node) return false; } } - - if (!node.GetChild().IsNull()) { - JsonObject nodeNew = node.GetChild(); - if (!CheckNode(nodeNew)) { - return false; - } + if (!item.GetChild().IsNull()) { + jsonQueue.push(item.GetChild()); + } + if (!item.GetNext().IsNull()) { + jsonQueue.push(item.GetNext()); } - node = node.GetNext(); } return true; } @@ -129,10 +130,14 @@ bool JsonCommon::CheckJsonField(JsonObject &jsonObj) bool JsonCommon::CheckProjectionNode(JsonObject &node, bool isFirstLevel, int &errCode) { - while (!node.IsNull()) { + std::queue jsonQueue; + jsonQueue.push(node); + while (!jsonQueue.empty()) { int ret = 0; std::set fieldSet; - std::string fieldName = node.GetItemField(ret); + JsonObject item = jsonQueue.front(); + jsonQueue.pop(); + std::string fieldName = item.GetItemField(ret); if (fieldName.empty()) { errCode = -E_INVALID_ARGS; return false; @@ -154,13 +159,12 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, bool isFirstLevel, int &e return false; } } - if (!node.GetChild().IsNull()) { - JsonObject nodeNew = node.GetChild(); - if (!CheckProjectionNode(nodeNew, false, errCode)) { - return false; - } + if (!item.GetNext().IsNull()) { + jsonQueue.push(item.GetNext()); + } + if (!item.GetChild().IsNull()) { + jsonQueue.push(item.GetChild()); } - node = node.GetNext(); } return true; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 2140e70d..1bd7e4c3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -41,7 +41,7 @@ bool CheckCollectionNamePrefix(const std::string &name, const std::string &prefi void ReplaceAll(std::string &inout, const std::string &what, const std::string &with) { - std::string::size_type pos {}; + std::string::size_type pos{}; while ((pos = inout.find(what.data(), pos, what.length())) != std::string::npos) { inout.replace(pos, what.length(), with.data(), with.length()); pos += with.length(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 1be20531..0c699b8d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "doc_errno.h" #include "log_print.h" @@ -146,17 +147,23 @@ int JsonObject::GetDeep(cJSON *cjson) int JsonObject::CheckNumber(cJSON *item, int &errCode) { - while (item != nullptr) { - if (item != NULL && cJSON_IsNumber(item)) { - double value = cJSON_GetNumberValue(item); + std::queue cjsonQueue; + cjsonQueue.push(item); + while (!cjsonQueue.empty()) { + cJSON *node = cjsonQueue.front(); + cjsonQueue.pop(); + if (node != NULL && cJSON_IsNumber(node)) { + double value = cJSON_GetNumberValue(node); if (value > __DBL_MAX__ || value < -__DBL_MAX__) { errCode = -E_INVALID_ARGS; } } - if (item->child != nullptr) { - return CheckNumber(item->child, errCode); + if (node->child != nullptr) { + cjsonQueue.push(node->child); + } + if (node->next != nullptr) { + cjsonQueue.push(node->next); } - item = item->next; } return E_OK; } -- Gitee From 1fce8e9ab27a899034327a5a4f1805a64bdb3428 Mon Sep 17 00:00:00 2001 From: mazhao Date: Tue, 27 Jun 2023 16:52:28 +0800 Subject: [PATCH 3/5] fix format Signed-off-by: mazhao --- .../gaussdb_rd/src/executor/document/check_common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 1bd7e4c3..2140e70d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -41,7 +41,7 @@ bool CheckCollectionNamePrefix(const std::string &name, const std::string &prefi void ReplaceAll(std::string &inout, const std::string &what, const std::string &with) { - std::string::size_type pos{}; + std::string::size_type pos {}; while ((pos = inout.find(what.data(), pos, what.length())) != std::string::npos) { inout.replace(pos, what.length(), with.data(), with.length()); pos += with.length(); -- Gitee From 7d4bd655fbf54e7db397889b2843e12005ec052b Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 3 Jul 2023 16:32:10 +0800 Subject: [PATCH 4/5] add find cut Signed-off-by: mazhao --- .../gaussdb_rd/src/interface/src/projection_tree.cpp | 6 +++--- .../data_share/gaussdb_rd/src/interface/src/result_set.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index 5c37b84b..4ab699c3 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -58,11 +58,11 @@ bool ProjectionTree::SearchTree(std::vector &singlePath, size_t &in { ProjectionNode *node = &node_; for (size_t i = 0; i < singlePath.size(); i++) { - if (node->isDeepest) { - index = i; - } if (node->sonNode[singlePath[i]] != nullptr) { node = node->sonNode[singlePath[i]]; + if (node->isDeepest) { + index = i + 1; + } } else { return false; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 2ab4fa81..dd28c026 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -198,10 +198,12 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat while (!nodeInstance.IsNull()) { singlePath.emplace_back(nodeInstance.GetItemField()); size_t index = 0; - if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { + bool isMatch = context_->projectionTree.SearchTree(singlePath, index); + if ((nodeInstance.GetType() == JsonObject::Type::JSON_ARRAY && isMatch && index == 0) || + (!isMatch && index == 0)) { allCutPath.emplace_back(singlePath); } - if (!nodeInstance.GetChild().IsNull()) { + if (nodeInstance.GetType() != JsonObject::Type::JSON_ARRAY && !nodeInstance.GetChild().IsNull()) { JsonObject nodeChiled = nodeInstance.GetChild(); CheckCutNode(&nodeChiled, singlePath, allCutPath); } -- Gitee From f22b932e79c74149a72d6a2f549f0bfa15147c5d Mon Sep 17 00:00:00 2001 From: mazhao Date: Mon, 3 Jul 2023 16:33:27 +0800 Subject: [PATCH 5/5] delete useless log Signed-off-by: mazhao --- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index 0c699b8d..a5d594d0 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -613,7 +613,6 @@ int JsonObject::DeleteItemDeeplyOnTarget(const JsonFieldPath &path) cJSON *nodeFather = MoveToPath(cjson_, patherPath, caseSensitive_); if (nodeFather == nullptr) { - GLOGE("Delete item failed, json field path not found."); return -E_JSON_PATH_NOT_EXISTS; } -- Gitee