From 8136715e136a5e893443614209df13c1bf26aed2 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Thu, 11 May 2023 21:21:36 +0800 Subject: [PATCH 01/10] fix Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/common/src/json_common.cpp | 43 ++----------------- 1 file changed, 4 insertions(+), 39 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 61f29c65..d3466024 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 @@ -611,44 +611,9 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) { - if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY && item.GetType() == JsonObject::Type::JSON_ARRAY && - !isAlreadyMatched) { - bool isEqual = (srcItem == item); - if (!isEqual) { // Filter value is No equal with src - isMatchFlag = isEqual; - } - isAlreadyMatched = isMatchFlag; - return false; // Both leaf node, no need iterate - } - if (srcItem.GetType() == JsonObject::Type::JSON_LEAF && item.GetType() == JsonObject::Type::JSON_LEAF && - !isAlreadyMatched) { - bool isEqual = isValueEqual(srcItem.GetItemValue(), item.GetItemValue()); - 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) { // srcItem Type is ARRAY, item Type is not ARRAY - bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); - if (!isEqual) { - isMatchFlag = isEqual; - } - return true; - } - isMatchFlag = false; - return false; // Different node types, overwrite directly, skip child node - } - return true; // Both array or object -} - -bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - bool &isCollapse, int &isMatchFlag) -{ - int errCode; - int isAlreadyMatched = 0; - JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { + int errCode = E_OK; + JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); // This function has only two error codes, and the other error code is not an exception, but the specified node was not found + if (errCode == E_OK && srcItem == item) { isMatchFlag = true; isAlreadyMatched = 1; return false; @@ -657,7 +622,7 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject std::string lastFieldName = granpaPath.back(); granpaPath.pop_back(); JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { + if (errCode == E_OK && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK -- Gitee From 3d773138e8dfa315b0ce5c2f513ef1b2d8dd41e9 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 16 May 2023 15:31:05 +0800 Subject: [PATCH 02/10] fix code check opinion Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/src/json_common.cpp | 4 +++- 1 file changed, 3 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 d3466024..810bac63 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 @@ -612,7 +612,9 @@ bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject & bool &isCollapse, int &isMatchFlag) { int errCode = E_OK; - JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); // This function has only two error codes, and the other error code is not an exception, but the specified node was not found + // This function has only two error codes, and the other error + // code is not an exception, but the specified node was not found + JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); if (errCode == E_OK && srcItem == item) { isMatchFlag = true; isAlreadyMatched = 1; -- Gitee From bea5936ad32e36aeb6a9afa5de39db0631435756 Mon Sep 17 00:00:00 2001 From: lianhuix Date: Tue, 16 May 2023 14:37:34 +0800 Subject: [PATCH 03/10] Fix big method Signed-off-by: lianhuix --- .../src/interface/src/result_set.cpp | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index cadbf670..b8bb62b1 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -88,6 +88,53 @@ int ResultSet::GetNextWithField() return E_OK; } +int ResultSet::GetNextWithField() +{ + int errCode = E_OK; + if (isOnlyId_) { + JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); + std::string idKey = idValue.GetStringValue(); + if (idKey.empty()) { + return -E_NO_DATA; + } + Key key(idKey.begin(), idKey.end()); + Value document; + Collection coll = store_->GetCollection(collectionName_); + errCode = coll.GetDocument(key, document); + if (errCode == -E_NOT_FOUND) { + return -E_NO_DATA; + } + std::string jsonData(document.begin(), document.end()); + CutJsonBranch(jsonData); + std::vector> values; + values.emplace_back(std::make_pair(idKey, jsonData)); + matchDatas_ = values; + } else { + Collection coll = store_->GetCollection(collectionName_); + std::vector> values; + JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + errCode = coll.GetMatchedDocument(filterObj, values); + if (errCode == -E_NOT_FOUND) { + return -E_NO_DATA; + } + for (size_t i = 0; i < values.size(); i++) { + CutJsonBranch(values[i].second); + } + matchDatas_ = values; + } + return E_OK; +} + int ResultSet::GetNextInner(bool isNeedCheckTable) { int errCode = E_OK; -- Gitee From e518e3fabafb1f89ac5219256eaf4a06096ddde0 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 13 May 2023 17:44:04 +0800 Subject: [PATCH 04/10] fix document long fuction Signed-off-by: Jeremyzz --- .../include/grd_base/grd_type_export.h | 2 +- .../src/interface/src/document_store.cpp | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h b/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h index d116ea22..baa98144 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/include/grd_base/grd_type_export.h @@ -21,7 +21,7 @@ extern "C" { #endif // __cplusplus #ifndef _WIN32 -#define GRD_API __attribute__((visibility("default"))) +#define GRD_API __attribute__((visibility("default"), weak)) #endif typedef struct GRD_DB GRD_DB; 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 cb1947eb..d7567525 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 @@ -396,12 +396,41 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) { + int errCode = E_OK; + JsonObject documentObj = JsonObject::Parse(document, errCode, true); + if (errCode != E_OK) { + GLOGE("document Parsed failed"); + return errCode; + } + errCode = UpsertArgsCheck(collection, filter, document, documentObj, flags); + if (errCode != E_OK) { + return errCode; + } + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + GLOGE("filter is invalid"); + return errCode; + } + bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + errCode = UpsertDataIntoDB(collection, filterObj, documentObj, isOnlyId, isReplace); + return errCode; +} + +int InsertArgsCheck(const std::string &collection, const std::string &document, JsonObject &documentObj, uint32_t flags) +{ + int errCode = E_OK; if (flags != 0u) { GLOGE("InsertDocument flags is not zero"); return -E_INVALID_ARGS; } std::string lowerCaseCollName; - int errCode = E_OK; if (!CheckCommon::CheckCollectionName(collection, lowerCaseCollName, errCode)) { GLOGE("Check collection name invalid. %d", errCode); return errCode; -- Gitee From da18cf241ea8d7509cc95d4932a3e63c30aa4e61 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 11:49:11 +0800 Subject: [PATCH 05/10] Modify the jumbling function in the document Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/src/document_store.cpp | 6 +++++- .../gaussdb_rd/test/unittest/api/documentdb_data_test.cpp | 2 +- .../gaussdb_rd/test/unittest/api/documentdb_find_test.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) 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 d7567525..880d0a5c 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 @@ -418,8 +418,12 @@ int InsertArgsCheck(const std::string &collection, const std::string &document, GLOGE("filter is invalid"); return errCode; } + std::shared_ptr resultInfo = std::make_shared(); + resultInfo->filter_ = filter; + resultInfo->isOnlyId_ = isOnlyId; + resultInfo->collectionName_ = collection; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - errCode = UpsertDataIntoDB(collection, filterObj, documentObj, isOnlyId, isReplace); + errCode = UpsertDataIntoDB(resultInfo, filterObj, documentObj, isReplace); return errCode; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index d43519a7..e84c02c6 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -134,7 +134,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest006, TestSize.Level0) std::string filter = R""({"_id":"1234"})""; std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - for (auto flags : std::vector { 2, 4, 8, 64, 1024, UINT32_MAX }) { + for (auto flags : std::vector{ 2, 4, 8, 64, 1024, UINT32_MAX }) { EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), document.c_str(), flags), GRD_INVALID_ARGS); } } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 01320cbc..9f100792 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -1429,7 +1429,7 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest061, TestSize.Level1) EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document063, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document062, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document061, 0), GRD_OK); - const char *filter = "{\"a\":1}"; + const char *filter = "{\"a\": 1}"; GRD_ResultSet *resultSet = nullptr; const char *projection = R"({})"; Query query = { filter, projection }; -- Gitee From 44e4ac08a61bf4c9f61fbd2bb60126e940a90f5a Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 15:44:54 +0800 Subject: [PATCH 06/10] fix some bug Signed-off-by: Jeremyzz --- .../src/interface/src/document_store.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 880d0a5c..78d49e92 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 @@ -397,18 +397,23 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) { int errCode = E_OK; - JsonObject documentObj = JsonObject::Parse(document, errCode, true); + errCode = UpsertArgsCheck(collection, filter, document, flags); if (errCode != E_OK) { - GLOGE("document Parsed failed"); return errCode; } - errCode = UpsertArgsCheck(collection, filter, document, documentObj, flags); + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); if (errCode != E_OK) { + GLOGE("filter Parsed failed"); return errCode; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + JsonObject documentObj = JsonObject::Parse(document, errCode, true); if (errCode != E_OK) { - GLOGE("filter Parsed failed"); + GLOGE("document Parsed failed"); + return errCode; + } + errCode = UpsertDocumentFormatCheck(document, documentObj); + if (errCode != E_OK) { + GLOGE("document format is illegal"); return errCode; } bool isOnlyId = true; @@ -427,7 +432,7 @@ int InsertArgsCheck(const std::string &collection, const std::string &document, return errCode; } -int InsertArgsCheck(const std::string &collection, const std::string &document, JsonObject &documentObj, uint32_t flags) +int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) { int errCode = E_OK; if (flags != 0u) { -- Gitee From 445e4efd0ad1410d93b4966bb0eb6751b5d2e3b0 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 16:46:33 +0800 Subject: [PATCH 07/10] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/src/document_store.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 78d49e92..a979cb7f 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 @@ -423,12 +423,12 @@ int InsertArgsCheck(const std::string &collection, const std::string &document, GLOGE("filter is invalid"); return errCode; } - std::shared_ptr resultInfo = std::make_shared(); - resultInfo->filter_ = filter; - resultInfo->isOnlyId_ = isOnlyId; - resultInfo->collectionName_ = collection; + std::shared_ptr context = std::make_shared(); + context->filter_ = filter; + context->isOnlyId_ = isOnlyId; + context->collectionName_ = collection; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - errCode = UpsertDataIntoDB(resultInfo, filterObj, documentObj, isReplace); + errCode = UpsertDataIntoDB(context, filterObj, documentObj, isReplace); return errCode; } -- Gitee From e62a91b48e34b72170804de71bdc41c7fe676f42 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 17:38:12 +0800 Subject: [PATCH 08/10] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/test/unittest/api/documentdb_find_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp index 9f100792..01320cbc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_find_test.cpp @@ -1429,7 +1429,7 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest061, TestSize.Level1) EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document063, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document062, 0), GRD_OK); EXPECT_EQ(GRD_InsertDoc(g_db, COLLECTION_NAME, document061, 0), GRD_OK); - const char *filter = "{\"a\": 1}"; + const char *filter = "{\"a\":1}"; GRD_ResultSet *resultSet = nullptr; const char *projection = R"({})"; Query query = { filter, projection }; -- Gitee From 9a5d56dde817af5204c921b4f6dd40468287e2ab Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 17:46:28 +0800 Subject: [PATCH 09/10] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/test/unittest/api/documentdb_data_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp index e84c02c6..d43519a7 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/test/unittest/api/documentdb_data_test.cpp @@ -134,7 +134,7 @@ HWTEST_F(DocumentDBDataTest, UpsertDataTest006, TestSize.Level0) std::string filter = R""({"_id":"1234"})""; std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - for (auto flags : std::vector{ 2, 4, 8, 64, 1024, UINT32_MAX }) { + for (auto flags : std::vector { 2, 4, 8, 64, 1024, UINT32_MAX }) { EXPECT_EQ(GRD_UpsertDoc(g_db, g_coll, filter.c_str(), document.c_str(), flags), GRD_INVALID_ARGS); } } -- Gitee From 281d06f647a605d0f0a6cc7247e5ab760fef257e Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 16 May 2023 09:41:41 +0800 Subject: [PATCH 10/10] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/src/document_store.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 a979cb7f..2fb11657 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 @@ -424,22 +424,21 @@ int InsertArgsCheck(const std::string &collection, const std::string &document, return errCode; } std::shared_ptr context = std::make_shared(); - context->filter_ = filter; - context->isOnlyId_ = isOnlyId; - context->collectionName_ = collection; + context->filter = filter; + context->isOnlyId = isOnlyId; + context->collectionName = collection; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - errCode = UpsertDataIntoDB(context, filterObj, documentObj, isReplace); - return errCode; + return UpsertDataIntoDB(context, filterObj, documentObj, isReplace); } int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) { - int errCode = E_OK; if (flags != 0u) { GLOGE("InsertDocument flags is not zero"); return -E_INVALID_ARGS; } std::string lowerCaseCollName; + int errCode = E_OK; if (!CheckCommon::CheckCollectionName(collection, lowerCaseCollName, errCode)) { GLOGE("Check collection name invalid. %d", errCode); return errCode; -- Gitee