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 d116ea2263c540ea73c159c185bb57c3c1191dec..baa981448cdd3b47203d7e850d561f3a685df7ef 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/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index 61f29c65ee047542ba2292ae4814f50faa230ce6..810bac632da109931a03f5427f5c5e87a5d6f087 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -611,44 +611,11 @@ bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, i bool JsonCommon::IsObjectItemMatch(const JsonObject &srcItem, const JsonObject &item, int &isAlreadyMatched, bool &isCollapse, int &isMatchFlag) { - if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY && item.GetType() == JsonObject::Type::JSON_ARRAY && - !isAlreadyMatched) { - bool isEqual = (srcItem == item); - if (!isEqual) { // Filter value is No equal with src - isMatchFlag = isEqual; - } - isAlreadyMatched = isMatchFlag; - return false; // Both leaf node, no need iterate - } - if (srcItem.GetType() == JsonObject::Type::JSON_LEAF && item.GetType() == JsonObject::Type::JSON_LEAF && - !isAlreadyMatched) { - bool isEqual = isValueEqual(srcItem.GetItemValue(), item.GetItemValue()); - if (!isEqual) { // Filter value is No equal with src - isMatchFlag = isEqual; - } - isAlreadyMatched = isMatchFlag; - return false; // Both leaf node, no need iterate - } else if (srcItem.GetType() != item.GetType()) { - if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { // srcItem Type is ARRAY, item Type is not ARRAY - bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); - if (!isEqual) { - isMatchFlag = isEqual; - } - return true; - } - isMatchFlag = false; - return false; // Different node types, overwrite directly, skip child node - } - return true; // Both array or object -} - -bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, - bool &isCollapse, int &isMatchFlag) -{ - int errCode; - int isAlreadyMatched = 0; + int errCode = E_OK; + // This function has only two error codes, and the other error + // code is not an exception, but the specified node was not found JsonObject srcItem = src.FindItemPowerMode(itemPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && srcItem == item) { + if (errCode == E_OK && srcItem == item) { isMatchFlag = true; isAlreadyMatched = 1; return false; @@ -657,7 +624,7 @@ bool JsonCommon::JsonEqualJudge(const JsonFieldPath &itemPath, const JsonObject std::string lastFieldName = granpaPath.back(); granpaPath.pop_back(); JsonObject granpaItem = src.FindItemPowerMode(granpaPath, errCode); - if (errCode != -E_JSON_PATH_NOT_EXISTS && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { + if (errCode == E_OK && granpaItem.GetType() == JsonObject::Type::JSON_ARRAY && isCollapse) { JsonObject fatherItem = granpaItem.GetChild(); while (!fatherItem.IsNull()) { if ((fatherItem.GetObjectItem(lastFieldName, errCode) == item)) { // this errCode is always E_OK 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 cb1947eb1f12c6eef18f91932c972efe84e85e74..2fb1165786dd77eddc46606cf0c1f16a772eec0c 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 @@ -394,6 +394,43 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri return UpsertDataIntoDB(context, filterObj, documentObj, isReplace); } +int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) +{ + int errCode = E_OK; + errCode = UpsertArgsCheck(collection, filter, document, 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; + } + JsonObject documentObj = JsonObject::Parse(document, errCode, true); + if (errCode != E_OK) { + GLOGE("document Parsed failed"); + return errCode; + } + errCode = UpsertDocumentFormatCheck(document, documentObj); + if (errCode != E_OK) { + GLOGE("document format is illegal"); + return errCode; + } + bool isOnlyId = true; + std::vector> filterAllPath; + errCode = TranFilter(filterObj, filterAllPath, isOnlyId); + if (errCode != E_OK) { + GLOGE("filter is invalid"); + return errCode; + } + 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); + return UpsertDataIntoDB(context, filterObj, documentObj, isReplace); +} + int InsertArgsCheck(const std::string &collection, const std::string &document, uint32_t flags) { if (flags != 0u) { 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 cadbf6703dd67a83f80cb49358665ba025245c0d..b8bb62b1003dc940ade94c1bd97e9cacb6994586 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -88,6 +88,53 @@ int ResultSet::GetNextWithField() return E_OK; } +int ResultSet::GetNextWithField() +{ + int errCode = E_OK; + if (isOnlyId_) { + JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + JsonObject filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); + std::string idKey = idValue.GetStringValue(); + if (idKey.empty()) { + return -E_NO_DATA; + } + Key key(idKey.begin(), idKey.end()); + Value document; + Collection coll = store_->GetCollection(collectionName_); + errCode = coll.GetDocument(key, document); + if (errCode == -E_NOT_FOUND) { + return -E_NO_DATA; + } + std::string jsonData(document.begin(), document.end()); + CutJsonBranch(jsonData); + std::vector> values; + values.emplace_back(std::make_pair(idKey, jsonData)); + matchDatas_ = values; + } else { + Collection coll = store_->GetCollection(collectionName_); + std::vector> values; + JsonObject filterObj = JsonObject::Parse(filter_, errCode, true, true); + if (errCode != E_OK) { + GLOGE("filter Parsed failed"); + return errCode; + } + errCode = coll.GetMatchedDocument(filterObj, values); + if (errCode == -E_NOT_FOUND) { + return -E_NO_DATA; + } + for (size_t i = 0; i < values.size(); i++) { + CutJsonBranch(values[i].second); + } + matchDatas_ = values; + } + return E_OK; +} + int ResultSet::GetNextInner(bool isNeedCheckTable) { int errCode = E_OK;