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 0d0a438ca2a3055ce6933859c54a6fe3da9406d2..c213f8588d04cbb460f24e504d5d40ac35a3e019 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 @@ -650,7 +650,22 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target } JsonFieldPath itemPath = SplitePath(path, isCollapse); if (src.IsFieldExistsPowerMode(itemPath)) { - return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + if (isCollapse) { + return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + } + else { + JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); + if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { + return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); + } + if (srcItem.Print() == item.Print()) { + isMatchFlag = true; + isAlreadyMatched = true; + return false; + } + isMatchFlag = false; + return false; + } } else { if (isCollapse) { GLOGE("Match failed, path not exist."); 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 e2c64b68511dea9606129b4c57082bc0605d0a34..9c125f7cb211a35653a459a5fcc4208b600f8738 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 @@ -25,7 +25,8 @@ using namespace DocumentDB; using namespace testing::ext; using namespace DocumentDBUnitTest; -class DocumentDBJsonCommonTest : public testing::Test { +namespace { + class DocumentDBJsonCommonTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -41,13 +42,6 @@ void DocumentDBJsonCommonTest::SetUp(void) {} void DocumentDBJsonCommonTest::TearDown(void) {} -/** - * @tc.name: OpenDBTest001 - * @tc.desc: Test open document db - * @tc.type: FUNC - * @tc.require: - * @tc.author: lianhuix - */ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) { std::string document = R""({"name":"Tmn","age":18,"addr":{"city":"shanghai","postal":200001}})""; @@ -590,4 +584,20 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest021, TestSize.Leve EXPECT_EQ(errCode, E_OK); JsonObject filterObj = JsonObject::Parse(filter, errCode); EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +} + +HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest022, TestSize.Level0) +{ + string document = R"({"_id" : "001", "key1" : {"key2" : {"key3" : {"key4" : 123, "k42" : "v42"}, "k32" : "v32"}, "k22" : "v22"}, + "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"}}})"; + 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); +} } \ No newline at end of file