From 8d69893ff5fdd5e65abb3d40b3abbeb514e336fb Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 13 May 2023 17:44:04 +0800 Subject: [PATCH 01/17] fix document long fuction Signed-off-by: Jeremyzz --- .../include/grd_base/grd_type_export.h | 2 +- .../src/common/include/document_type.h | 32 ++ .../gaussdb_rd/src/common/src/json_common.cpp | 9 +- .../gaussdb_rd/src/common/src/log_print.cpp | 1 - .../src/executor/base/grd_db_api.cpp | 6 +- .../src/executor/document/check_common.cpp | 2 +- .../executor/document/grd_document_api.cpp | 14 +- .../executor/document/grd_resultset_api.cpp | 8 +- .../src/interface/include/collection.h | 2 +- .../src/interface/include/document_store.h | 15 +- .../src/interface/include/result_set.h | 6 +- .../src/interface/include/result_set_common.h | 3 +- .../src/interface/src/document_store.cpp | 485 ++++++++++++------ .../src/interface/src/projection_tree.cpp | 2 - .../src/interface/src/result_set.cpp | 23 +- .../src/interface/src/result_set_common.cpp | 5 +- .../src/oh_adapter/src/json_object.cpp | 17 +- 17 files changed, 404 insertions(+), 228 deletions(-) create mode 100644 services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h 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/common/include/document_type.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h new file mode 100644 index 00000000..c818fb72 --- /dev/null +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef DOCUMENT_TYPE_H +#define DOCUMENT_TYPE_H + +#include + +namespace DocumentDB { +struct QueryContext +{ + std::string collectionName; + std::string filter; + std::vector> path; + bool ifShowId = false; + bool viewType = false; + bool isOnlyId = false; +}; +} // namespace DocumentDB +#endif // DOCUMENT_TYPE_H \ No newline at end of file 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 b84a888e..1b010261 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 @@ -102,7 +102,7 @@ bool JsonCommon::CheckNode(JsonObject &node) return false; } for (size_t i = 0; i < fieldName.size(); i++) { - if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || '_' == fieldName[i])) { + if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || fieldName[i] == '_')) { return false; } if (i == 0 && (isdigit(fieldName[i]))) { @@ -144,8 +144,8 @@ bool JsonCommon::CheckProjectionNode(JsonObject &node, bool isFirstLevel, int &e return false; } for (size_t i = 0; i < fieldName.size(); i++) { - if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || ('_' == fieldName[i]) || - (isFirstLevel && '.' == fieldName[i]))) { + if (!((isalpha(fieldName[i])) || (isdigit(fieldName[i])) || (fieldName[i] == '_') || + (isFirstLevel && fieldName[i] == '.'))) { errCode = -E_INVALID_ARGS; return false; } @@ -223,9 +223,6 @@ std::vector> JsonCommon::ParsePath(const JsonObject &ro { std::vector> resultPath; JsonObject projectionJson = root.GetChild(); - if (projectionJson.IsNull()) { - GLOGE("projectionJson is null"); - } std::vector singlePath; errCode = ParseNode(projectionJson, singlePath, resultPath, true); return resultPath; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp index 501ce977..398dbc33 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/log_print.cpp @@ -20,7 +20,6 @@ namespace DocumentDB { namespace { - void PrintLog(LogPrint::Level level, const char *tag, const std::string &msg) { if (msg.empty()) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp index 4da4291e..f61b9ffc 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/base/grd_db_api.cpp @@ -23,7 +23,7 @@ using namespace DocumentDB; -int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db) +GRD_API int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GRD_DB **db) { if (db == nullptr) { return GRD_INVALID_ARGS; @@ -47,7 +47,7 @@ int32_t GRD_DBOpen(const char *dbPath, const char *configStr, uint32_t flags, GR return TransferDocErr(ret); } -int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) +GRD_API int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -63,7 +63,7 @@ int32_t GRD_DBClose(GRD_DB *db, uint32_t flags) return GRD_OK; } -int32_t GRD_Flush(GRD_DB *db, uint32_t flags) +GRD_API int32_t GRD_Flush(GRD_DB *db, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 70792700..01513f9f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -41,7 +41,7 @@ bool CheckCollectionNamePrefix(const std::string &name, const std::string &prefi void ReplaceAll(std::string &inout, const std::string &what, const std::string &with) { - std::string::size_type pos{}; + std::string::size_type pos {}; while ((pos = inout.find(what.data(), pos, what.length())) != std::string::npos) { inout.replace(pos, what.length(), with.data(), with.length()); pos += with.length(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp index 668718c8..4515211c 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_document_api.cpp @@ -21,7 +21,7 @@ #include "log_print.h" using namespace DocumentDB; -int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) +GRD_API int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char *optionStr, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -33,7 +33,7 @@ int32_t GRD_CreateCollection(GRD_DB *db, const char *collectionName, const char return TransferDocErr(ret); } -int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags) +GRD_API int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flags) { if (db == nullptr || db->store_ == nullptr) { return GRD_INVALID_ARGS; @@ -44,7 +44,7 @@ int32_t GRD_DropCollection(GRD_DB *db, const char *collectionName, uint32_t flag return TransferDocErr(ret); } -int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, uint32_t flags) +GRD_API int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || filter == nullptr || update == nullptr) { return GRD_INVALID_ARGS; @@ -56,7 +56,7 @@ int32_t GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter return TransferDocErr(ret); } -int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, uint32_t flags) +GRD_API int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || filter == nullptr || document == nullptr) { @@ -69,7 +69,7 @@ int32_t GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter return TransferDocErr(ret); } -int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags) +GRD_API int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *document, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || document == nullptr) { return GRD_INVALID_ARGS; @@ -78,7 +78,7 @@ int32_t GRD_InsertDoc(GRD_DB *db, const char *collectionName, const char *docume return TransferDocErr(ret); } -int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags) +GRD_API int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter, uint32_t flags) { if (db == nullptr || db->store_ == nullptr || filter == nullptr || collectionName == nullptr) { return GRD_INVALID_ARGS; @@ -95,7 +95,7 @@ int32_t GRD_DeleteDoc(GRD_DB *db, const char *collectionName, const char *filter } } -int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, GRD_ResultSet **resultSet) +GRD_API int32_t GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, uint32_t flags, GRD_ResultSet **resultSet) { if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || resultSet == nullptr || query.filter == nullptr || query.projection == nullptr) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp index 296dbe58..d529552f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/grd_resultset_api.cpp @@ -23,7 +23,7 @@ using namespace DocumentDB; -int32_t GRD_Next(GRD_ResultSet *resultSet) +GRD_API int32_t GRD_Next(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { GLOGE("resultSet is nullptr"); @@ -33,7 +33,7 @@ int32_t GRD_Next(GRD_ResultSet *resultSet) return TransferDocErr(ret); } -int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) +GRD_API int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) { if (resultSet == nullptr || value == nullptr) { GLOGE("resultSet is nullptr,cant get value from it"); @@ -49,7 +49,7 @@ int32_t GRD_GetValue(GRD_ResultSet *resultSet, char **value) return TransferDocErr(ret); } -int32_t GRD_FreeValue(char *value) +GRD_API int32_t GRD_FreeValue(char *value) { if (value == nullptr) { return GRD_INVALID_ARGS; @@ -58,7 +58,7 @@ int32_t GRD_FreeValue(char *value) return GRD_OK; } -int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet) +GRD_API int32_t GRD_FreeResultSet(GRD_ResultSet *resultSet) { if (resultSet == nullptr) { return GRD_INVALID_ARGS; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h index 16c551c3..c04f5c7b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/collection.h @@ -26,7 +26,7 @@ class Collection { public: Collection(const std::string &name, KvStoreExecutor *executor); Collection(const Collection &other); - Collection(){}; + Collection() {}; ~Collection(); int PutDocument(const Key &key, const Value &document); 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 5c91d1d8..4f1d5e02 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 @@ -21,6 +21,7 @@ #include #include "collection.h" +#include "document_type.h" #include "kv_store_executor.h" struct GRD_ResultSet; @@ -64,8 +65,20 @@ public: bool IsCollectionExists(const std::string &collectionName, int &errCode); std::mutex dbMutex_; + private: - int GetViewType(JsonObject &jsonObj, bool &viewType); + int UpdateDataIntoDB(const std::string &collection, JsonObject &filterObj, const std::string &update, + bool &isOnlyId, bool &isReplace); + int GetDocKey(JsonObject &filterObj, const std::string &collection, const std::string &filter, bool &isOnlyId, + std::string &docId); + int UpsertDataIntoDB(const std::string &collection, JsonObject &filterObj, JsonObject &documentObj, bool &isOnlyId, + bool &isReplace); + int InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj); + int DeleteDataFromDB(const std::string &collection, const std::string &filter, JsonObject &filterObj, + bool &isOnlyId); + int InitFindResultSet(const std::string &collection, GRD_ResultSet *grdResultSet, QueryContext &resultInfo); + int CheckUpsertConflict(bool &isIdExist, std::string collection, JsonObject &filterObj, std::string &docId, + Collection &coll); KvStoreExecutor *executor_ = nullptr; std::map collections_; std::function closeNotifier_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index f72a93c2..3906ba3d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -19,8 +19,8 @@ #include #include -#include "doc_errno.h" #include "check_common.h" +#include "doc_errno.h" #include "document_store.h" #include "grd_base/grd_type_export.h" #include "json_object.h" @@ -31,9 +31,7 @@ class ResultSet { public: ResultSet(); ~ResultSet(); - - int Init(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId); + int Init(QueryContext &QueryContext, DocumentStore *store); int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h index fa2c17c7..fa407cfa 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h @@ -25,8 +25,7 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, ResultSet &resultSet, bool &isOnlyId); +int InitResultSet(QueryContext &resultInfo, DocumentStore *store, ResultSet &resultSet); int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, ResultSet &resultSet); } // namespace DocumentDB 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 60f50c13..37af86c4 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 @@ -15,12 +15,13 @@ #include "document_store.h" +#include "check_common.h" #include "collection_option.h" #include "doc_errno.h" -#include "check_common.h" #include "grd_base/grd_type_export.h" #include "grd_resultset_inner.h" #include "log_print.h" +#include "result_set.h" #include "result_set_common.h" namespace DocumentDB { @@ -127,8 +128,44 @@ END: return errCode; } -int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, - uint32_t flags) +int TranFilter(JsonObject &filterObj, std::vector> &filterAllPath, bool &isOnlyId) +{ + int errCode = E_OK; + filterAllPath = JsonCommon::ParsePath(filterObj, errCode); + if (errCode != E_OK) { + GLOGE("filter ParsePath failed"); + return errCode; + } + errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); + if (errCode != E_OK) { + return errCode; + } + return errCode; +} + +int DocumentStore::GetDocKey(JsonObject &filterObj, const std::string &collection, const std::string &filter, + bool &isOnlyId, std::string &docId) +{ + int errCode = E_OK; + if (isOnlyId) { + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); + docId = idValue.GetStringValue(); + } else { + ResultSet resultSet; + InitResultSet(this, collection, filter, resultSet); + errCode = resultSet.GetNext(); + if (errCode == -E_NO_DATA) { + return 0; // The amount of text updated + } else if (errCode != E_OK) { + return errCode; + } + resultSet.GetKey(docId); + } + return errCode; +} + +int UpdateArgsCheck(const std::string &collection, const std::string &filter, const std::string &update, uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -162,23 +199,13 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - GLOGE("filter ParsePath failed"); - return errCode; - } - bool isOnlyId = true; - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } - bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + return errCode; +} + +int DocumentStore::UpdateDataIntoDB(const std::string &collection, JsonObject &filterObj, const std::string &update, + bool &isOnlyId, bool &isReplace) +{ + int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; @@ -196,6 +223,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri docId = idValue.GetStringValue(); } else { ResultSet resultSet; + std::string filter = filterObj.Print(); InitResultSet(this, collection, filter, resultSet); // no start transaction inner errCode = resultSet.GetNext(false, true); @@ -223,8 +251,32 @@ END: return (errCode == E_OK) ? count : errCode; } -int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, - const std::string &document, uint32_t flags) +int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, + uint32_t flags) +{ + int errCode = E_OK; + errCode = UpdateArgsCheck(collection, filter, update, 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) { + return errCode; + } + bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + errCode = UpdateDataIntoDB(collection, filterObj, update, isOnlyId, isReplace); + return errCode; +} + +int UpsertArgsCheck(const std::string &collection, const std::string &filter, const std::string &document, + JsonObject &documentObj, uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -236,11 +288,6 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri GLOGE("args length is too long"); return -E_OVER_LIMIT; } - JsonObject documentObj = JsonObject::Parse(document, errCode, true); - if (errCode != E_OK) { - GLOGE("document Parsed failed"); - return errCode; - } std::vector> allPath; if (document != "{}") { allPath = JsonCommon::ParsePath(documentObj, errCode); @@ -257,22 +304,37 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; + return errCode; +} + +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::string collection, JsonObject &filterObj, + std::string &docId, Collection &coll) +{ + int errCode = E_OK; + if (!isIdExist) { + errCode = -E_INVALID_ARGS; } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - return errCode; + ResultSet resultSet; + std::string filter = filterObj.Print(); + InitResultSet(this, collection, filter, resultSet); + errCode = resultSet.GetNext(false, true); + bool isfilterMatch = false; + if (errCode == E_OK) { + isfilterMatch = true; } - bool isOnlyId = true; - bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; + Value ValueDocument; + Key key(docId.begin(), docId.end()); + errCode = coll.GetDocument(key, ValueDocument); + if (errCode == E_OK && !(isfilterMatch)) { + GLOGE("id exist but filter does not match, data conflict"); + errCode = -E_DATA_CONFLICT; } +} + +int DocumentStore::UpsertDataIntoDB(const std::string &collection, JsonObject &filterObj, JsonObject &documentObj, + bool &isOnlyId, bool &isReplace) +{ + int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; @@ -285,37 +347,16 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri int count = 0; std::string targetDocument; std::string docId; - if (isOnlyId) { - auto filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - docId = idValue.GetStringValue(); - JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); - documentObj.InsertItemObject(0, idObj); - targetDocument = documentObj.Print(); - } else { - bool isIdExist; - auto filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); if (!isIdExist) { - errCode = -E_INVALID_ARGS; - goto END; - } - ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); - errCode = resultSet.GetNext(false, true); - bool isfilterMatch = false; - if (errCode == E_OK) { - isfilterMatch = true; - } - docId = idValue.GetStringValue(); - JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); - documentObj.InsertItemObject(0, idObj); - targetDocument = documentObj.Print(); - Value ValueDocument; - Key key(docId.begin(), docId.end()); - errCode = coll.GetDocument(key, ValueDocument); - if (errCode == E_OK && !(isfilterMatch)) { - GLOGE("id exist but filter does not match, data conflict"); - errCode = -E_DATA_CONFLICT; + bool isIdExist; + auto filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID, isIdExist); + docId = idValue.GetStringValue(); + JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); + documentObj.InsertItemObject(0, idObj); + targetDocument = documentObj.Print(); + if (!isOnlyId) { + errCode = CheckUpsertConflict(isIdExist, collection, filterObj, docId, coll); + if (errCode != E_OK) { goto END; } } @@ -334,14 +375,44 @@ END: return (errCode == E_OK) ? count : errCode; } -int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) +int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, + 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; @@ -350,26 +421,42 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri GLOGE("document's length is too long"); return -E_OVER_LIMIT; } - JsonObject documentObj = JsonObject::Parse(document, errCode, true); - if (errCode != E_OK) { - GLOGE("Document Parsed failed"); - return errCode; - } errCode = CheckCommon::CheckDocument(documentObj); if (errCode != E_OK) { return errCode; } + return errCode; +} + +int DocumentStore::InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj) +{ + std::lock_guard lock(dbMutex_); JsonObject documentObjChild = documentObj.GetChild(); ValueObject idValue = JsonCommon::GetValueInSameLevel(documentObjChild, KEY_ID); std::string id = idValue.GetStringValue(); Key key(id.begin(), id.end()); Value value(document.begin(), document.end()); - std::lock_guard lock(dbMutex_); Collection coll = Collection(collection, executor_); return coll.InsertDocument(key, value); } -int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) +int DocumentStore::InsertDocument(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 = InsertArgsCheck(collection, document, documentObj, flags); + if (errCode != E_OK) { + return errCode; + } + errCode = InsertDataIntoDB(collection, document, documentObj); + return errCode; +} + +int DeleteArgsCheck(const std::string &collection, const std::string &filter, uint32_t flags) { if (flags != 0u) { GLOGE("DeleteDocument flags is not zero"); @@ -389,21 +476,13 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri GLOGE("filter's length is too long"); return -E_OVER_LIMIT; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - return errCode; - } - bool isOnlyId = true; - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } + return errCode; +} + +int DocumentStore::DeleteDataFromDB(const std::string &collection, const std::string &filter, JsonObject &filterObj, + bool &isOnlyId) +{ + int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; @@ -432,20 +511,101 @@ END: Key key(id.begin(), id.end()); errCode = coll.DeleteDocument(key); } - if (errCode == E_OK || errCode == E_NOT_FOUND) { + if (errCode == E_OK || errCode == E_NOT_FOUND) { executor_->Commit(); } else { executor_->Rollback(); } return errCode; } +int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) +{ + int errCode = E_OK; + errCode = DeleteArgsCheck(collection, filter, flags); + if (errCode != E_OK) { + return errCode; + } + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + return errCode; + } + errCode = DeleteDataFromDB(collection, filter, filterObj, isOnlyId); + return errCode; +} Collection DocumentStore::GetCollection(std::string &collectionName) { return Collection(collectionName, executor_); } -int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, - const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) +int JudgeViewType(size_t &index, ValueObject &leafItem, bool &viewType) +{ + switch (leafItem.GetValueType()) { + case ValueObject::ValueType::VALUE_BOOL: + if (leafItem.GetBoolValue()) { + if (index != 0 && !viewType) { + return -E_INVALID_ARGS; + } + viewType = true; + } else { + if (index != 0 && viewType) { + return E_INVALID_ARGS; + } + viewType = false; + } + break; + case ValueObject::ValueType::VALUE_STRING: + if (leafItem.GetStringValue() == "") { + if (index != 0 && !viewType) { + return -E_INVALID_ARGS; + } + viewType = true; + } else { + return -E_INVALID_ARGS; + } + break; + case ValueObject::ValueType::VALUE_NUMBER: + if (leafItem.GetIntValue() == 0) { + if (index != 0 && viewType) { + return -E_INVALID_ARGS; + } + viewType = false; + } else { + if (index != 0 && !viewType) { + return E_INVALID_ARGS; + } + viewType = true; + } + break; + default: + return E_INVALID_ARGS; + } + return E_OK; +} + +int GetViewType(JsonObject &jsonObj, bool &viewType) +{ + std::vector leafValue = JsonCommon::GetLeafValue(jsonObj); + if (leafValue.size() == 0) { + return E_INVALID_ARGS; + } + int ret = E_OK; + for (size_t i = 0; i < leafValue.size(); i++) { + ret = JudgeViewType(i, leafValue[i], viewType); + if (ret != E_OK) { + return ret; + } + } + return E_OK; +} + +int FindArgsCheck(const std::string &collection, const std::string &filter, const std::string &projection, + uint32_t flags) { if (flags != 0u && flags != GRD_DOC_ID_DISPLAY) { GLOGE("FindDocument flags is illegal"); @@ -461,32 +621,23 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("args length is too long"); return -E_OVER_LIMIT; } - JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); - if (errCode != E_OK) { - GLOGE("filter Parsed failed"); - return errCode; - } - std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj, errCode); - if (errCode != E_OK) { - return errCode; - } - bool isOnlyId = true; - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } if (projection.length() >= JSON_LENS_MAX) { GLOGE("projection's length is too long"); return -E_OVER_LIMIT; } + return errCode; +} + +int FindProjectionInit(const std::string &projection, QueryContext &resultInfo) +{ + int errCode = E_OK; + std::vector> allPath; JsonObject projectionObj = JsonObject::Parse(projection, errCode, true); if (errCode != E_OK) { GLOGE("projection Parsed failed"); return errCode; } bool viewType = false; - std::vector> allPath; if (projection != "{}") { allPath = JsonCommon::ParsePath(projectionObj, errCode); if (errCode != E_OK) { @@ -502,11 +653,16 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return errCode; } } - bool ifShowId = false; - if (flags == GRD_DOC_ID_DISPLAY) { - ifShowId = true; - } + resultInfo.path = allPath; + resultInfo.viewType = viewType; + return errCode; +} + +int DocumentStore::InitFindResultSet(const std::string &collection, GRD_ResultSet *grdResultSet, + QueryContext &resultInfo) +{ std::lock_guard lock(dbMutex_); + int errCode = E_OK; Collection coll = Collection(collection, executor_); if (IsCollectionOpening(collection)) { return -E_RESOURCE_BUSY; @@ -525,12 +681,12 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string if (errCode != E_OK) { goto END; } - errCode = InitResultSet(this, collection, filter, allPath, ifShowId, viewType, grdResultSet->resultSet_, isOnlyId); + errCode = InitResultSet(resultInfo, this, grdResultSet->resultSet_); if (errCode == E_OK) { collections_[collection] = nullptr; } END: - if (errCode == E_OK) { + if (errCode == E_OK) { executor_->Commit(); } else { executor_->Rollback(); @@ -538,6 +694,44 @@ END: return errCode; } +int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, + const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) +{ + QueryContext resultInfo; + int errCode = E_OK; + errCode = FindArgsCheck(collection, filter, projection, flags); + if (errCode != E_OK) { + GLOGE("delete arg is illegal"); + return errCode; + } + resultInfo.collectionName = collection; + resultInfo.filter = filter; + JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + errCode = FindProjectionInit(projection, resultInfo); + if (errCode != E_OK) { + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + GLOGE("filter is invalid"); + return errCode; + } + resultInfo.isOnlyId = isOnlyId; + bool ifShowId = false; + if (flags == GRD_DOC_ID_DISPLAY) { + ifShowId = true; + } + resultInfo.ifShowId = ifShowId; + errCode = InitFindResultSet(collection, grdResultSet, resultInfo); + return errCode; +} + bool DocumentStore::IsCollectionOpening(const std::string collection) { if (collections_.find(collection) != collections_.end()) { @@ -558,57 +752,6 @@ int DocumentStore::EraseCollection(const std::string collectionName) return E_INVALID_ARGS; } -int DocumentStore::GetViewType(JsonObject &jsonObj, bool &viewType) -{ - std::vector leafValue = JsonCommon::GetLeafValue(jsonObj); - if (leafValue.size() == 0) { - return E_INVALID_ARGS; - } - for (size_t i = 0; i < leafValue.size(); i++) { - switch (leafValue[i].GetValueType()) { - case ValueObject::ValueType::VALUE_BOOL: - if (leafValue[i].GetBoolValue()) { - if (i != 0 && !viewType) { - return -E_INVALID_ARGS; - } - viewType = true; - } else { - if (i != 0 && viewType) { - return E_INVALID_ARGS; - } - viewType = false; - } - break; - case ValueObject::ValueType::VALUE_STRING: - if (leafValue[i].GetStringValue() == "") { - if (i != 0 && !viewType) { - return -E_INVALID_ARGS; - } - viewType = true; - } else { - return -E_INVALID_ARGS; - } - break; - case ValueObject::ValueType::VALUE_NUMBER: - if (leafValue[i].GetIntValue() == 0) { - if (i != 0 && viewType) { - return -E_INVALID_ARGS; - } - viewType = false; - } else { - if (i != 0 && !viewType) { - return E_INVALID_ARGS; - } - viewType = true; - } - break; - default: - return E_INVALID_ARGS; - } - } - return E_OK; -} - void DocumentStore::OnClose(const std::function ¬ifier) { closeNotifier_ = notifier; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp index bd41e033..265ca61d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/projection_tree.cpp @@ -14,8 +14,6 @@ */ #include "projection_tree.h" -#include - namespace DocumentDB { const int JSON_DEEP_MAX = 4; 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 3ea01a2b..0da40e02 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 @@ -13,10 +13,10 @@ * limitations under the License. */ #include "result_set.h" -#include "securec.h" #include "db_constant.h" #include "log_print.h" +#include "securec.h" namespace DocumentDB { constexpr const char *KEY_ID = "_id"; @@ -30,20 +30,19 @@ int ResultSet::EraseCollection() } return E_OK; } -int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, bool &isOnlyId) +int ResultSet::Init(QueryContext &resultSetInfo, DocumentStore *store) { - isOnlyId_ = isOnlyId; + isOnlyId_ = resultSetInfo.isOnlyId; store_ = store; - collectionName_ = collectionName; - filter_ = filter; - projectionPath_ = path; - if (projectionTree_.ParseTree(path) == -E_INVALID_ARGS) { + collectionName_ = resultSetInfo.collectionName; + filter_ = resultSetInfo.filter; + projectionPath_ = resultSetInfo.path; + if (projectionTree_.ParseTree(projectionPath_) == -E_INVALID_ARGS) { GLOGE("Parse ProjectionTree failed"); return -E_INVALID_ARGS; } - ifShowId_ = ifShowId; - viewType_ = viewType; + ifShowId_ = resultSetInfo.ifShowId; + viewType_ = resultSetInfo.viewType; return E_OK; } @@ -139,7 +138,7 @@ int ResultSet::GetNext(bool isNeedTransaction, bool isNeedCheckTable) { int errCode = E_OK; if (!isNeedTransaction) { - return GetNextInner(isNeedCheckTable); + return GetNextInner(isNeedCheckTable); } std::lock_guard lock(store_->dbMutex_); errCode = store_->StartTransaction(); @@ -147,7 +146,7 @@ int ResultSet::GetNext(bool isNeedTransaction, bool isNeedCheckTable) return errCode; } errCode = GetNextInner(isNeedCheckTable); - if (errCode == E_OK || errCode == -E_NO_DATA) { + if (errCode == E_OK || errCode == -E_NO_DATA) { store_->Commit(); } else { store_->Rollback(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index c34c4a80..f2d1a4f8 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -23,10 +23,9 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - std::vector> &path, bool ifShowId, bool viewType, ResultSet &resultSet, bool &isOnlyId) +int InitResultSet(QueryContext &resultInfo, DocumentStore *store, ResultSet &resultSet) { - return resultSet.Init(store, collectionName, filter, path, ifShowId, viewType, isOnlyId); + return resultSet.Init(resultInfo, store); } int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, 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 3609c481..55a82f7c 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 @@ -107,10 +107,7 @@ bool JsonObject::operator==(const JsonObject &other) const bool JsonObject::IsNull() const { - if (cjson_ == nullptr) { - return true; - } - return false; + return (cjson_ == nullptr); } JsonObject::Type JsonObject::GetType() const @@ -122,6 +119,7 @@ JsonObject::Type JsonObject::GetType() const } return JsonObject::Type::JSON_LEAF; } + int JsonObject::GetDeep() { if (cjson_ == nullptr) { @@ -134,6 +132,7 @@ int JsonObject::GetDeep() jsonDeep_ = GetDeep(cjson_); return jsonDeep_; } + int JsonObject::GetDeep(cJSON *cjson) { if (cjson->child == nullptr) { @@ -156,7 +155,7 @@ int JsonObject::CheckNumber(cJSON *item, int &errCode) if (item != NULL && cJSON_IsNumber(item)) { double value = cJSON_GetNumberValue(item); if (value > __DBL_MAX__ || value < -__DBL_MAX__) { - errCode = E_INVALID_ARGS; + errCode = -E_INVALID_ARGS; } } if (item->child != nullptr) { @@ -185,7 +184,7 @@ int JsonObject::Init(const std::string &str, bool isFilter) int ret = 0; CheckNumber(cjson_, ret); - if (ret == E_INVALID_ARGS) { + if (ret == -E_INVALID_ARGS) { GLOGE("Int value is larger than double"); return -E_INVALID_ARGS; } @@ -261,14 +260,14 @@ std::string JsonObject::Print() const return ""; } char *ret = cJSON_PrintUnformatted(cjson_); - std::string str = ret; + std::string str = (ret == nullptr ? "" : ret); cJSON_free(ret); return str; } JsonObject JsonObject::GetObjectItem(const std::string &field, int &errCode) { - if (cjson_ == nullptr || (cjson_->type & cJSON_Object) != cJSON_Object) { + if (cjson_ == nullptr || cjson_->type != cJSON_Object) { errCode = -E_INVALID_ARGS; return JsonObject(); } @@ -288,7 +287,7 @@ JsonObject JsonObject::GetObjectItem(const std::string &field, int &errCode) JsonObject JsonObject::GetArrayItem(int index, int &errCode) { - if (cjson_ == nullptr || (cjson_->type & cJSON_Array) != cJSON_Array) { + if (cjson_ == nullptr || cjson_->type != cJSON_Array) { errCode = -E_INVALID_ARGS; return JsonObject(); } -- Gitee From 1e868ee1014d819d14a1b3ac885d3a0d103ce689 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 13 May 2023 17:58:08 +0800 Subject: [PATCH 02/17] fix code check opinion Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/common/include/document_type.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h index c818fb72..676fd32d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h @@ -19,8 +19,7 @@ #include namespace DocumentDB { -struct QueryContext -{ +struct QueryContext { std::string collectionName; std::string filter; std::vector> path; -- Gitee From 48f3d8d5ea3f7b92e7ac52f3628e0dd9ba1e7a5f Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Sat, 13 May 2023 18:24:32 +0800 Subject: [PATCH 03/17] fix code check opnion Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/include/document_store.h | 6 +++--- .../gaussdb_rd/src/interface/src/document_store.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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 4f1d5e02..7a0ee3a7 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,9 +50,9 @@ public: Collection GetCollection(std::string &collectionName); - bool IsCollectionOpening(const std::string collection); + bool IsCollectionOpening(const std::string &collection); - int EraseCollection(const std::string collectionName); + int EraseCollection(const std::string &collectionName); void OnClose(const std::function ¬ifier); @@ -77,7 +77,7 @@ private: int DeleteDataFromDB(const std::string &collection, const std::string &filter, JsonObject &filterObj, bool &isOnlyId); int InitFindResultSet(const std::string &collection, GRD_ResultSet *grdResultSet, QueryContext &resultInfo); - int CheckUpsertConflict(bool &isIdExist, std::string collection, JsonObject &filterObj, std::string &docId, + int CheckUpsertConflict(bool &isIdExist, const std::string &collection, JsonObject &filterObj, std::string &docId, Collection &coll); KvStoreExecutor *executor_ = nullptr; std::map collections_; 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 37af86c4..f43bb4d1 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 @@ -307,7 +307,7 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::string collection, JsonObject &filterObj, +int DocumentStore::CheckUpsertConflict(bool &isIdExist, const std::string &collection, JsonObject &filterObj, std::string &docId, Collection &coll) { int errCode = E_OK; @@ -732,7 +732,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return errCode; } -bool DocumentStore::IsCollectionOpening(const std::string collection) +bool DocumentStore::IsCollectionOpening(const std::string &collection) { if (collections_.find(collection) != collections_.end()) { GLOGE("DB is resource busy"); @@ -741,7 +741,7 @@ bool DocumentStore::IsCollectionOpening(const std::string collection) return false; } -int DocumentStore::EraseCollection(const std::string collectionName) +int DocumentStore::EraseCollection(const std::string &collectionName) { std::lock_guard lock(dbMutex_); if (collections_.find(collectionName) != collections_.end()) { -- Gitee From 2498dacce838763828e46cb6e47a68b63050e481 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 11:49:11 +0800 Subject: [PATCH 04/17] Modify the jumbling function in the document Signed-off-by: Jeremyzz --- .../src/common/include/document_type.h | 12 +-- .../src/interface/include/document_store.h | 15 +-- .../src/interface/include/result_set.h | 8 +- .../src/interface/include/result_set_common.h | 4 +- .../src/interface/src/collection.cpp | 1 - .../src/interface/src/document_store.cpp | 102 ++++++++---------- .../src/interface/src/result_set.cpp | 51 ++++----- .../src/interface/src/result_set_common.cpp | 10 +- .../unittest/api/documentdb_data_test.cpp | 2 +- .../unittest/api/documentdb_find_test.cpp | 5 +- 10 files changed, 86 insertions(+), 124 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h index 676fd32d..33d5cd94 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h @@ -20,12 +20,12 @@ namespace DocumentDB { struct QueryContext { - std::string collectionName; - std::string filter; - std::vector> path; - bool ifShowId = false; - bool viewType = false; - bool isOnlyId = false; + std::string collectionName_; + std::string filter_; + std::vector> path_; + bool ifShowId_ = false; + bool viewType_ = false; + bool isOnlyId_ = false; }; } // namespace DocumentDB #endif // DOCUMENT_TYPE_H \ No newline at end of file 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 7a0ee3a7..09488401 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 @@ -67,17 +67,12 @@ public: std::mutex dbMutex_; private: - int UpdateDataIntoDB(const std::string &collection, JsonObject &filterObj, const std::string &update, - bool &isOnlyId, bool &isReplace); - int GetDocKey(JsonObject &filterObj, const std::string &collection, const std::string &filter, bool &isOnlyId, - std::string &docId); - int UpsertDataIntoDB(const std::string &collection, JsonObject &filterObj, JsonObject &documentObj, bool &isOnlyId, - bool &isReplace); + int UpdateDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, const std::string &update, bool &isReplace); + int UpsertDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, JsonObject &documentObj, bool &isReplace); int InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj); - int DeleteDataFromDB(const std::string &collection, const std::string &filter, JsonObject &filterObj, - bool &isOnlyId); - int InitFindResultSet(const std::string &collection, GRD_ResultSet *grdResultSet, QueryContext &resultInfo); - int CheckUpsertConflict(bool &isIdExist, const std::string &collection, JsonObject &filterObj, std::string &docId, + int DeleteDataFromDB(std::shared_ptr resultInfo, JsonObject &filterObj); + int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr resultInfo); + int CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, JsonObject &filterObj, std::string &docId, Collection &coll); KvStoreExecutor *executor_ = nullptr; std::map collections_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index 3906ba3d..7e187b12 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -31,7 +31,7 @@ class ResultSet { public: ResultSet(); ~ResultSet(); - int Init(QueryContext &QueryContext, DocumentStore *store); + int Init(std::shared_ptr resultSetInfo, DocumentStore *store, bool ifField); int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); @@ -44,13 +44,9 @@ private: int CheckCutNode(JsonObject *node, std::vector singleCutPath, std::vector> &allCutPath); DocumentStore *store_ = nullptr; - std::string collectionName_; ValueObject key_; - std::string filter_; - bool ifShowId_ = false; - bool viewType_ = false; bool ifField_ = false; - bool isOnlyId_ = false; + std::shared_ptr resultSetInfo_; ProjectionTree projectionTree_; std::vector> projectionPath_; size_t index_ = 0; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h index fa407cfa..6f42ac50 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h @@ -25,8 +25,6 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(QueryContext &resultInfo, DocumentStore *store, ResultSet &resultSet); -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - ResultSet &resultSet); +int InitResultSet(std::shared_ptr resultInfo, DocumentStore *store, ResultSet &resultSet, bool ifField); } // namespace DocumentDB #endif // RESULTSET_COMMON_H diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp index a45056d0..92f8f766 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/collection.cpp @@ -158,7 +158,6 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen GLOGD("Append value failed. %d", errCode); return errCode; } - // kkk std::string valStr = originValue.Print(); if (valStr.length() + 1 > JSON_LENS_MAX) { GLOGE("document's length is too long"); 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 f43bb4d1..66918f09 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 @@ -143,28 +143,6 @@ int TranFilter(JsonObject &filterObj, std::vector> &fil return errCode; } -int DocumentStore::GetDocKey(JsonObject &filterObj, const std::string &collection, const std::string &filter, - bool &isOnlyId, std::string &docId) -{ - int errCode = E_OK; - if (isOnlyId) { - JsonObject filterObjChild = filterObj.GetChild(); - ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); - docId = idValue.GetStringValue(); - } else { - ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); - errCode = resultSet.GetNext(); - if (errCode == -E_NO_DATA) { - return 0; // The amount of text updated - } else if (errCode != E_OK) { - return errCode; - } - resultSet.GetKey(docId); - } - return errCode; -} - int UpdateArgsCheck(const std::string &collection, const std::string &filter, const std::string &update, uint32_t flags) { std::string lowerCaseCollName; @@ -202,8 +180,8 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::UpdateDataIntoDB(const std::string &collection, JsonObject &filterObj, const std::string &update, - bool &isOnlyId, bool &isReplace) +int DocumentStore::UpdateDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, const std::string &update, + bool &isReplace) { int errCode = E_OK; std::lock_guard lock(dbMutex_); @@ -216,15 +194,15 @@ int DocumentStore::UpdateDataIntoDB(const std::string &collection, JsonObject &f } std::string docId; int count = 0; - auto coll = Collection(collection, executor_); - if (isOnlyId) { + auto coll = Collection(resultInfo->collectionName_, executor_); + if (resultInfo->isOnlyId_) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); docId = idValue.GetStringValue(); } else { ResultSet resultSet; std::string filter = filterObj.Print(); - InitResultSet(this, collection, filter, resultSet); + InitResultSet(resultInfo, this, resultSet, true); // no start transaction inner errCode = resultSet.GetNext(false, true); if (errCode == -E_NO_DATA) { @@ -271,7 +249,10 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri return errCode; } bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - errCode = UpdateDataIntoDB(collection, filterObj, update, isOnlyId, isReplace); + std::shared_ptr resultInfo = std::make_shared(); + resultInfo->collectionName_ = collection; + resultInfo->isOnlyId_ = isOnlyId; + errCode = UpdateDataIntoDB(resultInfo, filterObj, update, isReplace); return errCode; } @@ -307,7 +288,7 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::CheckUpsertConflict(bool &isIdExist, const std::string &collection, JsonObject &filterObj, +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, JsonObject &filterObj, std::string &docId, Collection &coll) { int errCode = E_OK; @@ -315,8 +296,7 @@ int DocumentStore::CheckUpsertConflict(bool &isIdExist, const std::string &colle errCode = -E_INVALID_ARGS; } ResultSet resultSet; - std::string filter = filterObj.Print(); - InitResultSet(this, collection, filter, resultSet); + InitResultSet(resultInfo, this, resultSet, true); errCode = resultSet.GetNext(false, true); bool isfilterMatch = false; if (errCode == E_OK) { @@ -331,8 +311,8 @@ int DocumentStore::CheckUpsertConflict(bool &isIdExist, const std::string &colle } } -int DocumentStore::UpsertDataIntoDB(const std::string &collection, JsonObject &filterObj, JsonObject &documentObj, - bool &isOnlyId, bool &isReplace) +int DocumentStore::UpsertDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, JsonObject &documentObj, + bool &isReplace) { int errCode = E_OK; std::lock_guard lock(dbMutex_); @@ -343,7 +323,7 @@ int DocumentStore::UpsertDataIntoDB(const std::string &collection, JsonObject &f if (errCode != E_OK) { return errCode; } - Collection coll = Collection(collection, executor_); + Collection coll = Collection(resultInfo->collectionName_, executor_); int count = 0; std::string targetDocument; std::string docId; @@ -354,8 +334,8 @@ int DocumentStore::UpsertDataIntoDB(const std::string &collection, JsonObject &f JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); documentObj.InsertItemObject(0, idObj); targetDocument = documentObj.Print(); - if (!isOnlyId) { - errCode = CheckUpsertConflict(isIdExist, collection, filterObj, docId, coll); + if (!resultInfo->isOnlyId_) { + errCode = CheckUpsertConflict(isIdExist, resultInfo, filterObj, docId, coll); if (errCode != E_OK) { goto END; } @@ -400,8 +380,12 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri 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; } @@ -479,27 +463,26 @@ int DeleteArgsCheck(const std::string &collection, const std::string &filter, ui return errCode; } -int DocumentStore::DeleteDataFromDB(const std::string &collection, const std::string &filter, JsonObject &filterObj, - bool &isOnlyId) +int DocumentStore::DeleteDataFromDB(std::shared_ptr resultInfo, JsonObject &filterObj) { int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - Collection coll = Collection(collection, executor_); + Collection coll = Collection(resultInfo->collectionName_, executor_); errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } std::string id; - if (isOnlyId) { + if (resultInfo->isOnlyId_) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); id = idValue.GetStringValue(); } else { ResultSet resultSet; - InitResultSet(this, collection, filter, resultSet); + InitResultSet(resultInfo, this, resultSet, true); errCode = resultSet.GetNext(false, true); if (errCode != E_OK) { goto END; @@ -535,7 +518,11 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } - errCode = DeleteDataFromDB(collection, filter, filterObj, isOnlyId); + std::shared_ptr resultInfo = std::make_shared(); + resultInfo->filter_ = filter; + resultInfo->collectionName_ = collection; + resultInfo->isOnlyId_ = isOnlyId; + errCode = DeleteDataFromDB(resultInfo, filterObj); return errCode; } Collection DocumentStore::GetCollection(std::string &collectionName) @@ -628,7 +615,7 @@ int FindArgsCheck(const std::string &collection, const std::string &filter, cons return errCode; } -int FindProjectionInit(const std::string &projection, QueryContext &resultInfo) +int FindProjectionInit(const std::string &projection, std::shared_ptr resultInfo) { int errCode = E_OK; std::vector> allPath; @@ -653,18 +640,17 @@ int FindProjectionInit(const std::string &projection, QueryContext &resultInfo) return errCode; } } - resultInfo.path = allPath; - resultInfo.viewType = viewType; + resultInfo->path_ = std::move(allPath); + resultInfo->viewType_ = viewType; return errCode; } -int DocumentStore::InitFindResultSet(const std::string &collection, GRD_ResultSet *grdResultSet, - QueryContext &resultInfo) +int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr resultInfo) { std::lock_guard lock(dbMutex_); int errCode = E_OK; - Collection coll = Collection(collection, executor_); - if (IsCollectionOpening(collection)) { + Collection coll = Collection(resultInfo->collectionName_, executor_); + if (IsCollectionOpening(resultInfo->collectionName_)) { return -E_RESOURCE_BUSY; } if (executor_ == nullptr) { @@ -681,9 +667,9 @@ int DocumentStore::InitFindResultSet(const std::string &collection, GRD_ResultSe if (errCode != E_OK) { goto END; } - errCode = InitResultSet(resultInfo, this, grdResultSet->resultSet_); + errCode = InitResultSet(resultInfo, this, grdResultSet->resultSet_, false); if (errCode == E_OK) { - collections_[collection] = nullptr; + collections_[resultInfo->collectionName_] = nullptr; } END: if (errCode == E_OK) { @@ -697,15 +683,15 @@ END: int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) { - QueryContext resultInfo; + std::shared_ptr resultInfo = std::make_shared(); int errCode = E_OK; errCode = FindArgsCheck(collection, filter, projection, flags); if (errCode != E_OK) { GLOGE("delete arg is illegal"); return errCode; } - resultInfo.collectionName = collection; - resultInfo.filter = filter; + resultInfo->collectionName_ = collection; + resultInfo->filter_ = filter; JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); @@ -722,13 +708,13 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("filter is invalid"); return errCode; } - resultInfo.isOnlyId = isOnlyId; + resultInfo->isOnlyId_ = isOnlyId; bool ifShowId = false; if (flags == GRD_DOC_ID_DISPLAY) { ifShowId = true; } - resultInfo.ifShowId = ifShowId; - errCode = InitFindResultSet(collection, grdResultSet, resultInfo); + resultInfo->ifShowId_ = ifShowId; + errCode = InitFindResultSet(grdResultSet, resultInfo); return errCode; } 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 0da40e02..7e0721fb 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 @@ -22,36 +22,27 @@ namespace DocumentDB { constexpr const char *KEY_ID = "_id"; ResultSet::ResultSet() {} -ResultSet::~ResultSet() {} +ResultSet::~ResultSet() +{ + resultSetInfo_ = nullptr; +} int ResultSet::EraseCollection() { if (store_ != nullptr) { - store_->EraseCollection(collectionName_); + store_->EraseCollection(resultSetInfo_->collectionName_); } return E_OK; } -int ResultSet::Init(QueryContext &resultSetInfo, DocumentStore *store) +int ResultSet::Init(std::shared_ptr resultSetInfo, DocumentStore *store, bool ifField_) { - isOnlyId_ = resultSetInfo.isOnlyId; + ifField_ = ifField_; + resultSetInfo_ = resultSetInfo; store_ = store; - collectionName_ = resultSetInfo.collectionName; - filter_ = resultSetInfo.filter; - projectionPath_ = resultSetInfo.path; + projectionPath_ = std::move(resultSetInfo->path_); if (projectionTree_.ParseTree(projectionPath_) == -E_INVALID_ARGS) { GLOGE("Parse ProjectionTree failed"); return -E_INVALID_ARGS; } - ifShowId_ = resultSetInfo.ifShowId; - viewType_ = resultSetInfo.viewType; - return E_OK; -} - -int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter) -{ - ifField_ = true; - store_ = store; - collectionName_ = collectionName; - filter_ = filter; return E_OK; } @@ -59,7 +50,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) { int errCode = E_OK; if (isNeedCheckTable) { - std::string lowerCaseName = collectionName_; + std::string lowerCaseName = resultSetInfo_->collectionName_; std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { return std::tolower(c); }); @@ -72,8 +63,8 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } } if (!ifField_ && index_ == 0) { - if (isOnlyId_) { - JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + if (resultSetInfo_->isOnlyId_) { + JsonObject filterObj = JsonObject::Parse(resultSetInfo_->filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -86,7 +77,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } Key key(idKey.begin(), idKey.end()); Value document; - Collection coll = store_->GetCollection(collectionName_); + Collection coll = store_->GetCollection(resultSetInfo_->collectionName_); errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { return -E_NO_DATA; @@ -97,9 +88,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) values.emplace_back(std::pair(idKey, jsonData)); matchDatas_ = values; } else { - Collection coll = store_->GetCollection(collectionName_); + Collection coll = store_->GetCollection(resultSetInfo_->collectionName_); std::vector> values; - JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(resultSetInfo_->filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -114,9 +105,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) matchDatas_ = values; } } else if (index_ == 0) { - Collection coll = store_->GetCollection(collectionName_); + Collection coll = store_->GetCollection(resultSetInfo_->collectionName_); std::vector> values; - JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(resultSetInfo_->filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -219,7 +210,7 @@ int ResultSet::CutJsonBranch(std::string &jsonData) return errCode; } std::vector> allCutPath; - if (viewType_) { + if (resultSetInfo_->viewType_) { std::vector singlePath; JsonObject cjsonObjChild = cjsonObj.GetChild(); errCode = CheckCutNode(&cjsonObjChild, singlePath, allCutPath); @@ -228,16 +219,16 @@ int ResultSet::CutJsonBranch(std::string &jsonData) return errCode; } for (auto singleCutPaht : allCutPath) { - if (!ifShowId_ || singleCutPaht[0] != KEY_ID) { + if (!resultSetInfo_->ifShowId_ || singleCutPaht[0] != KEY_ID) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } } } - if (!viewType_) { + if (!resultSetInfo_->viewType_) { for (auto singleCutPaht : projectionPath_) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } - if (!ifShowId_) { + if (!resultSetInfo_->ifShowId_) { std::vector idPath; idPath.emplace_back(KEY_ID); cjsonObj.DeleteItemDeeplyOnTarget(idPath); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index f2d1a4f8..df2b5417 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -23,14 +23,8 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(QueryContext &resultInfo, DocumentStore *store, ResultSet &resultSet) +int InitResultSet(std::shared_ptr resultInfo, DocumentStore *store, ResultSet &resultSet, bool ifField) { - return resultSet.Init(resultInfo, store); -} - -int InitResultSet(DocumentStore *store, const std::string collectionName, const std::string &filter, - ResultSet &resultSet) -{ - return resultSet.Init(store, collectionName, filter); + return resultSet.Init(resultInfo, store, ifField); } } // namespace DocumentDB 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 57ab47aa..06281be0 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 3fa8c92d..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 }; @@ -1438,14 +1438,17 @@ HWTEST_F(DocumentDBFindTest, DocumentDBFindTest061, TestSize.Level1) char *value = nullptr; EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, document061); + EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, document062); + EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); CompareValue(value, document063); + EXPECT_EQ(GRD_FreeValue(value), GRD_OK); EXPECT_EQ(GRD_Next(resultSet), GRD_OK); EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); -- Gitee From c5d74a6a3dd280f781cf3292edd7f10a6e79bdbe Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 15:44:54 +0800 Subject: [PATCH 05/17] fix some bug Signed-off-by: Jeremyzz --- .../src/interface/src/document_store.cpp | 79 +++++++++++-------- 1 file changed, 46 insertions(+), 33 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 66918f09..50fa2cea 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 @@ -180,8 +180,8 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::UpdateDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, const std::string &update, - bool &isReplace) +int DocumentStore::UpdateDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, + const std::string &update, bool &isReplace) { int errCode = E_OK; std::lock_guard lock(dbMutex_); @@ -252,12 +252,13 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri std::shared_ptr resultInfo = std::make_shared(); resultInfo->collectionName_ = collection; resultInfo->isOnlyId_ = isOnlyId; + resultInfo->filter_ = filter; errCode = UpdateDataIntoDB(resultInfo, filterObj, update, isReplace); return errCode; } int UpsertArgsCheck(const std::string &collection, const std::string &filter, const std::string &document, - JsonObject &documentObj, uint32_t flags) + uint32_t flags) { std::string lowerCaseCollName; int errCode = E_OK; @@ -269,18 +270,6 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co GLOGE("args length is too long"); return -E_OVER_LIMIT; } - std::vector> allPath; - if (document != "{}") { - allPath = JsonCommon::ParsePath(documentObj, errCode); - if (errCode != E_OK) { - return errCode; - } - errCode = CheckCommon::CheckUpdata(documentObj, allPath); - if (errCode != E_OK) { - GLOGE("UpsertDocument document format is illegal"); - return errCode; - } - } if (flags != GRD_DOC_APPEND && flags != GRD_DOC_REPLACE) { GLOGE("Check flags invalid."); return -E_INVALID_ARGS; @@ -288,13 +277,10 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, JsonObject &filterObj, - std::string &docId, Collection &coll) +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, + JsonObject &filterObj, std::string &docId, Collection &coll) { int errCode = E_OK; - if (!isIdExist) { - errCode = -E_INVALID_ARGS; - } ResultSet resultSet; InitResultSet(resultInfo, this, resultSet, true); errCode = resultSet.GetNext(false, true); @@ -309,10 +295,11 @@ int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, JsonObject &filterObj, JsonObject &documentObj, - bool &isReplace) +int DocumentStore::UpsertDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, + JsonObject &documentObj, bool &isReplace) { int errCode = E_OK; std::lock_guard lock(dbMutex_); @@ -334,6 +321,10 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr resultInfo, Js JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); documentObj.InsertItemObject(0, idObj); targetDocument = documentObj.Print(); + if (!isIdExist) { + errCode = -E_INVALID_ARGS; + goto END; + } if (!resultInfo->isOnlyId_) { errCode = CheckUpsertConflict(isIdExist, resultInfo, filterObj, docId, coll); if (errCode != E_OK) { @@ -355,22 +346,44 @@ END: return (errCode == E_OK) ? count : errCode; } +int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentObj) +{ + int errCode = E_OK; + std::vector> allPath; + if (document != "{}") { + allPath = JsonCommon::ParsePath(documentObj, errCode); + if (errCode != E_OK) { + return errCode; + } + errCode = CheckCommon::CheckUpdata(documentObj, allPath); + if (errCode != E_OK) { + GLOGE("UpsertDocument document format is illegal"); + return errCode; + } + } + return errCode; +} int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, 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; @@ -389,7 +402,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri 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) { @@ -405,10 +418,6 @@ int InsertArgsCheck(const std::string &collection, const std::string &document, GLOGE("document's length is too long"); return -E_OVER_LIMIT; } - errCode = CheckCommon::CheckDocument(documentObj); - if (errCode != E_OK) { - return errCode; - } return errCode; } @@ -427,12 +436,16 @@ int DocumentStore::InsertDataIntoDB(const std::string &collection, const std::st int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) { int errCode = E_OK; + errCode = InsertArgsCheck(collection, document, flags); + if (errCode != E_OK) { + return errCode; + } JsonObject documentObj = JsonObject::Parse(document, errCode, true); if (errCode != E_OK) { GLOGE("Document Parsed failed"); return errCode; } - errCode = InsertArgsCheck(collection, document, documentObj, flags); + errCode = CheckCommon::CheckDocument(documentObj); if (errCode != E_OK) { return errCode; } -- Gitee From 5c64475940fb5bddf17c3160173c83f1bdb5ac23 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 16:29:14 +0800 Subject: [PATCH 06/17] fix bug Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/interface/src/document_store.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 50fa2cea..c1848262 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 @@ -327,7 +327,8 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr resultInfo, Js } if (!resultInfo->isOnlyId_) { errCode = CheckUpsertConflict(isIdExist, resultInfo, filterObj, docId, coll); - if (errCode != E_OK) { + if (errCode == -E_DATA_CONFLICT) { // There are only three return values, E_ OK and - E_ NO_ The return value of DATA is a normal scenario, and you can continue to move forward + GLOGE("upsert data conflict"); goto END; } } -- Gitee From 02ca198b754771b649aa506bc25e9bbc491ca444 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 16:46:33 +0800 Subject: [PATCH 07/17] fix code check Signed-off-by: Jeremyzz --- .../src/common/include/document_type.h | 3 + .../src/interface/include/document_store.h | 14 +-- .../src/interface/include/result_set.h | 7 +- .../src/interface/include/result_set_common.h | 2 +- .../src/interface/src/document_store.cpp | 88 +++++++++---------- .../src/interface/src/result_set.cpp | 43 ++++----- .../src/interface/src/result_set_common.cpp | 8 +- 7 files changed, 83 insertions(+), 82 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h index 33d5cd94..b9bc7ce0 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h @@ -18,11 +18,14 @@ #include +#include "projection_tree.h" + namespace DocumentDB { struct QueryContext { std::string collectionName_; std::string filter_; std::vector> path_; + ProjectionTree projectionTree_; bool ifShowId_ = false; bool viewType_ = false; bool isOnlyId_ = false; 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 09488401..8843fdd3 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 @@ -67,13 +67,15 @@ public: std::mutex dbMutex_; private: - int UpdateDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, const std::string &update, bool &isReplace); - int UpsertDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, JsonObject &documentObj, bool &isReplace); + int UpdateDataIntoDB(std::shared_ptr context, JsonObject &filterObj, const std::string &update, + bool &isReplace); + int UpsertDataIntoDB(std::shared_ptr context, JsonObject &filterObj, JsonObject &documentObj, + bool &isReplace); int InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj); - int DeleteDataFromDB(std::shared_ptr resultInfo, JsonObject &filterObj); - int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr resultInfo); - int CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, JsonObject &filterObj, std::string &docId, - Collection &coll); + int DeleteDataFromDB(std::shared_ptr context, JsonObject &filterObj); + int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr context); + int CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, + std::string &docId, Collection &coll); KvStoreExecutor *executor_ = nullptr; std::map collections_; std::function closeNotifier_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index 7e187b12..db57f3cb 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -24,14 +24,13 @@ #include "document_store.h" #include "grd_base/grd_type_export.h" #include "json_object.h" -#include "projection_tree.h" namespace DocumentDB { class ResultSet { public: ResultSet(); ~ResultSet(); - int Init(std::shared_ptr resultSetInfo, DocumentStore *store, bool ifField); + int Init(std::shared_ptr context, DocumentStore *store, bool ifField); int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); @@ -46,10 +45,8 @@ private: DocumentStore *store_ = nullptr; ValueObject key_; bool ifField_ = false; - std::shared_ptr resultSetInfo_; - ProjectionTree projectionTree_; - std::vector> projectionPath_; size_t index_ = 0; + std::shared_ptr context_; std::vector> matchDatas_; }; } // namespace DocumentDB diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h index 6f42ac50..189d2243 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h @@ -25,6 +25,6 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(std::shared_ptr resultInfo, DocumentStore *store, ResultSet &resultSet, bool ifField); +int InitResultSet(std::shared_ptr context, DocumentStore *store, ResultSet &resultSet, bool ifField); } // namespace DocumentDB #endif // RESULTSET_COMMON_H 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 c1848262..249dd9aa 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 @@ -180,7 +180,7 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::UpdateDataIntoDB(std::shared_ptr resultInfo, JsonObject &filterObj, +int DocumentStore::UpdateDataIntoDB(std::shared_ptr context, JsonObject &filterObj, const std::string &update, bool &isReplace) { int errCode = E_OK; @@ -194,15 +194,15 @@ int DocumentStore::UpdateDataIntoDB(std::shared_ptr resultInfo, Js } std::string docId; int count = 0; - auto coll = Collection(resultInfo->collectionName_, executor_); - if (resultInfo->isOnlyId_) { + auto coll = Collection(context->collectionName_, executor_); + if (context->isOnlyId_) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); docId = idValue.GetStringValue(); } else { ResultSet resultSet; std::string filter = filterObj.Print(); - InitResultSet(resultInfo, this, resultSet, true); + InitResultSet(context, this, resultSet, true); // no start transaction inner errCode = resultSet.GetNext(false, true); if (errCode == -E_NO_DATA) { @@ -249,11 +249,11 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri return errCode; } bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - std::shared_ptr resultInfo = std::make_shared(); - resultInfo->collectionName_ = collection; - resultInfo->isOnlyId_ = isOnlyId; - resultInfo->filter_ = filter; - errCode = UpdateDataIntoDB(resultInfo, filterObj, update, isReplace); + std::shared_ptr context = std::make_shared(); + context->collectionName_ = collection; + context->isOnlyId_ = isOnlyId; + context->filter_ = filter; + errCode = UpdateDataIntoDB(context, filterObj, update, isReplace); return errCode; } @@ -277,12 +277,12 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, std::string &docId, Collection &coll) { int errCode = E_OK; ResultSet resultSet; - InitResultSet(resultInfo, this, resultSet, true); + InitResultSet(context, this, resultSet, true); errCode = resultSet.GetNext(false, true); bool isfilterMatch = false; if (errCode == E_OK) { @@ -298,7 +298,7 @@ int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr resultInfo, JsonObject &filterObj, +int DocumentStore::UpsertDataIntoDB(std::shared_ptr context, JsonObject &filterObj, JsonObject &documentObj, bool &isReplace) { int errCode = E_OK; @@ -310,7 +310,7 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr resultInfo, Js if (errCode != E_OK) { return errCode; } - Collection coll = Collection(resultInfo->collectionName_, executor_); + Collection coll = Collection(context->collectionName_, executor_); int count = 0; std::string targetDocument; std::string docId; @@ -325,8 +325,8 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr resultInfo, Js errCode = -E_INVALID_ARGS; goto END; } - if (!resultInfo->isOnlyId_) { - errCode = CheckUpsertConflict(isIdExist, resultInfo, filterObj, docId, coll); + if (!context->isOnlyId_) { + errCode = CheckUpsertConflict(isIdExist, context, filterObj, docId, coll); if (errCode == -E_DATA_CONFLICT) { // There are only three return values, E_ OK and - E_ NO_ The return value of DATA is a normal scenario, and you can continue to move forward GLOGE("upsert data conflict"); goto END; @@ -394,12 +394,12 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri 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; } @@ -477,26 +477,26 @@ int DeleteArgsCheck(const std::string &collection, const std::string &filter, ui return errCode; } -int DocumentStore::DeleteDataFromDB(std::shared_ptr resultInfo, JsonObject &filterObj) +int DocumentStore::DeleteDataFromDB(std::shared_ptr context, JsonObject &filterObj) { int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - Collection coll = Collection(resultInfo->collectionName_, executor_); + Collection coll = Collection(context->collectionName_, executor_); errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } std::string id; - if (resultInfo->isOnlyId_) { + if (context->isOnlyId_) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); id = idValue.GetStringValue(); } else { ResultSet resultSet; - InitResultSet(resultInfo, this, resultSet, true); + InitResultSet(context, this, resultSet, true); errCode = resultSet.GetNext(false, true); if (errCode != E_OK) { goto END; @@ -532,11 +532,11 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } - std::shared_ptr resultInfo = std::make_shared(); - resultInfo->filter_ = filter; - resultInfo->collectionName_ = collection; - resultInfo->isOnlyId_ = isOnlyId; - errCode = DeleteDataFromDB(resultInfo, filterObj); + std::shared_ptr context = std::make_shared(); + context->filter_ = filter; + context->collectionName_ = collection; + context->isOnlyId_ = isOnlyId; + errCode = DeleteDataFromDB(context, filterObj); return errCode; } Collection DocumentStore::GetCollection(std::string &collectionName) @@ -629,7 +629,7 @@ int FindArgsCheck(const std::string &collection, const std::string &filter, cons return errCode; } -int FindProjectionInit(const std::string &projection, std::shared_ptr resultInfo) +int FindProjectionInit(const std::string &projection, std::shared_ptr context) { int errCode = E_OK; std::vector> allPath; @@ -654,17 +654,17 @@ int FindProjectionInit(const std::string &projection, std::shared_ptrpath_ = std::move(allPath); - resultInfo->viewType_ = viewType; + context->path_ = std::move(allPath); + context->viewType_ = viewType; return errCode; } -int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr resultInfo) +int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr context) { std::lock_guard lock(dbMutex_); int errCode = E_OK; - Collection coll = Collection(resultInfo->collectionName_, executor_); - if (IsCollectionOpening(resultInfo->collectionName_)) { + Collection coll = Collection(context->collectionName_, executor_); + if (IsCollectionOpening(context->collectionName_)) { return -E_RESOURCE_BUSY; } if (executor_ == nullptr) { @@ -681,9 +681,9 @@ int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_pt if (errCode != E_OK) { goto END; } - errCode = InitResultSet(resultInfo, this, grdResultSet->resultSet_, false); + errCode = InitResultSet(context, this, grdResultSet->resultSet_, false); if (errCode == E_OK) { - collections_[resultInfo->collectionName_] = nullptr; + collections_[context->collectionName_] = nullptr; } END: if (errCode == E_OK) { @@ -697,21 +697,21 @@ END: int DocumentStore::FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, uint32_t flags, GRD_ResultSet *grdResultSet) { - std::shared_ptr resultInfo = std::make_shared(); + std::shared_ptr context = std::make_shared(); int errCode = E_OK; errCode = FindArgsCheck(collection, filter, projection, flags); if (errCode != E_OK) { GLOGE("delete arg is illegal"); return errCode; } - resultInfo->collectionName_ = collection; - resultInfo->filter_ = filter; + context->collectionName_ = collection; + context->filter_ = filter; JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; } - errCode = FindProjectionInit(projection, resultInfo); + errCode = FindProjectionInit(projection, context); if (errCode != E_OK) { return errCode; } @@ -722,13 +722,13 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("filter is invalid"); return errCode; } - resultInfo->isOnlyId_ = isOnlyId; + context->isOnlyId_ = isOnlyId; bool ifShowId = false; if (flags == GRD_DOC_ID_DISPLAY) { ifShowId = true; } - resultInfo->ifShowId_ = ifShowId; - errCode = InitFindResultSet(grdResultSet, resultInfo); + context->ifShowId_ = ifShowId; + errCode = InitFindResultSet(grdResultSet, context); return errCode; } 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 7e0721fb..1032cd34 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 @@ -22,27 +22,22 @@ namespace DocumentDB { constexpr const char *KEY_ID = "_id"; ResultSet::ResultSet() {} -ResultSet::~ResultSet() +ResultSet::~ResultSet() { - resultSetInfo_ = nullptr; + context_ = nullptr; } int ResultSet::EraseCollection() { if (store_ != nullptr) { - store_->EraseCollection(resultSetInfo_->collectionName_); + store_->EraseCollection(context_->collectionName_); } return E_OK; } -int ResultSet::Init(std::shared_ptr resultSetInfo, DocumentStore *store, bool ifField_) +int ResultSet::Init(std::shared_ptr context, DocumentStore *store, bool ifField_) { ifField_ = ifField_; - resultSetInfo_ = resultSetInfo; + context_ = context; store_ = store; - projectionPath_ = std::move(resultSetInfo->path_); - if (projectionTree_.ParseTree(projectionPath_) == -E_INVALID_ARGS) { - GLOGE("Parse ProjectionTree failed"); - return -E_INVALID_ARGS; - } return E_OK; } @@ -50,7 +45,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) { int errCode = E_OK; if (isNeedCheckTable) { - std::string lowerCaseName = resultSetInfo_->collectionName_; + std::string lowerCaseName = context_->collectionName_; std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { return std::tolower(c); }); @@ -63,8 +58,8 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } } if (!ifField_ && index_ == 0) { - if (resultSetInfo_->isOnlyId_) { - JsonObject filterObj = JsonObject::Parse(resultSetInfo_->filter_, errCode, true, true); + if (context_->isOnlyId_) { + JsonObject filterObj = JsonObject::Parse(context_->filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -77,7 +72,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } Key key(idKey.begin(), idKey.end()); Value document; - Collection coll = store_->GetCollection(resultSetInfo_->collectionName_); + Collection coll = store_->GetCollection(context_->collectionName_); errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { return -E_NO_DATA; @@ -88,9 +83,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) values.emplace_back(std::pair(idKey, jsonData)); matchDatas_ = values; } else { - Collection coll = store_->GetCollection(resultSetInfo_->collectionName_); + Collection coll = store_->GetCollection(context_->collectionName_); std::vector> values; - JsonObject filterObj = JsonObject::Parse(resultSetInfo_->filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(context_->filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -105,9 +100,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) matchDatas_ = values; } } else if (index_ == 0) { - Collection coll = store_->GetCollection(resultSetInfo_->collectionName_); + Collection coll = store_->GetCollection(context_->collectionName_); std::vector> values; - JsonObject filterObj = JsonObject::Parse(resultSetInfo_->filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(context_->filter_, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -187,7 +182,7 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat } singlePath.emplace_back(node->GetItemField()); int index = 0; - if (!projectionTree_.SearchTree(singlePath, index) && index == 0) { + if (!context_->projectionTree_.SearchTree(singlePath, index) && index == 0) { allCutPath.emplace_back(singlePath); } if (!node->GetChild().IsNull()) { @@ -210,7 +205,7 @@ int ResultSet::CutJsonBranch(std::string &jsonData) return errCode; } std::vector> allCutPath; - if (resultSetInfo_->viewType_) { + if (context_->viewType_) { std::vector singlePath; JsonObject cjsonObjChild = cjsonObj.GetChild(); errCode = CheckCutNode(&cjsonObjChild, singlePath, allCutPath); @@ -219,16 +214,16 @@ int ResultSet::CutJsonBranch(std::string &jsonData) return errCode; } for (auto singleCutPaht : allCutPath) { - if (!resultSetInfo_->ifShowId_ || singleCutPaht[0] != KEY_ID) { + if (!context_->ifShowId_ || singleCutPaht[0] != KEY_ID) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } } } - if (!resultSetInfo_->viewType_) { - for (auto singleCutPaht : projectionPath_) { + if (!context_->viewType_) { + for (auto singleCutPaht : context_->path_) { // projection Path cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } - if (!resultSetInfo_->ifShowId_) { + if (!context_->ifShowId_) { std::vector idPath; idPath.emplace_back(KEY_ID); cjsonObj.DeleteItemDeeplyOnTarget(idPath); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index df2b5417..2e6cef1a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -23,8 +23,12 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(std::shared_ptr resultInfo, DocumentStore *store, ResultSet &resultSet, bool ifField) +int InitResultSet(std::shared_ptr context, DocumentStore *store, ResultSet &resultSet, bool ifField) { - return resultSet.Init(resultInfo, store, ifField); + if (context->projectionTree_.ParseTree(context->path_) == -E_INVALID_ARGS) { + GLOGE("Parse ProjectionTree failed"); + return -E_INVALID_ARGS; + } + return resultSet.Init(context, store, ifField); } } // namespace DocumentDB -- Gitee From 77200e756352c63cb77e925f8a4db438ae180f59 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 16:48:27 +0800 Subject: [PATCH 08/17] fix code check Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/interface/src/document_store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 249dd9aa..f420201b 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 @@ -327,7 +327,7 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr context, JsonO } if (!context->isOnlyId_) { errCode = CheckUpsertConflict(isIdExist, context, filterObj, docId, coll); - if (errCode == -E_DATA_CONFLICT) { // There are only three return values, E_ OK and - E_ NO_ The return value of DATA is a normal scenario, and you can continue to move forward + if (errCode == -E_DATA_CONFLICT) { // There are only three return values, E_ OK and - E_ NO_DATA is a normal scenario, and that situation can continue to move forward GLOGE("upsert data conflict"); goto END; } -- Gitee From 8fc08e6a0afbbe0ba9fc551447b927fef510b7ad Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 17:38:12 +0800 Subject: [PATCH 09/17] 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 9ae788e043cabc617b311e31a2dd78ae2cca9bfe Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 17:44:16 +0800 Subject: [PATCH 10/17] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/src/document_store.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 f420201b..249f7fbf 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 @@ -327,7 +327,9 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr context, JsonO } if (!context->isOnlyId_) { errCode = CheckUpsertConflict(isIdExist, context, filterObj, docId, coll); - if (errCode == -E_DATA_CONFLICT) { // There are only three return values, E_ OK and - E_ NO_DATA is a normal scenario, and that situation can continue to move forward + // There are only three return values, E_ OK and - E_ NO_DATA is a normal scenario, + // and that situation can continue to move forward + if (errCode == -E_DATA_CONFLICT) { GLOGE("upsert data conflict"); goto END; } -- Gitee From 462080812438b5df20664ef71345de2f876eb1ca Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 17:46:28 +0800 Subject: [PATCH 11/17] 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 06281be0..57ab47aa 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 d712e39c721b4be7d4aebb0de15434f6d2c99477 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Mon, 15 May 2023 18:07:51 +0800 Subject: [PATCH 12/17] fix code check Signed-off-by: Jeremyzz --- .../gaussdb_rd/src/interface/src/result_set_common.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index 2e6cef1a..385e5270 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -25,9 +25,11 @@ namespace DocumentDB { class ValueObject; int InitResultSet(std::shared_ptr context, DocumentStore *store, ResultSet &resultSet, bool ifField) { - if (context->projectionTree_.ParseTree(context->path_) == -E_INVALID_ARGS) { - GLOGE("Parse ProjectionTree failed"); - return -E_INVALID_ARGS; + if (ifField == false) { + if (context->projectionTree_.ParseTree(context->path_) == -E_INVALID_ARGS) { + GLOGE("Parse ProjectionTree failed"); + return -E_INVALID_ARGS; + } } return resultSet.Init(context, store, ifField); } -- Gitee From 0d30e8b643ab3b377c2b034d247f1ade041166bb Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 16 May 2023 09:41:41 +0800 Subject: [PATCH 13/17] fix code check Signed-off-by: Jeremyzz --- .../src/common/include/document_type.h | 14 +-- .../src/interface/src/document_store.cpp | 105 ++++++++---------- .../src/interface/src/result_set.cpp | 30 ++--- .../src/interface/src/result_set_common.cpp | 2 +- 4 files changed, 67 insertions(+), 84 deletions(-) diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h index b9bc7ce0..69c95c0e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/include/document_type.h @@ -22,13 +22,13 @@ namespace DocumentDB { struct QueryContext { - std::string collectionName_; - std::string filter_; - std::vector> path_; - ProjectionTree projectionTree_; - bool ifShowId_ = false; - bool viewType_ = false; - bool isOnlyId_ = false; + std::string collectionName; + std::string filter; + std::vector> path; + ProjectionTree projectionTree; + bool ifShowId = false; + bool viewType = false; + bool isOnlyId = false; }; } // namespace DocumentDB #endif // DOCUMENT_TYPE_H \ No newline at end of file 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 249f7fbf..73d27068 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 @@ -136,11 +136,7 @@ int TranFilter(JsonObject &filterObj, std::vector> &fil GLOGE("filter ParsePath failed"); return errCode; } - errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); - if (errCode != E_OK) { - return errCode; - } - return errCode; + return CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); } int UpdateArgsCheck(const std::string &collection, const std::string &filter, const std::string &update, uint32_t flags) @@ -183,19 +179,18 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co int DocumentStore::UpdateDataIntoDB(std::shared_ptr context, JsonObject &filterObj, const std::string &update, bool &isReplace) { - int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - errCode = executor_->StartTransaction(); + int errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } std::string docId; int count = 0; - auto coll = Collection(context->collectionName_, executor_); - if (context->isOnlyId_) { + auto coll = Collection(context->collectionName, executor_); + if (context->isOnlyId) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); docId = idValue.GetStringValue(); @@ -232,8 +227,7 @@ END: int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, uint32_t flags) { - int errCode = E_OK; - errCode = UpdateArgsCheck(collection, filter, update, flags); + int errCode = UpdateArgsCheck(collection, filter, update, flags); if (errCode != E_OK) { return errCode; } @@ -250,11 +244,10 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri } bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); std::shared_ptr context = std::make_shared(); - context->collectionName_ = collection; - context->isOnlyId_ = isOnlyId; - context->filter_ = filter; - errCode = UpdateDataIntoDB(context, filterObj, update, isReplace); - return errCode; + context->collectionName = collection; + context->isOnlyId = isOnlyId; + context->filter = filter; + return UpdateDataIntoDB(context, filterObj, update, isReplace); } int UpsertArgsCheck(const std::string &collection, const std::string &filter, const std::string &document, @@ -277,13 +270,12 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, - JsonObject &filterObj, std::string &docId, Collection &coll) +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, + std::string &docId, Collection &coll) { - int errCode = E_OK; ResultSet resultSet; InitResultSet(context, this, resultSet, true); - errCode = resultSet.GetNext(false, true); + int errCode = resultSet.GetNext(false, true); bool isfilterMatch = false; if (errCode == E_OK) { isfilterMatch = true; @@ -301,16 +293,15 @@ int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, JsonObject &documentObj, bool &isReplace) { - int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - errCode = executor_->StartTransaction(); + int errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } - Collection coll = Collection(context->collectionName_, executor_); + Collection coll = Collection(context->collectionName, executor_); int count = 0; std::string targetDocument; std::string docId; @@ -325,7 +316,7 @@ int DocumentStore::UpsertDataIntoDB(std::shared_ptr context, JsonO errCode = -E_INVALID_ARGS; goto END; } - if (!context->isOnlyId_) { + if (!context->isOnlyId) { errCode = CheckUpsertConflict(isIdExist, context, filterObj, docId, coll); // There are only three return values, E_ OK and - E_ NO_DATA is a normal scenario, // and that situation can continue to move forward @@ -369,8 +360,7 @@ int UpsertDocumentFormatCheck(const std::string &document, JsonObject &documentO int DocumentStore::UpsertDocument(const std::string &collection, const std::string &filter, const std::string &document, uint32_t flags) { - int errCode = E_OK; - errCode = UpsertArgsCheck(collection, filter, document, flags); + int errCode = UpsertArgsCheck(collection, filter, document, flags); if (errCode != E_OK) { return errCode; } @@ -397,22 +387,21 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri 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; @@ -438,8 +427,7 @@ int DocumentStore::InsertDataIntoDB(const std::string &collection, const std::st int DocumentStore::InsertDocument(const std::string &collection, const std::string &document, uint32_t flags) { - int errCode = E_OK; - errCode = InsertArgsCheck(collection, document, flags); + int errCode = InsertArgsCheck(collection, document, flags); if (errCode != E_OK) { return errCode; } @@ -452,8 +440,7 @@ int DocumentStore::InsertDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } - errCode = InsertDataIntoDB(collection, document, documentObj); - return errCode; + return InsertDataIntoDB(collection, document, documentObj); } int DeleteArgsCheck(const std::string &collection, const std::string &filter, uint32_t flags) @@ -481,18 +468,17 @@ int DeleteArgsCheck(const std::string &collection, const std::string &filter, ui int DocumentStore::DeleteDataFromDB(std::shared_ptr context, JsonObject &filterObj) { - int errCode = E_OK; std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { return -E_INNER_ERROR; } - Collection coll = Collection(context->collectionName_, executor_); - errCode = executor_->StartTransaction(); + Collection coll = Collection(context->collectionName, executor_); + int errCode = executor_->StartTransaction(); if (errCode != E_OK) { return errCode; } std::string id; - if (context->isOnlyId_) { + if (context->isOnlyId) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); id = idValue.GetStringValue(); @@ -519,8 +505,7 @@ END: } int DocumentStore::DeleteDocument(const std::string &collection, const std::string &filter, uint32_t flags) { - int errCode = E_OK; - errCode = DeleteArgsCheck(collection, filter, flags); + int errCode = DeleteArgsCheck(collection, filter, flags); if (errCode != E_OK) { return errCode; } @@ -535,11 +520,10 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } std::shared_ptr context = std::make_shared(); - context->filter_ = filter; - context->collectionName_ = collection; - context->isOnlyId_ = isOnlyId; - errCode = DeleteDataFromDB(context, filterObj); - return errCode; + context->filter = filter; + context->collectionName = collection; + context->isOnlyId = isOnlyId; + return DeleteDataFromDB(context, filterObj); } Collection DocumentStore::GetCollection(std::string &collectionName) { @@ -604,7 +588,7 @@ int GetViewType(JsonObject &jsonObj, bool &viewType) return ret; } } - return E_OK; + return ret; } int FindArgsCheck(const std::string &collection, const std::string &filter, const std::string &projection, @@ -656,8 +640,8 @@ int FindProjectionInit(const std::string &projection, std::shared_ptrpath_ = std::move(allPath); - context->viewType_ = viewType; + context->path = std::move(allPath); + context->viewType = viewType; return errCode; } @@ -665,8 +649,8 @@ 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_)) { + Collection coll = Collection(context->collectionName, executor_); + if (IsCollectionOpening(context->collectionName)) { return -E_RESOURCE_BUSY; } if (executor_ == nullptr) { @@ -685,7 +669,7 @@ int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_pt } errCode = InitResultSet(context, this, grdResultSet->resultSet_, false); if (errCode == E_OK) { - collections_[context->collectionName_] = nullptr; + collections_[context->collectionName] = nullptr; } END: if (errCode == E_OK) { @@ -706,8 +690,8 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("delete arg is illegal"); return errCode; } - context->collectionName_ = collection; - context->filter_ = filter; + context->collectionName = collection; + context->filter = filter; JsonObject filterObj = JsonObject::Parse(filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); @@ -724,14 +708,13 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("filter is invalid"); return errCode; } - context->isOnlyId_ = isOnlyId; - bool ifShowId = false; + context->isOnlyId = isOnlyId; if (flags == GRD_DOC_ID_DISPLAY) { - ifShowId = true; + context->ifShowId = true; + } else { + context->ifShowId = false; } - context->ifShowId_ = ifShowId; - errCode = InitFindResultSet(grdResultSet, context); - return errCode; + return InitFindResultSet(grdResultSet, context); } bool DocumentStore::IsCollectionOpening(const std::string &collection) 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 1032cd34..4cad1960 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 @@ -29,7 +29,7 @@ ResultSet::~ResultSet() int ResultSet::EraseCollection() { if (store_ != nullptr) { - store_->EraseCollection(context_->collectionName_); + store_->EraseCollection(context_->collectionName); } return E_OK; } @@ -45,7 +45,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) { int errCode = E_OK; if (isNeedCheckTable) { - std::string lowerCaseName = context_->collectionName_; + std::string lowerCaseName = context_->collectionName; std::transform(lowerCaseName.begin(), lowerCaseName.end(), lowerCaseName.begin(), [](unsigned char c) { return std::tolower(c); }); @@ -58,8 +58,8 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } } if (!ifField_ && index_ == 0) { - if (context_->isOnlyId_) { - JsonObject filterObj = JsonObject::Parse(context_->filter_, errCode, true, true); + if (context_->isOnlyId) { + JsonObject filterObj = JsonObject::Parse(context_->filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -72,7 +72,7 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) } Key key(idKey.begin(), idKey.end()); Value document; - Collection coll = store_->GetCollection(context_->collectionName_); + Collection coll = store_->GetCollection(context_->collectionName); errCode = coll.GetDocument(key, document); if (errCode == -E_NOT_FOUND) { return -E_NO_DATA; @@ -83,9 +83,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) values.emplace_back(std::pair(idKey, jsonData)); matchDatas_ = values; } else { - Collection coll = store_->GetCollection(context_->collectionName_); + Collection coll = store_->GetCollection(context_->collectionName); std::vector> values; - JsonObject filterObj = JsonObject::Parse(context_->filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(context_->filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -100,9 +100,9 @@ int ResultSet::GetNextInner(bool isNeedCheckTable) matchDatas_ = values; } } else if (index_ == 0) { - Collection coll = store_->GetCollection(context_->collectionName_); + Collection coll = store_->GetCollection(context_->collectionName); std::vector> values; - JsonObject filterObj = JsonObject::Parse(context_->filter_, errCode, true, true); + JsonObject filterObj = JsonObject::Parse(context_->filter, errCode, true, true); if (errCode != E_OK) { GLOGE("filter Parsed failed"); return errCode; @@ -182,7 +182,7 @@ int ResultSet::CheckCutNode(JsonObject *node, std::vector singlePat } singlePath.emplace_back(node->GetItemField()); int index = 0; - if (!context_->projectionTree_.SearchTree(singlePath, index) && index == 0) { + if (!context_->projectionTree.SearchTree(singlePath, index) && index == 0) { allCutPath.emplace_back(singlePath); } if (!node->GetChild().IsNull()) { @@ -205,7 +205,7 @@ int ResultSet::CutJsonBranch(std::string &jsonData) return errCode; } std::vector> allCutPath; - if (context_->viewType_) { + if (context_->viewType) { std::vector singlePath; JsonObject cjsonObjChild = cjsonObj.GetChild(); errCode = CheckCutNode(&cjsonObjChild, singlePath, allCutPath); @@ -214,16 +214,16 @@ int ResultSet::CutJsonBranch(std::string &jsonData) return errCode; } for (auto singleCutPaht : allCutPath) { - if (!context_->ifShowId_ || singleCutPaht[0] != KEY_ID) { + if (!context_->ifShowId || singleCutPaht[0] != KEY_ID) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } } } - if (!context_->viewType_) { - for (auto singleCutPaht : context_->path_) { // projection Path + if (!context_->viewType) { + for (auto singleCutPaht : context_->path) { // projection Path cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } - if (!context_->ifShowId_) { + if (!context_->ifShowId) { std::vector idPath; idPath.emplace_back(KEY_ID); cjsonObj.DeleteItemDeeplyOnTarget(idPath); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index 385e5270..0b5ce84d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -26,7 +26,7 @@ class ValueObject; int InitResultSet(std::shared_ptr context, DocumentStore *store, ResultSet &resultSet, bool ifField) { if (ifField == false) { - if (context->projectionTree_.ParseTree(context->path_) == -E_INVALID_ARGS) { + if (context->projectionTree.ParseTree(context->path) == -E_INVALID_ARGS) { GLOGE("Parse ProjectionTree failed"); return -E_INVALID_ARGS; } -- Gitee From 52f94ecec6f173d753151faa35420fd7bf8b85ac Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 16 May 2023 10:04:32 +0800 Subject: [PATCH 14/17] fix code check Signed-off-by: Jeremyzz --- .../src/interface/include/document_store.h | 10 +++++----- .../gaussdb_rd/src/interface/include/result_set.h | 3 +-- .../src/interface/include/result_set_common.h | 2 +- .../gaussdb_rd/src/interface/src/document_store.cpp | 12 ++++++------ 4 files changed, 13 insertions(+), 14 deletions(-) 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 8843fdd3..cf25d614 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 @@ -67,14 +67,14 @@ public: std::mutex dbMutex_; private: - int UpdateDataIntoDB(std::shared_ptr context, JsonObject &filterObj, const std::string &update, + int UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &update, bool &isReplace); - int UpsertDataIntoDB(std::shared_ptr context, JsonObject &filterObj, JsonObject &documentObj, + int UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, JsonObject &documentObj, bool &isReplace); int InsertDataIntoDB(const std::string &collection, const std::string &document, JsonObject &documentObj); - int DeleteDataFromDB(std::shared_ptr context, JsonObject &filterObj); - int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr context); - int CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, + int DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj); + int InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr &context); + int CheckUpsertConflict(bool &isIdExist, std::shared_ptr &context, JsonObject &filterObj, std::string &docId, Collection &coll); KvStoreExecutor *executor_ = nullptr; std::map collections_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index db57f3cb..23c09204 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -30,8 +30,7 @@ class ResultSet { public: ResultSet(); ~ResultSet(); - int Init(std::shared_ptr context, DocumentStore *store, bool ifField); - int Init(DocumentStore *store, const std::string collectionName, const std::string &filter); + int Init(std::shared_ptr &context, DocumentStore *store, bool ifField); int GetNext(bool isNeedTransaction = false, bool isNeedCheckTable = false); int GetValue(char **value); int GetKey(std::string &key); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h index 189d2243..0a59f9ff 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set_common.h @@ -25,6 +25,6 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(std::shared_ptr context, DocumentStore *store, ResultSet &resultSet, bool ifField); +int InitResultSet(std::shared_ptr &context, DocumentStore *store, ResultSet &resultSet, bool ifField); } // namespace DocumentDB #endif // RESULTSET_COMMON_H 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 73d27068..63738006 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 @@ -176,7 +176,7 @@ int UpdateArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::UpdateDataIntoDB(std::shared_ptr context, JsonObject &filterObj, +int DocumentStore::UpdateDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, const std::string &update, bool &isReplace) { std::lock_guard lock(dbMutex_); @@ -270,7 +270,7 @@ int UpsertArgsCheck(const std::string &collection, const std::string &filter, co return errCode; } -int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, +int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr &context, JsonObject &filterObj, std::string &docId, Collection &coll) { ResultSet resultSet; @@ -290,7 +290,7 @@ int DocumentStore::CheckUpsertConflict(bool &isIdExist, std::shared_ptr context, JsonObject &filterObj, +int DocumentStore::UpsertDataIntoDB(std::shared_ptr &context, JsonObject &filterObj, JsonObject &documentObj, bool &isReplace) { std::lock_guard lock(dbMutex_); @@ -466,7 +466,7 @@ int DeleteArgsCheck(const std::string &collection, const std::string &filter, ui return errCode; } -int DocumentStore::DeleteDataFromDB(std::shared_ptr context, JsonObject &filterObj) +int DocumentStore::DeleteDataFromDB(std::shared_ptr &context, JsonObject &filterObj) { std::lock_guard lock(dbMutex_); if (executor_ == nullptr) { @@ -615,7 +615,7 @@ int FindArgsCheck(const std::string &collection, const std::string &filter, cons return errCode; } -int FindProjectionInit(const std::string &projection, std::shared_ptr context) +int FindProjectionInit(const std::string &projection, std::shared_ptr &context) { int errCode = E_OK; std::vector> allPath; @@ -645,7 +645,7 @@ int FindProjectionInit(const std::string &projection, std::shared_ptr context) +int DocumentStore::InitFindResultSet(GRD_ResultSet *grdResultSet, std::shared_ptr &context) { std::lock_guard lock(dbMutex_); int errCode = E_OK; -- Gitee From e1f1791edfc30af87c4ca7adb890f069cef99fe3 Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 16 May 2023 10:09:33 +0800 Subject: [PATCH 15/17] fix code check Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/interface/src/result_set.cpp | 6 +++--- .../gaussdb_rd/src/interface/src/result_set_common.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 4cad1960..9c65b48e 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 @@ -33,7 +33,7 @@ int ResultSet::EraseCollection() } return E_OK; } -int ResultSet::Init(std::shared_ptr context, DocumentStore *store, bool ifField_) +int ResultSet::Init(std::shared_ptr &context, DocumentStore *store, bool ifField_) { ifField_ = ifField_; context_ = context; @@ -213,14 +213,14 @@ int ResultSet::CutJsonBranch(std::string &jsonData) GLOGE("The node in CheckCutNode is nullptr"); return errCode; } - for (auto singleCutPaht : allCutPath) { + for (const auto & singleCutPaht : allCutPath) { if (!context_->ifShowId || singleCutPaht[0] != KEY_ID) { cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } } } if (!context_->viewType) { - for (auto singleCutPaht : context_->path) { // projection Path + for (const auto & singleCutPaht : context_->path) { // projection Path cjsonObj.DeleteItemDeeplyOnTarget(singleCutPaht); } if (!context_->ifShowId) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp index 0b5ce84d..74b41d0a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set_common.cpp @@ -23,7 +23,7 @@ namespace DocumentDB { class ValueObject; -int InitResultSet(std::shared_ptr context, DocumentStore *store, ResultSet &resultSet, bool ifField) +int InitResultSet(std::shared_ptr &context, DocumentStore *store, ResultSet &resultSet, bool ifField) { if (ifField == false) { if (context->projectionTree.ParseTree(context->path) == -E_INVALID_ARGS) { -- Gitee From 43c2fa33fde3901615837a763feeb598ee575b1d Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Tue, 16 May 2023 14:22:25 +0800 Subject: [PATCH 16/17] fix code check Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/src/interface/src/result_set.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9c65b48e..facfd211 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 @@ -33,9 +33,9 @@ int ResultSet::EraseCollection() } return E_OK; } -int ResultSet::Init(std::shared_ptr &context, DocumentStore *store, bool ifField_) +int ResultSet::Init(std::shared_ptr &context, DocumentStore *store, bool ifField) { - ifField_ = ifField_; + ifField_ = ifField; context_ = context; store_ = store; return E_OK; -- Gitee From 9fc2c3dba54e41acccced201621881033677913a Mon Sep 17 00:00:00 2001 From: Jeremyzz Date: Wed, 17 May 2023 16:52:41 +0800 Subject: [PATCH 17/17] delete weak Signed-off-by: Jeremyzz --- .../data_share/gaussdb_rd/include/grd_base/grd_type_export.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 baa98144..d116ea22 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"), weak)) +#define GRD_API __attribute__((visibility("default"))) #endif typedef struct GRD_DB GRD_DB; -- Gitee