From 842bbe88aff43d2ad79a509c038b5a7ab4955f99 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Fri, 5 May 2023 18:53:23 +0800 Subject: [PATCH 1/7] fix do not return faild when collection dont exsit bug Signed-off-by: Jeremyzz --- .../src/interface/src/document_store.cpp | 34 ++++++++++++++++++- .../unittest/api/documentdb_data_test.cpp | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 210316d8..a3856fb9 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -155,6 +155,13 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } bool isOnlyId = true; auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; @@ -235,6 +242,13 @@ 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_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; @@ -286,6 +300,13 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } if (document.length() + 1 > JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; @@ -321,7 +342,11 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); - if (!coll.IsCollectionExists(errCode)) { + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { return -E_INVALID_ARGS; } if (filter.empty()) { @@ -433,6 +458,13 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string ifShowId = true; } auto coll = Collection(collection, executor_); + int IsCollectionExist = coll.IsCollectionExists(errCode); + if (errCode != E_OK) { + return errCode; + } + if (!IsCollectionExist) { + return -E_INVALID_ARGS; + } std::lock_guard lock(dbMutex_); if (!coll.FindDocument()) { GLOGE("no corresponding table name"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index 17ff76b7..fa4c609f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -150,7 +150,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest007, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string val = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_NO_DATA); + EXPECT_EQ(GRD_UpsertDoc(g_db, "collection_not_exists", filter.c_str(), val.c_str(), GRD_DOC_REPLACE), GRD_INVALID_ARGS); } /** -- Gitee From a584bfcb3835a9445be3095cb732b6f2f974b4f6 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 6 May 2023 19:53:44 +0800 Subject: [PATCH 2/7] Solve the problem that the field name of the filter parameter is not illegally validated Signed-off-by: Jeremyzz --- .../src/executor/document/document_check.cpp | 9 ++- .../unittest/api/documentdb_find_test.cpp | 57 +++++++------------ 2 files changed, 26 insertions(+), 40 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp index 285036fc..dba81784 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp @@ -108,13 +108,16 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< isOnlyId = false; } for (int i = 0; i < filterPath.size(); i++) { - for (auto fieldName : filterPath[i]) { - for (int j = 0; j < fieldName.size(); j++) { - if (!((isalpha(fieldName[j])) || (isdigit(fieldName[j])) || ('_' == fieldName[j]))) { + for (int j = 0; j < filterPath[i].size(); j++) { + for (auto oneChar : filterPath[i][j]) { + if (!((isalpha(oneChar)) || (isdigit(oneChar)) || ('_' == oneChar))) { return -E_INVALID_ARGS; } } } + if (!filterPath[i].empty() && !filterPath[i][0].empty() && isdigit(filterPath[i][0][0])) { + return -E_INVALID_ARGS; + } } bool isIdExisit = false; int ret = CheckIdFormat(filterObj, isIdExisit); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp index 3691ff16..9bdae66a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp @@ -1520,43 +1520,26 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest057, TestSize.Level1) // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_NOT_AVAILABLE); EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } -/** - * @tc.name: DocumentFindApiTest058 - * @tc.desc: Test findDoc with no _id. - * @tc.type: FUNC - * @tc.require: - * @tc.author: mazhao - */ -HWTEST_F(DocumentFindApiTest, DocumentFindApiTest058, TestSize.Level1) -{ - /** - * @tc.steps: step1. Create filter with _id and get the record according to filter condition. - * @tc.expected: step1. Succeed to get the record, the matching record is g_document6. - */ - // const char *filter = "{\"personInfo.0.school\" : \"B\", \"$personInfo.0.age\" : 15}"; - // GRD_ResultSet *resultSet = nullptr; - // Query query = {filter, "{}"}; - // EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); - // EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); - // char *value = NULL; - // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - // EXPECT_EQ(GRD_FreeValue(value), GRD_OK); - /** - * @tc.steps: step2. Invoke GRD_Next to get the next matching value. Release resultSet. - * @tc.expected: step2. Cannot get next record, return GRD_NO_DATA. - */ - // EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - // CompareValue(value, g_document2); - // EXPECT_EQ(GRD_FreeValue(value), GRD_OK); - // EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - // CompareValue(value, g_document13); - // EXPECT_EQ(GRD_FreeValue(value), GRD_OK); - // EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - // CompareValue(value, g_document13); - //EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); +HWTEST_F(DocumentFindApiTest, DocumentFindApiTest058, TestSize.Level1) +{ + GRD_ResultSet *resultSet = nullptr; + Query query; + query.filter = R"({abc: true})"; + query.projection = "{}"; + ASSERT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); + ASSERT_EQ(resultSet, nullptr); + + query.filter = R"({'abc': 123})"; + ASSERT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_FORMAT); + ASSERT_EQ(resultSet, nullptr); + + query.filter = R"({"123a1": 123})"; + ASSERT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); + ASSERT_EQ(resultSet, nullptr); + + query.filter = R"({"abc$": 123})"; + ASSERT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_INVALID_ARGS); + ASSERT_EQ(resultSet, nullptr); } \ No newline at end of file -- Gitee From 165fa710f9e0e90caef40d25bab65c16e5770e5d Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 18:17:17 +0800 Subject: [PATCH 3/7] fix bug Signed-off-by: Jeremyzz --- .../src/oh_adapter/include/json_object.h | 1 + .../unittest/api/documentdb_data_test.cpp | 27 +------------------ .../documentdb_json_common_test.cpp | 2 +- 3 files changed, 3 insertions(+), 27 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h index c7a1ae8a..8db800e6 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h @@ -61,6 +61,7 @@ using JsonFieldPath = std::vector; class JsonObject { public: static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = true); + bool operator==(const JsonObject& other) const; ~JsonObject(); std::string Print() const; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index c90def1a..f818888b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -175,6 +175,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest009, TestSize.Level0) { int result = GRD_UpsertDoc(g_db, g_coll, R"({"_id" : "abcde"})", R"({"a00001":1, "a00001":2})", 0); ASSERT_EQ(result, GRD_INVALID_FORMAT); +} HWTEST_F(DocumentDBDataTest, UpsertDataTest010, TestSize.Level0) { std::string filter = R""({"_id":"1234", "aaa" : "bbb"})""; @@ -299,32 +300,6 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest007, TestSize.Level0) } -HWTEST_F(DocumentDBDataTest, UpdateDataTest008, TestSize.Level0) -{ -<<<<<<< fixUpdateLargeData - std::string filter = R""({"_id":"1234"})""; - std::string document = R""({"_id":"1234", "field1":{"c_field":{"cc_field":{"ccc_field":1}}}, "field2" : 2})""; - - EXPECT_EQ(GRD_InsertDoc(g_db, g_coll, document.c_str(), 0), GRD_OK); - - std::string updata = R""({"field1":1, "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; - EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), updata.c_str(), 0), 1); - - GRD_ResultSet *resultSet = nullptr; - const char *projection = "{}"; - Query query = { filter.c_str(), projection }; - EXPECT_EQ(GRD_FindDoc(g_db, g_coll, query, 1, &resultSet), GRD_OK); - EXPECT_EQ(GRD_Next(resultSet), GRD_OK); - char *value = NULL; - EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); - string valueStr = value; - string repectStr = R""({"_id":"1234","field1":1,"field2":2,"FIELD1":[1,true,1.23456789,"hello world!",null]})""; - EXPECT_EQ((valueStr == repectStr), 1); - EXPECT_EQ(GRD_FreeValue(value), GRD_OK); - EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); - -} - HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp index 5a0c3626..588d2bfb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -621,7 +621,7 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest023, TestSize.Leve EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj1, errCode), false); } -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest023, TestSize.Level0) +HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest024, TestSize.Level0) { std::string document = "{\"name\": 1, \"personInfo.school\": 1, \"personInfo.age\": 1}"; int errCode = E_OK; -- Gitee From 1e1c7c0d65cf8c73af6cfe68923c7539a76c444d Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Wed, 17 May 2023 16:45:43 +0800 Subject: [PATCH 4/7] Fix the issue of excessive parameter transfer Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 9 ++++----- .../unittest/oh_adapter/documentdb_json_common_test.cpp | 4 ++-- 2 files changed, 6 insertions(+), 7 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 e63cfbff..f8785b70 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 @@ -500,7 +500,7 @@ bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const } bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const JsonObject &father, const JsonObject &item, - bool &isAddedFlag, int &externErrCode) + int &externErrCode) { bool isCollapse = false; JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); @@ -510,6 +510,7 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json int errCode = E_OK; JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); std::string lastFieldName = itemPath.back(); + int isAddedFlag = false; if (errCode != E_OK) { isAddedFlag = true; AddSpliteField(src, item, itemPath, externErrCode); @@ -544,9 +545,8 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isReplace) { int externErrCode = E_OK; - bool isAddedFlag = false; JsonObjectIterator(add, {}, - [&src, &externErrCode, &isReplace, &isAddedFlag](const JsonFieldPath &path, const JsonObject &father, + [&src, &externErrCode, &isReplace](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { bool isCollapse = false; JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); @@ -562,7 +562,6 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl if (!ret) { return false; } - isAddedFlag = true; return false; } else { if (isReplace) { @@ -570,7 +569,7 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isRepl externErrCode = -E_NO_DATA; return false; } - return JsonNodeAppend(src, path, father, item, isAddedFlag, externErrCode); + return JsonNodeAppend(src, path, father, item, externErrCode); } }); return externErrCode; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp index aca10555..bfe3a846 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -286,8 +286,8 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) { - std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; - std::string updateDoc = R""({"name.0":"GG"})""; + std::string document = R""({"name":{"first":"Xue","second":"Lang"}, "info":"AA"})""; + std::string updateDoc = R""({"info":"GG", "name.0":"GG"})""; int errCode = E_OK; JsonObject src = JsonObject::Parse(document, errCode); -- Gitee From 432e374afa735e6f41395fcf8776b5b02da6fcda Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 18 May 2023 10:45:28 +0800 Subject: [PATCH 5/7] fixPreviousObservations Signed-off-by: Jeremyzz --- .../src/common/include/json_common.h | 3 +-- .../gaussdb_rd/src/common/src/json_common.cpp | 19 +++++++++---------- .../src/interface/include/document_store.h | 2 +- .../src/interface/src/document_store.cpp | 4 ++-- 4 files changed, 13 insertions(+), 15 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 4e8cd1ae..a3a2b61d 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 68d832f5..e3364e65 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 @@ -543,9 +543,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; @@ -626,7 +625,7 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & isMatchFlag = isEqual; } isAlreadyMatched = isMatchFlag; - return false; // Both leaf node, no need iterate + return false; // Both leaf node, no need iterate } else if (srcItem.GetType() != item.GetType()) { if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { // srcItem Type is ARRAY, item Type is not ARRAY bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); @@ -638,13 +637,14 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & isMatchFlag = false; return false; // Different node types, overwrite directly, skip child node } - return true; // Both array or object + return true; // Both array or object } 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 +659,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 +668,6 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject } return false; } - return IsObjectItemMatch(srcItem, item, isAlreadyMatched, isCollapse, isMatchFlag); } @@ -685,14 +684,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 cf25d614..cefdc9e3 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 d6fe2935..48cbfeae 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"); -- Gitee From 8fe976ed9c701209af8f4fcc7544cdc737c87124 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 18 May 2023 11:09:32 +0800 Subject: [PATCH 6/7] fix 38 code check Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 5 ++++- .../data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 e3364e65..6d0342d7 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) { @@ -611,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; } 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 e607ed65..d414a752 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 our 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()) { -- Gitee From a38d2fff7ed9b9c19e7b67ab4923dc249914aa1e Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 18 May 2023 15:09:44 +0800 Subject: [PATCH 7/7] fix code check opinion Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 6 +++--- .../gaussdb_rd/src/oh_adapter/src/json_object.cpp | 2 +- 2 files changed, 4 insertions(+), 4 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 89bb9570..7380fa09 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 @@ -514,7 +514,7 @@ bool JsonNodeAppend(const JsonObject &src, const JsonFieldPath &path, const Json 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. + // 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); @@ -628,7 +628,7 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & isMatchFlag = isEqual; } isAlreadyMatched = isMatchFlag; - return false; // Both leaf node, no need iterate + return false; // Both leaf node, no need iterate } else if (srcItem.GetType() != item.GetType()) { if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { // srcItem Type is ARRAY, item Type is not ARRAY bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); @@ -640,7 +640,7 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & isMatchFlag = false; return false; // Different node types, overwrite directly, skip child node } - return true; // Both array or object + return true; // Both array or object } bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, 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 d414a752..7ac3a08c 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,7 +611,7 @@ 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 our target is an object, +// 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 { -- Gitee