From e1112d010ba92ed0ff4b1f5aed869c5cc4edc45a Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 8 May 2023 23:02:35 +0800 Subject: [PATCH 1/3] fix conflict Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 2 +- .../src/interface/src/document_store.cpp | 3 +-- .../oh_adapter/documentdb_json_common_test.cpp | 16 +--------------- 3 files changed, 3 insertions(+), 18 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 cfd77cea..5881cc65 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 @@ -673,7 +673,7 @@ bool JsonCommon::IsJsonNodeMatch(const JsonObject &src, const JsonObject &target JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode != E_OK) { GLOGE("fine item falied"); - return errCode; + return false; } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); 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 0cc6fb5c..d639dc21 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 @@ -336,7 +336,6 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri return errCode; } auto coll = Collection(collection, executor_); - if (document.length() >= JSON_LENS_MAX) { bool isCollectionExist = coll.IsCollectionExists(errCode); if (errCode != E_OK) { return errCode; @@ -344,7 +343,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri if (!isCollectionExist) { return -E_INVALID_ARGS; } - if (document.length() + 1 > JSON_LENS_MAX) { + if (document.length() >= JSON_LENS_MAX) { GLOGE("document's length is too long"); return -E_OVER_LIMIT; } 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 432d82b6..a450eca7 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; @@ -636,18 +636,4 @@ HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest023, TestSize.Leve } } -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest023, TestSize.Level0) -{ - std::string document = "{\"name\": 1, \"personInfo.school\": 1, \"personInfo.age\": 1}"; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - auto path = JsonCommon::ParsePath(srcObj, errCode); - for (auto singlePath : path) { - for (auto filedName : singlePath) { - GLOGE("filedName is =========>%s", filedName.c_str()); - } - GLOGE("///////////////////////////"); - } -} } \ No newline at end of file -- Gitee From c622c6c05ae003346cd2690938f902df94a9631a Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 9 May 2023 09:07:13 +0800 Subject: [PATCH 2/3] fix code check problem Signed-off-by: Jeremyzz --- .../src/common/src/json_common.cpp | 16 ----- .../src/executor/document/document_check.cpp | 27 +++++--- .../unittest/api/documentdb_data_test.cpp | 67 ++++++++++++++++++- 3 files changed, 83 insertions(+), 27 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 5881cc65..0045d798 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 @@ -589,10 +589,6 @@ 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; @@ -602,18 +598,10 @@ 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; @@ -671,10 +659,6 @@ 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 false; - } if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { return JsonEqualJudge(itemPath, src, item, isAlreadyMatched, isCollapse, isMatchFlag); } 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 be35db74..01c9d414 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 @@ -241,16 +241,6 @@ int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector filedSet; - int errCode = E_OK; - if (!updataObj.GetChild().IsNull()) { - auto updataObjChild = updataObj.GetChild(); - if (!JsonCommon::CheckProjectionField(updataObjChild, errCode)) { - GLOGE("updataObj json field format is illegal"); - return errCode; - } - } for (int i = 0; i < path.size(); i++) { if (path[i].empty()) { return -E_INVALID_JSON_FORMAT; @@ -266,11 +256,28 @@ int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector filedSet; + int errCode = E_OK; + if (!updataObj.GetChild().IsNull()) { + auto updataObjChild = updataObj.GetChild(); + if (!JsonCommon::CheckProjectionField(updataObjChild, errCode)) { + GLOGE("updataObj json field format is illegal"); + return errCode; + } + } for (auto singlePath : path) { if (singlePath.size() > JSON_DEEP_MAX) { return -E_INVALID_ARGS;; } } + if (!updataObj.GetChild().IsNull()) { + auto updataObjChild = updataObj.GetChild(); + if (!JsonCommon::CheckProjectionField(updataObjChild, errCode)) { + GLOGE("updataObj json field format is illegal"); + return errCode; + } + } bool isIdExist = true; CheckIdFormat(updataObj, isIdExist); if (isIdExist) { 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 5f53194a..5e256eb1 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 @@ -50,7 +50,7 @@ void DocumentDBDataTest::SetUp(void) { EXPECT_EQ(GRD_DBOpen(g_path.c_str(), nullptr, GRD_DB_OPEN_CREATE, &g_db), GRD_OK); EXPECT_NE(g_db, nullptr); - + GRD_DropCollection(g_db, g_coll, 0); EXPECT_EQ(GRD_CreateCollection(g_db, g_coll, "", 0), GRD_OK); } @@ -171,6 +171,13 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest008, TestSize.Level0) EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), updateDoc.c_str(), GRD_DOC_APPEND), 1); } +HWTEST_F(DocumentDBDataTest, UpsertDataTest009, TestSize.Level0) +{ + std::string filter = R""({"_id":"abcde"})""; + std::string document = R"({"field1": ")" + string(1024 * 1024 + 1, 'a') + "\"}"; + EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), document.c_str(), GRD_DOC_REPLACE), GRD_OVER_LIMIT); +} + HWTEST_F(DocumentDBDataTest, UpsertDataTest010, TestSize.Level0) { int result = GRD_UpsertDoc(g_db, g_coll, R"({"_id" : "abcde"})", R"({"a00001":1, "a00001":2})", 0); @@ -275,3 +282,61 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest007, TestSize.Level0) result = GRD_UpdateDoc(g_db, g_coll, "{\"field2\" : 2}", "{\"\":3}", 0); EXPECT_EQ(result, GRD_INVALID_FORMAT); } + +HWTEST_F(DocumentDBDataTest, UpdateDataTest008, TestSize.Level0) +{ + const char *updateStr = R""({"field2":{"c_field":{"cc_field":{"ccc_field":{"ccc_field":[1,false,1.234e2,["hello world!"]]}}}}})""; + int result = GRD_UpdateDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); + int result2 = GRD_UpsertDoc(g_db, g_coll, "{\"field\" : 2}", updateStr, 0); + EXPECT_EQ(result, GRD_INVALID_ARGS); + EXPECT_EQ(result2, GRD_INVALID_ARGS); +} + +HWTEST_F(DocumentDBDataTest, UpdateDataTest009, TestSize.Level0) +{ + 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, UpdateDataTest010, TestSize.Level0) +{ + std::string filter = R""({"_id":"1234"})""; + std::string updata = R""({"field1":1, "FIELD1":[1, true, 1.23456789, "hello world!", null]})""; + EXPECT_EQ(GRD_UpdateDoc(g_db, "grd_aa", filter.c_str(), updata.c_str(), 0), GRD_INVALID_FORMAT); + EXPECT_EQ(GRD_UpdateDoc(g_db, "gRd_aa", filter.c_str(), updata.c_str(), 0), GRD_INVALID_FORMAT); +} + +HWTEST_F(DocumentDBDataTest, UpdateDataTest011, TestSize.Level0) +{ + int result = GRD_OK; + const char *doc = R"({"_id":"007", "field1":{"c_field":{"cc_field":{"ccc_field":1}}}, "field2":2})"; + result = GRD_InsertDoc(g_db,g_coll, doc, 0); + cJSON *updata = cJSON_CreateObject(); + for (int i = 0; i <= 40000; i++) { + string temp = "f" + string(5 - std::to_string(i).size(), '0') + std::to_string(i); + cJSON_AddStringToObject(updata, temp.c_str(), "a"); + } + char *updateStr = cJSON_PrintUnformatted(updata); + result = GRD_UpdateDoc(g_db, g_coll, R""({"_id":"007"})"", updateStr, 0); + EXPECT_EQ(result, 1); + cJSON_Delete(updata); + cJSON_free; +} -- Gitee From 68f074ff53a43b8738a7c107ed939a4d2691fd39 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 9 May 2023 09:10:22 +0800 Subject: [PATCH 3/3] fix code check problem Signed-off-by: Jeremyzz --- .../src/executor/document/document_check.cpp | 9 --------- 1 file changed, 9 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 01c9d414..d81d0c54 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 @@ -256,8 +256,6 @@ int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector filedSet; int errCode = E_OK; if (!updataObj.GetChild().IsNull()) { auto updataObjChild = updataObj.GetChild(); @@ -271,13 +269,6 @@ int CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector