From efaf746959311238a682bdc4ca5102a7a470d724 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 17:02:22 +0800 Subject: [PATCH 01/11] fix public code check Signed-off-by: Jeremyzz --- .../src/common/include/json_common.h | 8 ++-- .../gaussdb_rd/src/common/include/log_print.h | 2 +- .../gaussdb_rd/src/common/src/json_common.cpp | 40 +++++++++---------- .../gaussdb_rd/src/common/src/log_print.cpp | 6 +-- .../src/executor/document/document_check.cpp | 4 +- .../src/interface/src/document_store.cpp | 30 +++++++------- .../src/interface/src/result_set.cpp | 18 ++++----- .../src/oh_adapter/include/json_object.h | 2 +- .../src/oh_adapter/src/json_object.cpp | 8 ++-- .../src/sqlite_store_executor_impl.cpp | 2 +- .../src/oh_adapter/src/sqlite_utils.cpp | 4 -- 11 files changed, 60 insertions(+), 64 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h index cc522e24..e1301386 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h @@ -34,7 +34,7 @@ public: static bool CheckJsonField(JsonObject &node); static bool CheckProjectionField(JsonObject &node, int &errCode); static int ParseNode(JsonObject &Node, std::vector singlePath, - std::vector> &resultPath, bool isFirstFloor); + std::vector> &resultPath, bool isFirstLevel); static std::vector> ParsePath(const JsonObject &node, int &errCode); static std::vector GetLeafValue(const JsonObject &node); static bool isValueEqual(const ValueObject &srcValue, const ValueObject &targetValue); @@ -44,9 +44,9 @@ public: private: static bool JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); - static bool CheckNode(JsonObject &Node, std::set fieldSet, bool &errFlag); - static bool CheckProjectionNode(JsonObject &Node, std::set fieldSet, bool &errFlag, - bool isFirstFloor, int &errCode); + static bool CheckNode(JsonObject &Node, std::set filedSet, bool &errFlag); + static bool CheckProjectionNode(JsonObject &Node, std::set filedSet, bool &errFlag, + bool isFirstLevel, int &errCode); static void CheckLeafNode(const JsonObject &Node, std::vector &leafValue); static bool IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); }; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h index 25918731..cf1b9b33 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/log_print.h @@ -31,7 +31,7 @@ public: LEVEL_FATAL }; - static void Log(Level level, const std::string &tag, const char *format, ...); + static void Log(Level level, const char *tag, const char *format, ...); }; } // namespace DocumentDB 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 e9267988..383fedad 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 @@ -26,13 +26,13 @@ ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &fie { while (!node.IsNull()) { if (node.GetItemField() == field) { - auto itemValue = node.GetItemValue(); + ValueObject itemValue = node.GetItemValue(); return itemValue; } if (node.GetNext().IsNull()) { return ValueObject(); } - auto nodeNew = node.GetNext(); + JsonObject nodeNew = node.GetNext(); node = nodeNew; } return ValueObject(); @@ -42,7 +42,7 @@ ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &fie { while (!node.IsNull()) { if (node.GetItemField() == field) { - auto itemValue = node.GetItemValue(); + ValueObject itemValue = node.GetItemValue(); isFieldExist = true; return itemValue; } @@ -50,7 +50,7 @@ ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &fie isFieldExist = false; return ValueObject(); } - auto nodeNew = node.GetNext(); + JsonObject nodeNew = node.GetNext(); node = nodeNew; } isFieldExist = false; @@ -60,15 +60,15 @@ ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &fie void JsonCommon::CheckLeafNode(const JsonObject &node, std::vector &leafValue) { if (node.GetChild().IsNull()) { - auto itemValue = node.GetItemValue(); + ValueObject itemValue = node.GetItemValue(); leafValue.emplace_back(itemValue); } if (!node.GetChild().IsNull()) { - auto nodeNew = node.GetChild(); + JsonObject nodeNew = node.GetChild(); CheckLeafNode(nodeNew, leafValue); } if (!node.GetNext().IsNull()) { - auto nodeNew = node.GetNext(); + JsonObject nodeNew = node.GetNext(); CheckLeafNode(nodeNew, leafValue); } } @@ -121,14 +121,14 @@ bool JsonCommon::CheckNode(JsonObject &node, std::set fieldSet, boo } } if (!node.GetChild().IsNull()) { - auto nodeNew = node.GetChild(); + JsonObject nodeNew = node.GetChild(); std::set newFieldSet; if (!CheckNode(nodeNew, newFieldSet, errFlag)) { return false; } } if (!node.GetNext().IsNull()) { - auto nodeNew = node.GetNext(); + JsonObject nodeNew = node.GetNext(); if (!CheckNode(nodeNew, fieldSet, errFlag)) { return false; } @@ -144,7 +144,7 @@ bool JsonCommon::CheckJsonField(JsonObject &jsonObj) } bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fieldSet, bool &errFlag, - bool isFirstFloor, int &errCode) + bool isFirstLevel, int &errCode) { if (!errFlag) { return false; @@ -167,7 +167,7 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fie } for (size_t i = 0; i < fieldName.size(); i++) { if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || ('_' == fieldName[i]) || - (isFirstFloor && '.' == fieldName[i]))) { + (isFirstLevel && '.' == fieldName[i]))) { errCode = -E_INVALID_ARGS; errFlag = false; return false; @@ -180,15 +180,15 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fie } } if (!node.GetChild().IsNull()) { - auto nodeNew = node.GetChild(); + JsonObject nodeNew = node.GetChild(); std::set newFieldSet; if (!CheckProjectionNode(nodeNew, newFieldSet, errFlag, false, errCode)) { return false; } } if (!node.GetNext().IsNull()) { - auto nodeNew = node.GetNext(); - if (!CheckProjectionNode(nodeNew, fieldSet, errFlag, isFirstFloor, errCode)) { + JsonObject nodeNew = node.GetNext(); + if (!CheckProjectionNode(nodeNew, fieldSet, errFlag, isFirstLevel, errCode)) { return false; } } @@ -199,16 +199,16 @@ bool JsonCommon::CheckProjectionField(JsonObject &jsonObj, int &errCode) { std::set fieldSet; bool errFlag = true; - bool isFirstFloor = true; - return CheckProjectionNode(jsonObj, fieldSet, errFlag, isFirstFloor, errCode); + bool isFirstLevel = true; + return CheckProjectionNode(jsonObj, fieldSet, errFlag, isFirstLevel, errCode); } int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, - std::vector> &resultPath, bool isFirstFloor) + std::vector> &resultPath, bool isFirstLevel) { while (!node.IsNull()) { int insertCount = 0; - if (isFirstFloor) { + if (isFirstLevel) { std::string tempParseName; std::vector allFieldsName; std::string priFieldName = node.GetItemField(); @@ -234,7 +234,7 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, singlePath.insert(singlePath.end(), allFieldsName.begin(), allFieldsName.end()); } if (!node.GetChild().IsNull() && node.GetChild().GetItemField() != "") { - auto nodeNew = node.GetChild(); + JsonObject nodeNew = node.GetChild(); int ret = E_OK; ret = ParseNode(nodeNew, singlePath, resultPath, false); if (ret != E_OK) { @@ -254,7 +254,7 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, std::vector> JsonCommon::ParsePath(const JsonObject &root, int &errCode) { std::vector> resultPath; - auto projectionJson = root.GetChild(); + JsonObject projectionJson = root.GetChild(); if (projectionJson.IsNull()) { GLOGE("projectionJson is null"); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp index 246852eb..8cdbae4c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp @@ -21,13 +21,13 @@ namespace DocumentDB { namespace { -void PrintLog(Logger::Level level, const std::string &tag, const std::string &msg) +void PrintLog(Logger::Level level, const char *tag, const std::string &msg) { if (msg.empty()) { return; } const std::string format = "%{public}s"; - OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag.c_str() }; + OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag }; switch (level) { case Logger::Level::LEVEL_DEBUG: (void)OHOS::HiviewDFX::HiLog::Debug(label, format.c_str(), msg.c_str()); @@ -60,7 +60,7 @@ void PreparePrivateLog(const char *format, std::string &outStrFormat) } } // namespace -void Logger::Log(Level level, const std::string &tag, const char *format, ...) +void Logger::Log(Level level, const char *tag, const char *format, ...) { static const int maxLogLength = 1024; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp index 4a3c8a4a..e4d88cfe 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp @@ -180,7 +180,7 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) return ret; } if (!documentObj.GetChild().IsNull()) { - auto documentObjChild = documentObj.GetChild(); + JsonObject documentObjChild = documentObj.GetChild(); if (!JsonCommon::CheckJsonField(documentObjChild)) { GLOGE("Document json field format is illegal"); return -E_INVALID_ARGS; @@ -234,7 +234,7 @@ int CheckCommon::CheckProjection(JsonObject &projectionObj, std::vector lock(dbMutex_); bool isCollectionExist = coll.IsCollectionExists(errCode); @@ -267,11 +267,11 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri } bool isOnlyId = true; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - auto coll = Collection(collection, executor_); errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; } + Collection coll = Collection(collection, executor_); if (isOnlyId) { std::lock_guard lock(dbMutex_); bool isCollectionExist = coll.IsCollectionExists(errCode); @@ -281,7 +281,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri if (!isCollectionExist) { return -E_INVALID_ARGS; } - auto filterObjChild = filterObj.GetChild(); + JsonObject filterObjChild = filterObj.GetChild(); ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string docId = idValue.GetStringValue(); JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); @@ -294,8 +294,8 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri return errCode; } bool isIdExist; - auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExist); + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExist); if (!isIdExist) { return -E_INVALID_ARGS; } @@ -346,7 +346,6 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri GLOGE("Check collection name invalid. %d", errCode); return errCode; } - auto coll = Collection(collection, executor_); if (document.length() >= JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; @@ -360,12 +359,13 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } - auto documentObjChild = documentObj.GetChild(); - auto idValue = JsonCommon::GetValueByField(documentObjChild, KEY_ID); + JsonObject documentObjChild = documentObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueByField(documentObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); Value value(document.begin(), document.end()); std::lock_guard lock(dbMutex_); + Collection coll = Collection(collection, executor_); bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; @@ -389,7 +389,6 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri GLOGE("Check collection name invalid. %d", errCode); return errCode; } - auto coll = Collection(collection, executor_); if (filter.empty()) { GLOGE("Filter is empty"); return -E_INVALID_ARGS; @@ -413,9 +412,10 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } + Collection coll = Collection(collection, executor_); if (isOnlyId) { - auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); std::lock_guard lock(dbMutex_); @@ -513,8 +513,8 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string if (flags == GRD_DOC_ID_DISPLAY) { ifShowId = true; } - auto coll = Collection(collection, executor_); std::lock_guard lock(dbMutex_); + Collection coll = Collection(collection, executor_); bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; @@ -559,7 +559,7 @@ int DocumentStore::EraseCollection(const std::string collectionName) int DocumentStore::GetViewType(JsonObject &jsonObj, bool &viewType) { - auto leafValue = JsonCommon::GetLeafValue(jsonObj); + std::vector leafValue = JsonCommon::GetLeafValue(jsonObj); if (leafValue.size() == 0) { return E_INVALID_ARGS; } 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 f82f17f7..5d529c8c 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 @@ -64,8 +64,8 @@ int ResultSet::GetNext() GLOGE("filter Parsed failed"); return errCode; } - auto filterObjChild = filterObj.GetChild(); - auto idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); std::string idKey = idValue.GetStringValue(); if (idKey.empty()) { GLOGE("id is empty"); @@ -73,7 +73,7 @@ int ResultSet::GetNext() } Key key(idKey.begin(), idKey.end()); Value document; - auto coll = Collection(collectionName_, store_->GetExecutor(errCode)); + Collection coll = Collection(collectionName_, store_->GetExecutor(errCode)); errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); @@ -86,7 +86,7 @@ int ResultSet::GetNext() matchDatas_ = values; } else { int errCode = 0; - auto coll = Collection(collectionName_, store_->GetExecutor(errCode)); + Collection coll = Collection(collectionName_, store_->GetExecutor(errCode)); std::vector> values; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); if (errCode != E_OK) { @@ -105,7 +105,7 @@ int ResultSet::GetNext() } } else if (index_ == 0) { int errCode = 0; - auto coll = Collection(collectionName_, store_->GetExecutor(errCode)); + Collection coll = Collection(collectionName_, store_->GetExecutor(errCode)); std::vector> values; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); if (errCode != E_OK) { @@ -133,7 +133,7 @@ int ResultSet::GetValue(char **value) GLOGE("The value vector in resultSet is empty"); return -E_NO_DATA; } - auto jsonData = matchDatas_[index_ - 1].second; + std::string jsonData = matchDatas_[index_ - 1].second; char *jsonstr = new char[jsonData.size() + 1]; if (jsonstr == nullptr) { GLOGE("Memory allocation failed!"); @@ -172,12 +172,12 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat allCutPath.emplace_back(singlePath); } if (!node->GetChild().IsNull()) { - auto nodeNew = node->GetChild(); + JsonObject nodeNew = node->GetChild(); CheckCutNode(&nodeNew, singlePath, allCutPath); } if (!node->GetNext().IsNull()) { singlePath.pop_back(); - auto nodeNew = node->GetNext(); + JsonObject nodeNew = node->GetNext(); CheckCutNode(&nodeNew, singlePath, allCutPath); } return E_OK; @@ -193,7 +193,7 @@ int ResultSet::CutJsonBranch(std::string &jsonData) std::vector> allCutPath; if (viewType_) { std::vector singlePath; - auto cjsonObjChild = cjsonObj.GetChild(); + JsonObject cjsonObjChild = cjsonObj.GetChild(); errCode = CheckCutNode(&cjsonObjChild, singlePath, allCutPath); if (errCode != E_OK) { GLOGE("The node in CheckCutNode is nullptr"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h index 6adebe7d..6ad4aa5c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h @@ -98,7 +98,7 @@ public: bool IsNull() const; int GetDeep(); enum class Type { - JSON_LEAF, + JSON_LEAF, // Corresponds to nodes of type null, number, string, true false in CJSON JSON_OBJECT, JSON_ARRAY }; 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 625d39f5..84ed2129 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 @@ -14,6 +14,7 @@ */ #include "json_object.h" + #include #include @@ -100,8 +101,7 @@ bool ValueObject::operator==(const ValueObject &other) const return false; } -JsonObject JsonObject::Parse(const std::string &jsonStr, int &errCode, - bool caseSensitive, bool isFilter) +JsonObject JsonObject::Parse(const std::string &jsonStr, int &errCode, bool caseSensitive, bool isFilter) { JsonObject obj; errCode = obj.Init(jsonStr, isFilter); @@ -121,7 +121,7 @@ JsonObject::~JsonObject() } } -bool JsonObject::operator==(const JsonObject& other) const +bool JsonObject::operator==(const JsonObject &other) const { return (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0); } @@ -578,7 +578,7 @@ cJSON *GetChildPowerMode(cJSON *cjson, const std::string &field, bool caseSens) if (!IsNumber(field)) { cjson = cjson->child; while (cjson != nullptr) { - auto resultItem = GetChild(cjson, field, caseSens); + cJSON *resultItem = GetChild(cjson, field, caseSens); if (resultItem != nullptr) { return resultItem; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp index fbd0fd84..eed4e2f5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -140,7 +140,7 @@ int SqliteStoreExecutor::InsertData(const std::string &collName, const Key &key, return E_OK; }, nullptr); - if (errCode != SQLITE_OK) { + if (errCode != E_OK) { GLOGE("[sqlite executor] Put data failed. err=%d", errCode); if (errCode == -E_ERROR) { GLOGE("have same ID before"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp index 328c87ec..4daae0f1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/sqlite_utils.cpp @@ -53,11 +53,7 @@ bool g_configLog = false; void SQLiteUtils::SqliteLogCallback(void *data, int err, const char *msg) { -#ifdef RUNNING_ON_SIMULATED_ENV - GLOGD("[SQLite] err=%d sys=%d %s msg=%s", err, errno, sqlite3_errstr(err), msg); -#else GLOGD("[SQLite] err=%d sys=%d %s", err, errno, sqlite3_errstr(err)); -#endif } int SQLiteUtils::CreateDataBase(const std::string &path, int flag, sqlite3 *&db) -- Gitee From 12a824333a01ac2a63292a9098f97babf8227dce Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 17:12:29 +0800 Subject: [PATCH 02/11] fix Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/executor/document/document_check.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp index e4d88cfe..e103c118 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp @@ -153,7 +153,7 @@ bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) int CheckCommon::CheckIdFormat(JsonObject &filterJson, bool &isIdExisit) { - auto filterObjChild = filterJson.GetChild(); + JsonObject filterObjChild = filterJson.GetChild(); ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExisit); if ((idValue.GetValueType() == ValueObject::ValueType::VALUE_NULL) && isIdExisit == false) { return E_OK; -- Gitee From 6d0c7056e695e420835f4fa03d98198f1d6d1fca Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 17:24:32 +0800 Subject: [PATCH 03/11] fix Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/executor/document/document_check.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp index e103c118..dc83ab1c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp @@ -133,7 +133,7 @@ bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) if (errCode != E_OK) { return false; } - for (auto singlePath : updatePath) { + for (const auto &singlePath : updatePath) { if (singlePath.size() > JSON_DEEP_MAX) { GLOGE("filter's json deep is deeper than JSON_DEEP_MAX"); errCode = -E_INVALID_ARGS; @@ -213,7 +213,7 @@ int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector JSON_DEEP_MAX) { return -E_INVALID_ARGS; } -- Gitee From e9e46bf7977d36ec051b3b60314d93d134a7e90e Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 18:13:43 +0800 Subject: [PATCH 04/11] Solve the problem of recursion Signed-off-by: Jeremyzz --- .../src/common/include/json_common.h | 5 +- .../gaussdb_rd/src/common/src/json_common.cpp | 74 ++++++------------- .../src/executor/document/document_check.cpp | 35 --------- .../src/executor/document/document_check.h | 1 - 4 files changed, 25 insertions(+), 90 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h index e1301386..0f0ec132 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h @@ -44,9 +44,8 @@ public: private: static bool JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); - static bool CheckNode(JsonObject &Node, std::set filedSet, bool &errFlag); - static bool CheckProjectionNode(JsonObject &Node, std::set filedSet, bool &errFlag, - bool isFirstLevel, int &errCode); + static bool CheckNode(JsonObject &Node); + static bool CheckProjectionNode(JsonObject &Node, bool isFirstLevel, int &errCode); static void CheckLeafNode(const JsonObject &Node, std::vector &leafValue); static bool IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); }; 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 383fedad..9cdf2f0c 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 @@ -84,14 +84,12 @@ std::vector JsonCommon::GetLeafValue(const JsonObject &node) return leafValue; } -bool JsonCommon::CheckNode(JsonObject &node, std::set fieldSet, bool &errFlag) +bool JsonCommon::CheckNode(JsonObject &node) { - if (!errFlag) { - return false; - } std::string fieldName; - if (!node.IsNull()) { + while (!node.IsNull()) { int ret = 0; + std::set fieldSet; bool isFieldNameExist = true; fieldName = node.GetItemField(ret); if (ret != E_OK) { @@ -101,106 +99,80 @@ bool JsonCommon::CheckNode(JsonObject &node, std::set fieldSet, boo if (isFieldNameExist) { fieldSet.insert(fieldName); if (fieldName.empty()) { - errFlag = false; return false; } } } else { - errFlag = false; return false; } for (size_t i = 0; i < fieldName.size(); i++) { if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || '_' == fieldName[i])) { - errFlag = false; return false; } if (i == 0 && (isdigit(fieldName[i]))) { - errFlag = false; return false; } } - } - if (!node.GetChild().IsNull()) { - JsonObject nodeNew = node.GetChild(); - std::set newFieldSet; - if (!CheckNode(nodeNew, newFieldSet, errFlag)) { - return false; - } - } - if (!node.GetNext().IsNull()) { - JsonObject nodeNew = node.GetNext(); - if (!CheckNode(nodeNew, fieldSet, errFlag)) { - return false; + + if (!node.GetChild().IsNull()) { + JsonObject nodeNew = node.GetChild(); + if (!CheckNode(nodeNew)) { + return false; + } } + node = node.GetNext(); } - return errFlag; + return true; } bool JsonCommon::CheckJsonField(JsonObject &jsonObj) { - std::set fieldSet; - bool errFlag = true; - return CheckNode(jsonObj, fieldSet, errFlag); + return CheckNode(jsonObj); } -bool JsonCommon::CheckProjectionNode(JsonObject &node, std::set fieldSet, bool &errFlag, - bool isFirstLevel, int &errCode) +bool JsonCommon::CheckProjectionNode(JsonObject &node, bool isFirstLevel, int &errCode) { - if (!errFlag) { - return false; - } std::string fieldName; - if (!node.IsNull()) { + while (!node.IsNull()) { int ret = 0; + std::set fieldSet; fieldName = node.GetItemField(ret); if (fieldName.empty()) { errCode = -E_INVALID_ARGS; - errFlag = false; return false; } if (fieldSet.find(fieldName) == fieldSet.end() && ret == E_OK) { fieldSet.insert(fieldName); } else { errCode = -E_INVALID_JSON_FORMAT; - errFlag = false; return false; } for (size_t i = 0; i < fieldName.size(); i++) { if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || ('_' == fieldName[i]) || (isFirstLevel && '.' == fieldName[i]))) { errCode = -E_INVALID_ARGS; - errFlag = false; return false; } if (i == 0 && (isdigit(fieldName[i]))) { errCode = -E_INVALID_ARGS; - errFlag = false; return false; } } - } - if (!node.GetChild().IsNull()) { - JsonObject nodeNew = node.GetChild(); - std::set newFieldSet; - if (!CheckProjectionNode(nodeNew, newFieldSet, errFlag, false, errCode)) { - return false; - } - } - if (!node.GetNext().IsNull()) { - JsonObject nodeNew = node.GetNext(); - if (!CheckProjectionNode(nodeNew, fieldSet, errFlag, isFirstLevel, errCode)) { - return false; + if (!node.GetChild().IsNull()) { + JsonObject nodeNew = node.GetChild(); + if (!CheckProjectionNode(nodeNew, false, errCode)) { + return false; + } } + node = node.GetNext(); } - return errFlag; + return true; } bool JsonCommon::CheckProjectionField(JsonObject &jsonObj, int &errCode) { - std::set fieldSet; - bool errFlag = true; bool isFirstLevel = true; - return CheckProjectionNode(jsonObj, fieldSet, errFlag, isFirstLevel, errCode); + return CheckProjectionNode(jsonObj, isFirstLevel, errCode); } int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp index dc83ab1c..9be552f9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp @@ -116,41 +116,6 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< return E_OK; } -bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) -{ - if (updateStr.empty()) { - errCode = -E_INVALID_ARGS; - return false; - } - - JsonObject updateObj = JsonObject::Parse(updateStr, errCode, true); - if (updateObj.IsNull() || errCode != E_OK) { - GLOGE("Parse update document failed. %d", errCode); - return false; - } - std::vector> updatePath; - updatePath = JsonCommon::ParsePath(updateObj, errCode); - if (errCode != E_OK) { - return false; - } - for (const auto &singlePath : updatePath) { - if (singlePath.size() > JSON_DEEP_MAX) { - GLOGE("filter's json deep is deeper than JSON_DEEP_MAX"); - errCode = -E_INVALID_ARGS; - return false; - } - } - - JsonObject filterId = updateObj.GetObjectItem("_id", errCode); - if (errCode != -E_NOT_FOUND) { - GLOGE("Can not change '_id' with update document failed."); - errCode = -E_INVALID_ARGS; - return false; - } - - return true; -} - int CheckCommon::CheckIdFormat(JsonObject &filterJson, bool &isIdExisit) { JsonObject filterObjChild = filterJson.GetChild(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h index c9b94350..51ca33e7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h @@ -33,7 +33,6 @@ public: static int CheckIdFormat(JsonObject &data, bool &isIdExisit); static int CheckDocument(JsonObject &document); static int CheckUpdata(JsonObject &updata, std::vector> &path); - static bool CheckDocument(const std::string &updateStr, int &errCode); static int CheckProjection(JsonObject &projectionObj, std::vector> &path); }; using Key = std::vector; -- Gitee From d0dd64a1ad69ed3afaad1d45f367e34ad7547e68 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 18:32:24 +0800 Subject: [PATCH 05/11] fix Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/executor/document/grd_resultset_api.cpp | 2 -- .../data_share/gaussdb_rd/src/interface/include/collection.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index 20cbe48a..524a44ee 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -29,8 +29,6 @@ int32_t GRD_Next(GRD_ResultSet *resultSet) GLOGE("resultSet is nullptr"); return GRD_INVALID_ARGS; }; - std::mutex dbMutex; - std::lock_guard lock(dbMutex); int ret = resultSet->resultSet_.GetNext(); return TransferDocErr(ret); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 2b0a982d..129eb54d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -25,7 +25,7 @@ namespace DocumentDB { class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); - Collection(const Collection &a){}; + Collection(const Collection &a) = default; Collection(){}; ~Collection(); -- Gitee From ab40316e58faa0f6d6ce1007aeba00ac72b433ca Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 18:55:27 +0800 Subject: [PATCH 06/11] fix Signed-off-by: Jeremyzz --- .../src/executor/document/document_check.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp index 9be552f9..e7e6756c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.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(); @@ -83,7 +83,8 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< return -E_INVALID_ARGS; } } - if (!filterObj.GetChild().GetNext().IsNull()) { + int errCode = E_OK; + if (!filterObj.GetObjectItem("_id", errCode).GetNext().IsNull() && errCode != E_OK) { isOnlyId = false; } for (size_t i = 0; i < filterPath.size(); i++) { @@ -144,12 +145,10 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) GLOGE("Document Id format is illegal"); return ret; } - if (!documentObj.GetChild().IsNull()) { - JsonObject documentObjChild = documentObj.GetChild(); - if (!JsonCommon::CheckJsonField(documentObjChild)) { - GLOGE("Document json field format is illegal"); - return -E_INVALID_ARGS; - } + JsonObject documentObjChild = documentObj.GetChild(); + if (!JsonCommon::CheckJsonField(documentObjChild)) { + GLOGE("Document json field format is illegal"); + return -E_INVALID_ARGS; } return E_OK; } -- Gitee From 3e02e1b21d39944272213d678ecf906e662441ca Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 19:36:57 +0800 Subject: [PATCH 07/11] fix 22 Signed-off-by: Jeremyzz --- .../src/common/include/json_common.h | 4 ++-- .../gaussdb_rd/src/common/src/json_common.cpp | 5 ++--- .../src/executor/document/document_check.cpp | 2 +- .../src/executor/document/document_check.h | 2 +- .../executor/document/grd_document_api.cpp | 12 +++-------- .../src/interface/include/collection.h | 2 +- .../src/interface/include/projection_tree.h | 5 +---- .../src/interface/include/result_set.h | 3 +-- .../src/interface/src/collection.cpp | 2 +- .../src/interface/src/document_store.cpp | 12 ++++++----- .../src/interface/src/projection_tree.cpp | 20 ++++++++----------- .../src/interface/src/result_set.cpp | 10 +++++----- .../src/oh_adapter/include/json_object.h | 1 - 13 files changed, 33 insertions(+), 47 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h index 0f0ec132..ec9e465f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/json_common.h @@ -29,8 +29,8 @@ public: JsonCommon() = default; ~JsonCommon(); - static ValueObject GetValueByField(JsonObject &node, const std::string &field); - static ValueObject GetValueByField(JsonObject &node, const std::string &field, bool &isFieldExist); + static ValueObject GetValueInSameLevel(JsonObject &node, const std::string &field); + static ValueObject GetValueInSameLevel(JsonObject &node, const std::string &field, bool &isFieldExist); static bool CheckJsonField(JsonObject &node); static bool CheckProjectionField(JsonObject &node, int &errCode); static int ParseNode(JsonObject &Node, std::vector singlePath, 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 9cdf2f0c..810e40a1 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 @@ -19,10 +19,9 @@ #include "doc_errno.h" #include "log_print.h" -#include "securec.h" namespace DocumentDB { -ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &field) +ValueObject JsonCommon::GetValueInSameLevel(JsonObject &node, const std::string &field) { while (!node.IsNull()) { if (node.GetItemField() == field) { @@ -38,7 +37,7 @@ ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &fie return ValueObject(); } -ValueObject JsonCommon::GetValueByField(JsonObject &node, const std::string &field, bool &isFieldExist) +ValueObject JsonCommon::GetValueInSameLevel(JsonObject &node, const std::string &field, bool &isFieldExist) { while (!node.IsNull()) { if (node.GetItemField() == field) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp index e7e6756c..db1cb132 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.cpp @@ -120,7 +120,7 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< int CheckCommon::CheckIdFormat(JsonObject &filterJson, bool &isIdExisit) { JsonObject filterObjChild = filterJson.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExisit); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExisit); if ((idValue.GetValueType() == ValueObject::ValueType::VALUE_NULL) && isIdExisit == false) { return E_OK; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h index 51ca33e7..08318370 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/document_check.h @@ -25,7 +25,7 @@ namespace DocumentDB { class JsonCommon; class CheckCommon { public: - CheckCommon() = default; + CheckCommon() = delete; ~CheckCommon() = default; static bool CheckCollectionName(const std::string &collectionName, std::string &formattedName, int &errCode); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp index 5fffa173..6bf15227 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp @@ -89,20 +89,14 @@ int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter } int ret = db->store_->DeleteDocument(collectionName, filter, flags); int errCode = TransferDocErr(ret); - int deleteCount = 0; switch (errCode) { case GRD_OK: - deleteCount = 1; - return deleteCount; - break; + return 1; // The amount of text deleted case GRD_NO_DATA: - deleteCount = 0; - return deleteCount; - break; + return 0; default: - break; + return errCode; } - return errCode; } int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, GRD_ResultSet **resultSet) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 129eb54d..72335d46 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -32,7 +32,7 @@ public: int PutDocument(const Key &key, const Value &document); int InsertDocument(const Key &key, const Value &document); int GetDocument(const Key &key, Value &document) const; - int GetFieldedDocument(const JsonObject &filterObj, std::vector> &values) const; + int GetMatchedDocument(const JsonObject &filterObj, std::vector> &values) const; int DeleteDocument(const Key &key); int IsCollectionExists(int &errCode); int UpsertDocument(const std::string &id, const std::string &document, bool isReplace = true); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h index a2763707..f7c7b095 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h @@ -25,7 +25,7 @@ namespace DocumentDB { struct ProjectionNode { - std::unordered_map SonNode; + std::unordered_map sonNode; bool isDeepest; int Deep; int ViewType; @@ -42,9 +42,6 @@ struct ProjectionNode { }; class ProjectionTree { public: - ProjectionTree(); - ~ProjectionTree(); - int ParseTree(std::vector> &path); bool SearchTree(std::vector &singlePath, int &index); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index 28187d30..0ccff761 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -17,6 +17,7 @@ #define RESULTSET_H #include +#include #include "doc_errno.h" #include "document_check.h" @@ -24,8 +25,6 @@ #include "grd_base/grd_type_export.h" #include "json_object.h" #include "projection_tree.h" -#include "securec.h" -#include "vector" namespace DocumentDB { class ResultSet { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index 651d1ece..44c513aa 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -71,7 +71,7 @@ int Collection::GetDocument(const Key &key, Value &document) const return executor_->GetData(name_, key, document); } -int Collection::GetFieldedDocument(const JsonObject &filterObj, +int Collection::GetMatchedDocument(const JsonObject &filterObj, std::vector> &values) const { if (executor_ == nullptr) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index 64bf026a..9225c639 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -176,7 +176,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri Collection coll = Collection(collection, executor_); if (isOnlyId) { JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); std::string docId = idValue.GetStringValue(); std::lock_guard lock(dbMutex_); bool isCollectionExist = coll.IsCollectionExists(errCode); @@ -282,7 +282,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri return -E_INVALID_ARGS; } JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); std::string docId = idValue.GetStringValue(); JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); documentObj.InsertItemObject(0, idObj); @@ -290,12 +290,14 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri errCode = coll.UpsertDocument(docId, addedIdDocument, isReplace); if (errCode == E_OK) { errCode = 1; // upsert one record. + } else if (errCode == -E_NOT_FOUND) { + errCode = E_OK; } return errCode; } bool isIdExist; JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID, isIdExist); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); if (!isIdExist) { return -E_INVALID_ARGS; } @@ -360,7 +362,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } JsonObject documentObjChild = documentObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(documentObjChild, KEY_ID); + ValueObject idValue = JsonCommon::GetValueInSameLevel(documentObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); Value value(document.begin(), document.end()); @@ -415,7 +417,7 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri Collection coll = Collection(collection, executor_); if (isOnlyId) { JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); std::lock_guard lock(dbMutex_); 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 1dd3afbd..bd41e033 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 @@ -19,21 +19,17 @@ namespace DocumentDB { const int JSON_DEEP_MAX = 4; -ProjectionTree::ProjectionTree() {} - -ProjectionTree::~ProjectionTree() {} - int ProjectionTree::ParseTree(std::vector> &path) { ProjectionNode *node = &node_; - if (node == NULL) { + if (node == nullptr) { return E_OK; } for (auto singlePath : path) { node = &node_; for (size_t j = 0; j < singlePath.size(); j++) { - if (node->SonNode[singlePath[j]] != nullptr) { - node = node->SonNode[singlePath[j]]; + if (node->sonNode[singlePath[j]] != nullptr) { + node = node->sonNode[singlePath[j]]; if (j < singlePath.size() - 1 && node->isDeepest) { return -E_INVALID_ARGS; } @@ -52,8 +48,8 @@ int ProjectionTree::ParseTree(std::vector> &path) return -E_INVALID_ARGS; } node->isDeepest = false; - node->SonNode[singlePath[j]] = tempNode; - node = node->SonNode[singlePath[j]]; + node->sonNode[singlePath[j]] = tempNode; + node = node->sonNode[singlePath[j]]; } } } @@ -67,8 +63,8 @@ bool ProjectionTree::SearchTree(std::vector &singlePath, int &index if (node->isDeepest) { index = i; } - if (node->SonNode[singlePath[i]] != nullptr) { - node = node->SonNode[singlePath[i]]; + if (node->sonNode[singlePath[i]] != nullptr) { + node = node->sonNode[singlePath[i]]; } else { return false; } @@ -78,7 +74,7 @@ bool ProjectionTree::SearchTree(std::vector &singlePath, int &index int ProjectionNode::DeleteProjectionNode() { - for (auto item : SonNode) { + for (auto item : sonNode) { if (item.second != nullptr) { delete item.second; item.second = nullptr; 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 5d529c8c..e37e072f 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 @@ -13,7 +13,7 @@ * limitations under the License. */ #include "result_set.h" - +#include "securec.h" #include "log_print.h" namespace DocumentDB { @@ -65,7 +65,7 @@ int ResultSet::GetNext() return errCode; } JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueByField(filterObjChild, KEY_ID); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); std::string idKey = idValue.GetStringValue(); if (idKey.empty()) { GLOGE("id is empty"); @@ -93,7 +93,7 @@ int ResultSet::GetNext() GLOGE("filter Parsed failed"); return errCode; } - errCode = coll.GetFieldedDocument(filterObj, values); + errCode = coll.GetMatchedDocument(filterObj, values); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); return -E_NO_DATA; @@ -112,7 +112,7 @@ int ResultSet::GetNext() GLOGE("filter Parsed failed"); return errCode; } - errCode = coll.GetFieldedDocument(filterObj, values); + errCode = coll.GetMatchedDocument(filterObj, values); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); return -E_NO_DATA; @@ -139,7 +139,7 @@ int ResultSet::GetValue(char **value) GLOGE("Memory allocation failed!"); return -E_FAILED_MEMORY_ALLOCATE; } - errno_t err = strcpy_s(jsonstr, jsonData.size() + 1, jsonData.c_str()); + int err = strcpy_s(jsonstr, jsonData.size() + 1, jsonData.c_str()); if (err != 0) { GLOGE("strcpy_s failed"); delete[] jsonstr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h index 6ad4aa5c..a195f443 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/include/json_object.h @@ -44,7 +44,6 @@ public: int64_t GetIntValue() const; double GetDoubleValue() const; std::string GetStringValue() const; - bool operator==(const ValueObject &other) const; private: ValueType valueType = ValueType::VALUE_NULL; -- Gitee From 9c13ad1af6d5afd84da9d61a9f0a86aaad6ab5da Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 19:46:59 +0800 Subject: [PATCH 08/11] fix Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/common/src/log_print.cpp | 2 +- .../src/oh_adapter/src/json_object.cpp | 20 ------------------- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp index 8cdbae4c..4ff8fa98 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp @@ -27,7 +27,7 @@ void PrintLog(Logger::Level level, const char *tag, const std::string &msg) return; } const std::string format = "%{public}s"; - OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag }; + OHOS::HiviewDFX::HiLogLabel label = { LOG_CORE, 0xD001631, tag }; // The identity of the log switch (level) { case Logger::Level::LEVEL_DEBUG: (void)OHOS::HiviewDFX::HiLog::Debug(label, format.c_str(), msg.c_str()); 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 84ed2129..347c4c80 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 @@ -81,26 +81,6 @@ std::string ValueObject::GetStringValue() const return stringValue; } -bool ValueObject::operator==(const ValueObject &other) const -{ - if (this->GetValueType() != other.GetValueType()) { - return false; - } - switch (this->GetValueType()) { - case ValueObject::ValueType::VALUE_NULL: - return true; - case ValueObject::ValueType::VALUE_BOOL: - return (this->GetBoolValue() == other.GetBoolValue()) ? true : false; - case ValueObject::ValueType::VALUE_NUMBER: - return (this->GetDoubleValue() == other.GetDoubleValue()) ? true : false; - case ValueObject::ValueType::VALUE_STRING: - return (this->GetStringValue() == other.GetStringValue()) ? true : false; - default: - break; - } - return false; -} - JsonObject JsonObject::Parse(const std::string &jsonStr, int &errCode, bool caseSensitive, bool isFilter) { JsonObject obj; -- Gitee From 2fc571a8781b3c542999653c48baca7f9b48feb3 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 20:17:09 +0800 Subject: [PATCH 09/11] fix check args nullptr Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/executor/document/grd_resultset_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index 524a44ee..e2e2d46e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -35,7 +35,7 @@ int32_t GRD_Next(GRD_ResultSet *resultSet) int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) { - if (resultSet == nullptr) { + if (resultSet == nullptr || value != nullptr) { GLOGE("resultSet is nullptr,cant get value from it"); return GRD_INVALID_ARGS; }; -- Gitee From bfbe363739a6c9c4ce4c5389c5ef8dad82b2b8ea Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 20:29:15 +0800 Subject: [PATCH 10/11] fix check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/executor/document/grd_resultset_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index e2e2d46e..19b681a2 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -35,7 +35,7 @@ int32_t GRD_Next(GRD_ResultSet *resultSet) int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) { - if (resultSet == nullptr || value != nullptr) { + if (resultSet == nullptr || value == nullptr) { GLOGE("resultSet is nullptr,cant get value from it"); return GRD_INVALID_ARGS; }; -- Gitee From 42b4f026e5e9e3e3e255ab22e97dc8cc1bccf33b Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 20:31:09 +0800 Subject: [PATCH 11/11] fix Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/include/collection.h | 2 +- .../gaussdb_rd/src/interface/include/document_store.h | 2 +- .../data_share/gaussdb_rd/src/interface/src/collection.cpp | 6 ++++++ .../gaussdb_rd/src/interface/src/document_store.cpp | 4 ++-- .../data_share/gaussdb_rd/src/interface/src/result_set.cpp | 6 +++--- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 72335d46..570f89ae 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -25,7 +25,7 @@ namespace DocumentDB { class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); - Collection(const Collection &a) = default; + Collection(const Collection &other); Collection(){}; ~Collection(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h index 9fb37fd7..950ca7b7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/document_store.h @@ -47,7 +47,7 @@ public: int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet); - KvStoreExecutor *GetExecutor(int errCode); + Collection GetCollection(std::string &collectionName); bool IsCollectionOpening(const std::string collection); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index 44c513aa..e4c2d8fd 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -33,6 +33,12 @@ Collection::Collection(const std::string &name, KvStoreExecutor *executor) : exe name_ = COLL_PREFIX + lowerCaseName; } +Collection::Collection(const Collection &other) +{ + name_ = other.name_; + executor_ = other.executor_; +} + Collection::~Collection() { executor_ = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index 9225c639..39eea099 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -449,9 +449,9 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri Key key(id.begin(), id.end()); return coll.DeleteDocument(key); } -KvStoreExecutor *DocumentStore::GetExecutor(int errCode) +Collection DocumentStore::GetCollection(std::string &collectionName) { - return executor_; + return Collection(collectionName, executor_); } int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) 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 e37e072f..6fecf04e 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 @@ -73,7 +73,7 @@ int ResultSet::GetNext() } Key key(idKey.begin(), idKey.end()); Value document; - Collection coll = Collection(collectionName_, store_->GetExecutor(errCode)); + Collection coll = store_->GetCollection(collectionName_); errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { GLOGE("Cant get value from db"); @@ -86,7 +86,7 @@ int ResultSet::GetNext() matchDatas_ = values; } else { int errCode = 0; - Collection coll = Collection(collectionName_, store_->GetExecutor(errCode)); + Collection coll = store_->GetCollection(collectionName_); std::vector> values; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); if (errCode != E_OK) { @@ -105,7 +105,7 @@ int ResultSet::GetNext() } } else if (index_ == 0) { int errCode = 0; - Collection coll = Collection(collectionName_, store_->GetExecutor(errCode)); + Collection coll = store_->GetCollection(collectionName_); std::vector> values; JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); if (errCode != E_OK) { -- Gitee