From 710e889bac6a28ff54b4ea971529213c2bd96dfd Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 6 May 2023 09:37:59 +0800 Subject: [PATCH 1/8] fix match bug Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/common/src/json_common.cpp | 2 +- .../gaussdb_rd_simple/src/oh_adapter/include/json_object.h | 1 + .../gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index c213f858..9a0b814c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -658,7 +658,7 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); } - if (srcItem.Print() == item.Print()) { + if (srcItem == item) { isMatchFlag = true; isAlreadyMatched = true; return false; 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 f2056984..bcd74b4d 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 = false); + bool operator==(const JsonObject& other) const; ~JsonObject(); std::string Print() const; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index fe6106e2..d0e02d3b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -123,6 +123,13 @@ JsonObject::~JsonObject() } } +bool JsonObject::operator==(const JsonObject& other) const +{ + bool isEqual = false; + (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0) ? isEqual = true : isEqual = false; + return isEqual; +} + bool JsonObject::IsNull() const { if (cjson_ == nullptr) { -- Gitee From b887aa6f95f99da5d32bf44517ee005b590a4ac1 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 6 May 2023 10:25:44 +0800 Subject: [PATCH 2/8] apply yellow zone Signed-off-by: Jeremyzz --- .../src/executor/document/document_check.cpp | 2 +- .../documentdb_json_common_test.cpp | 41 +++++++++++++++++-- 2 files changed, 39 insertions(+), 4 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..7d5815c7 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 @@ -240,7 +240,7 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) bool CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector> &path) { - if (updataObj.GetDeep() > JSON_DEEP_MAX) { + if (.GetDeep() > JSON_DEEP_MAX) { GLOGE("projectionObj's json deep is deeper than JSON_DEEP_MAX"); return -E_INVALID_ARGS; } 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 9c125f7c..3af6a9cf 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 @@ -592,12 +592,47 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest022, TestSize.Leve "k12" : "v12"})"; string document2 = R"({"_id" : "002", "key1" : {"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}}, "k12" : "v12"})"; const char *filter = R"({"key1" : {"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}}})"; + const char *filter2 = R"({"key1" : {"k22" : "v22", "key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}}})"; int errCode = E_OK; JsonObject srcObj1 = JsonObject::Parse(document, errCode); JsonObject srcObj2 = JsonObject::Parse(document2, errCode); EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj1, filterObj, errCode), false); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj, errCode), true); + JsonObject filterObj1 = JsonObject::Parse(filter, errCode); + JsonObject filterObj2 = JsonObject::Parse(filter2, errCode); + EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj1, filterObj1, errCode), false); + EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj1, errCode), true); + + EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj1, filterObj2, errCode), true); + EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj2, errCode), false); } + +HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest023, TestSize.Level0) +{ + string document = R"({"_id" : "001", "key1" : {"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}, "k22" : "v22"}, + "k12" : "v12", "key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}})"; + string document2 = R"({"_id" : "002", "key1" : {"key2" : {"key3" : {"key4" : 123}, "k32" : "v32"}, "k22" : "v22"}, "k12" : "v12"})"; + const char *filter = R"({"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}})"; + int errCode = E_OK; + JsonObject srcObj1 = JsonObject::Parse(document, errCode); + JsonObject srcObj2 = JsonObject::Parse(document2, errCode); + EXPECT_EQ(errCode, E_OK); + JsonObject filterObj1 = JsonObject::Parse(filter, errCode); + EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj1, filterObj1, errCode), true); + EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj1, errCode), false); +} + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest024, TestSize.Level0) +// { +// string document = R"({"_id" : "002", "attributes" : [{"warehouse" : "A", "qty" :5}, {"warehouse" : "C", "qty" : 5, "address" : ["aaaa", "bbbb", "cccc", {"tag" : "old"}]}]})"; +// string document2 = R"({"_id" : "002", "key1" : {"key2" : {"key3" : {"key4" : 123}, "k32" : "v32"}, "k22" : "v22"}, "k12" : "v12"})"; +// const char *filter = R"({"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}})"; +// int errCode = E_OK; +// JsonObject srcObj1 = JsonObject::Parse(document, errCode); +// JsonObject srcObj2 = JsonObject::Parse(document2, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj1 = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj1, filterObj1, errCode), true); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj1, errCode), false); +// } + } \ No newline at end of file -- Gitee From fd93a70d4852b7514fe0bd2035ca57f111c04b69 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 6 May 2023 16:09:01 +0800 Subject: [PATCH 3/8] fix ut 12 Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 18 ++++++++++-------- .../src/executor/document/document_check.cpp | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 9a0b814c..f5f70981 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -583,6 +583,11 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, { int errCode; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); + if (srcItem == item) { + isMatchFlag = true; + isAlreadyMatched = 1; + return false; + } JsonFieldPath granpaPath = itemPath; std::string lastFiledName = granpaPath.back(); granpaPath.pop_back(); @@ -590,18 +595,15 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, if (granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { - int isEqual = true; - int compareRet = (fatherItem.GetObjectItem(lastFiledName, errCode).Print() == item.Print()); - if (errCode == E_OK) { - isEqual = compareRet; - } - if (isEqual) { - GLOGI("Filter value is equal with src"); - isMatchFlag = isEqual; + if ((fatherItem.GetObjectItem(lastFiledName, errCode).Print() == item.Print())) { + isMatchFlag = true; isAlreadyMatched = 1; + break; } + isMatchFlag = false; fatherItem = fatherItem.GetNext(); } + return false; } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY && item.GetType() == JsonObject::Type::JSON_ARRAY && !isAlreadyMatched) { 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 7d5815c7..285036fc 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 @@ -240,7 +240,7 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) bool CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector> &path) { - if (.GetDeep() > JSON_DEEP_MAX) { + if (updataObj.GetDeep() > JSON_DEEP_MAX) { GLOGE("projectionObj's json deep is deeper than JSON_DEEP_MAX"); return -E_INVALID_ARGS; } -- Gitee From 16696b7a2e8bd836f7dae61df4068bf13ed7bc2d Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 6 May 2023 17:25:37 +0800 Subject: [PATCH 4/8] fix filterMatch BUG Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index f5f70981..f5f8a8ae 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -669,15 +669,6 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target return false; } } else { - if (isCollapse) { - GLOGE("Match failed, path not exist."); - isMatchFlag = false; - return false; - } - GLOGI("Not match anything"); - if (isAlreadyMatched == 0) { - isMatchFlag = false; - } std::vector ItemLeafValue = GetLeafValue(item); int isNULLFlag = true; for (auto ValueItem : ItemLeafValue) { @@ -687,8 +678,18 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target } else { GLOGI("filter leaf is null, Src leaf is dont exist"); isMatchFlag = true; + return false; } } + if (isCollapse) { + GLOGE("Match failed, path not exist."); + isMatchFlag = false; + return false; + } + GLOGI("Not match anything"); + if (isAlreadyMatched == 0) { + isMatchFlag = false; + } return false; // Source path not exist, if leaf value is null, isMatchFlag become true, else it will become false. } }); -- Gitee From 42c9d9acf4e9bff76f35f2b9568ec314392d4b50 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 14:42:05 +0800 Subject: [PATCH 5/8] fix code check opinion Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index d0e02d3b..8667b9da 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -125,9 +125,7 @@ JsonObject::~JsonObject() bool JsonObject::operator==(const JsonObject& other) const { - bool isEqual = false; - (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0) ? isEqual = true : isEqual = false; - return isEqual; + return (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0); } bool JsonObject::IsNull() const -- Gitee From 76d1a3c406268e36fcd0907fa2c325460424f790 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 15:41:05 +0800 Subject: [PATCH 6/8] fix Code check opinion Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 24 ++++------- .../src/oh_adapter/src/json_object.cpp | 2 +- .../unittest/api/documentdb_find_test.cpp | 40 ------------------- .../documentdb_json_common_test.cpp | 14 ------- 4 files changed, 9 insertions(+), 71 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index f5f8a8ae..c3a17437 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -595,7 +595,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, if (granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { - if ((fatherItem.GetObjectItem(lastFiledName, errCode).Print() == item.Print())) { + if ((fatherItem.GetObjectItem(lastFiledName, errCode) == item)) { isMatchFlag = true; isAlreadyMatched = 1; break; @@ -608,8 +608,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY && item.GetType() == JsonObject::Type::JSON_ARRAY && !isAlreadyMatched) { bool isEqual = (srcItem.Print() == item.Print()); - if (!isEqual) { - GLOGI("Filter value is No equal with src"); + if (!isEqual) { // Filter value is No equal with src isMatchFlag = isEqual; } isAlreadyMatched = isMatchFlag; @@ -618,22 +617,19 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, if (srcItem.GetType() == JsonObject::Type::JSON_LEAF && item.GetType() == JsonObject::Type::JSON_LEAF && !isAlreadyMatched) { bool isEqual = isValueEqual(srcItem.GetItemValue(), item.GetItemValue()); - if (!isEqual) { - GLOGI("Filter value is No equal with src"); + if (!isEqual) { // Filter value is No equal with src isMatchFlag = isEqual; } isAlreadyMatched = isMatchFlag; return false; // Both leaf node, no need iterate } else if (srcItem.GetType() != item.GetType()) { - if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { - GLOGI("srcItem Type is ARRAY, item Type is not ARRAY"); + if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { // srcItem Type is ARRAY, item Type is not ARRAY bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); if (!isEqual) { isMatchFlag = isEqual; } return true; } - GLOGI("valueType is different"); isMatchFlag = false; return false; // Different node types, overwrite directly, skip child node } @@ -672,22 +668,18 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target std::vector ItemLeafValue = GetLeafValue(item); int isNULLFlag = true; for (auto ValueItem : ItemLeafValue) { - if (ValueItem.GetValueType() != ValueObject::ValueType::VALUE_NULL) { - GLOGI("leaf value is not null"); + if (ValueItem.GetValueType() != ValueObject::ValueType::VALUE_NULL) { // leaf value is not null isNULLFlag = false; - } else { - GLOGI("filter leaf is null, Src leaf is dont exist"); + } else { // filter leaf is null, Src leaf is dont exist isMatchFlag = true; return false; } } - if (isCollapse) { - GLOGE("Match failed, path not exist."); + if (isCollapse) { // Match failed, path not exist isMatchFlag = false; return false; } - GLOGI("Not match anything"); - if (isAlreadyMatched == 0) { + if (isAlreadyMatched == 0) { //Not match anything isMatchFlag = false; } return false; // Source path not exist, if leaf value is null, isMatchFlag become true, else it will become false. diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index 8667b9da..bbc03f70 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -125,7 +125,7 @@ JsonObject::~JsonObject() bool JsonObject::operator==(const JsonObject& other) const { - return (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0); + return (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0); // If the two nodes exist with a different fieldName, then return 0. } bool JsonObject::IsNull() const 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..7b657b94 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,3 @@ 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); -} \ No newline at end of file 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 3af6a9cf..157770f8 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,18 +621,4 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest023, TestSize.Leve EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj1, errCode), false); } -// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest024, TestSize.Level0) -// { -// string document = R"({"_id" : "002", "attributes" : [{"warehouse" : "A", "qty" :5}, {"warehouse" : "C", "qty" : 5, "address" : ["aaaa", "bbbb", "cccc", {"tag" : "old"}]}]})"; -// string document2 = R"({"_id" : "002", "key1" : {"key2" : {"key3" : {"key4" : 123}, "k32" : "v32"}, "k22" : "v22"}, "k12" : "v12"})"; -// const char *filter = R"({"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}})"; -// int errCode = E_OK; -// JsonObject srcObj1 = JsonObject::Parse(document, errCode); -// JsonObject srcObj2 = JsonObject::Parse(document2, errCode); -// EXPECT_EQ(errCode, E_OK); -// JsonObject filterObj1 = JsonObject::Parse(filter, errCode); -// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj1, filterObj1, errCode), true); -// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj1, errCode), false); -// } - } \ No newline at end of file -- Gitee From 27d29e8946638ecb868305f6182abfe9fe5c9532 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 16:24:38 +0800 Subject: [PATCH 7/8] fix code CheckOpinion Signed-off-by: Jeremyzz --- .../gaussdb_rd_simple/src/oh_adapter/include/json_object.h | 2 +- .../gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp | 2 +- 2 files changed, 2 insertions(+), 2 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 bcd74b4d..f4ebbdd3 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,7 +61,7 @@ using JsonFieldPath = std::vector; class JsonObject { public: static JsonObject Parse(const std::string &jsonStr, int &errCode, bool caseSensitive = false); - bool operator==(const JsonObject& other) const; + bool operator==(const JsonObject& other) const; // If the two nodes exist with a different fieldName, then return 0. ~JsonObject(); std::string Print() const; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index bbc03f70..8667b9da 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -125,7 +125,7 @@ JsonObject::~JsonObject() bool JsonObject::operator==(const JsonObject& other) const { - return (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0); // If the two nodes exist with a different fieldName, then return 0. + return (cJSON_Compare(this->cjson_, other.cjson_, 0) != 0); } bool JsonObject::IsNull() const -- Gitee From 4458370552a0f37942a5c1a09188e71c9d881abf Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 20:57:00 +0800 Subject: [PATCH 8/8] fix filterMatch code check Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index c3a17437..3d4d2564 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -583,6 +583,10 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, { int errCode; JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); + if (errCode != E_OK) { + GLOGE("fine item falied"); + return errCode; + } if (srcItem == item) { isMatchFlag = true; isAlreadyMatched = 1; @@ -592,10 +596,18 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, std::string lastFiledName = granpaPath.back(); granpaPath.pop_back(); JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); + if (errCode != E_OK) { + GLOGE("fine item falied"); + return errCode; + } if (granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFiledName, errCode) == item)) { + if (errCode != E_OK) { + GLOGE("get item falied"); + return errCode; + } isMatchFlag = true; isAlreadyMatched = 1; break; @@ -653,6 +665,10 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target } else { JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); + if (errCode != E_OK) { + GLOGE("fine item falied"); + return errCode; + } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); } -- Gitee