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 4e8cd1ae69c42707aa6dae872dbea5bd5234e0a8..a3a2b61d889f66a939804d262e82ccae25b2395a 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 @@ -40,12 +40,11 @@ public: private: static bool JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); + bool &isCollapse, int &isMatchFlag); 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); - static bool IsObjectItemMatch(const JsonObject &srcItem, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag); }; 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 68d832f5627c447e4c30fe6e45e9241dc72b9307..7380fa09138ec33e12a6d0bec91176f296d0853d 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 @@ -513,6 +513,9 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json AddSpliteField(src, item, itemPath, externErrCode); return false; } + // This condition is to determine that the path has a point operator, + // and the name of the last path cannot be a number or the srcItem to be added is an array, otherwise. + // adding a node with the number fieldName does not legal. if (isCollapse && (!IsNumber(lastFieldName) || srcFatherItem.GetType() == JsonObject::Type::JSON_ARRAY)) { errCode = srcFatherItem.AddItemToObject(lastFieldName, item); if (errCode != E_OK) { @@ -543,9 +546,8 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl { int externErrCode = E_OK; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, - const JsonObject &item) { - bool isCollapse = false; + [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { + bool isCollapse = false; // Whether there is a path generated by the dot operator, such as t1.t2.t3 JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); if (src.IsFieldExists(itemPath)) { int errCode = E_OK; @@ -612,7 +614,7 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & { if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY && item.GetType() == JsonObject::Type::JSON_ARRAY && !isAlreadyMatched) { - bool isEqual = (srcItem.Print() == item.Print()); + bool isEqual = (srcItem == item); if (!isEqual) { // Filter value is No equal with src isMatchFlag = isEqual; } @@ -642,9 +644,10 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & } bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) + bool &isCollapse, int &isMatchFlag) { int errCode; + int isAlreadyMatched = 0; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { isMatchFlag = true; @@ -659,8 +662,8 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK - isMatchFlag = true; isAlreadyMatched = 1; + isMatchFlag = true; break; } isMatchFlag = false; @@ -668,7 +671,6 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject } return false; } - return IsObjectItemMatch(srcItem, item, isAlreadyMatched, isCollapse, isMatchFlag); } @@ -685,14 +687,14 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target JsonFieldPath itemPath = SplitePath(path, isCollapse); if (src.IsFieldExistsPowerMode(itemPath)) { if (isCollapse) { - return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + return JsonEqualJudge(itemPath, src, item, isCollapse, isMatchFlag); } else { JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode != E_OK) { return false; } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { - return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + return JsonEqualJudge(itemPath, src, item, isCollapse, isMatchFlag); } if (srcItem == item) { isMatchFlag = true; 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 cf25d6144c737b120f722892c3ef466447efac1e..cefdc9e308305435398eaf9b256ecb24bcece392 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 @@ -50,7 +50,7 @@ public: Collection GetCollection(std::string &collectionName); - bool IsCollectionOpening(const std::string &collection); + bool IsExistResultSet(const std::string &collection); int EraseCollection(const std::string &collectionName); 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 fc4151a1e651abe2723126e1f1ad79a6f0409644..cb1947eb1f12c6eef18f91932c972efe84e85e74 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 @@ -650,7 +650,7 @@ int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_pt std::lock_guard lock(dbMutex_); int errCode = E_OK; Collection coll = Collection(context->collectionName, executor_); - if (IsCollectionOpening(context->collectionName)) { + if (IsExistResultSet(context->collectionName)) { return -E_RESOURCE_BUSY; } if (executor_ == nullptr) { @@ -717,7 +717,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return InitFindResultSet(grdResultSet, context); } -bool DocumentStore::IsCollectionOpening(const std::string &collection) +bool DocumentStore::IsExistResultSet(const std::string &collection) { if (collections_.find(collection) != collections_.end()) { GLOGE("DB is resource busy"); 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 e607ed65f85618c61776f179868ea17b270cf999..7ac3a08c0717fc083ac31ac794a74bb24002bb12 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 @@ -611,6 +611,8 @@ JsonObject JsonObject::FindItem(const JsonFieldPath &jsonPath, int &errCode) con return item; } +// Compared with the non-powerMode mode, the node found by this function is an Array, and target is an object, +// if the Array contains the same object as the target, it can match this object in this mode. JsonObject JsonObject::FindItemPowerMode(const JsonFieldPath &jsonPath, int &errCode) const { if (jsonPath.empty()) {