diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h index 5c464162d0613cffe34289e7d89f3a421a65ef77..02197027a27783bec712d17597567ac8feb9c743 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/include/json_common.h @@ -34,9 +34,10 @@ public: static bool CheckProjectionField(JsonObject &node); static int ParseNode(JsonObject &Node, std::vector singlePath, std::vector> &resultPath, bool isFirstFloor); - static std::vector> ParsePath(const JsonObject &node); + static std::vector> ParsePath(const JsonObject &node, int &errCode); static std::vector GetLeafValue(const JsonObject &node); - static int Append(const JsonObject &src, const JsonObject &add); + static bool isValueEqual(const ValueObject &srcValue, const ValueObject &targetValue); + static int Append(const JsonObject &src, const JsonObject &add, bool isReplace); static bool IsJsonNodeMatch(const JsonObject &src, const JsonObject &target, int &errCode); private: static bool JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, const JsonObject &item, @@ -45,7 +46,7 @@ private: static bool CheckProjectionNode(JsonObject &Node, std::set filedSet, bool &errFlag, bool isFirstFloor); static void CheckLeafNode(const JsonObject &Node, std::vector &leafValue); - static bool IsArrayMathch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); + static bool IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched); }; } // DocumentDB #endif // JSON_COMMON_H \ No newline at end of file diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp index 626216ad8c3f7424deb64cbf1cbdc63517455514..461f2260b675fa66fcbc6bff66c670c8652fe892 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/common/src/json_common.cpp @@ -198,6 +198,9 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, tempParseName = tempParseName + priFieldName[j]; } if (priFieldName[j] == '.' || j == priFieldName.size() - 1) { + if (j > 0 && priFieldName[j] == '.' && priFieldName[j - 1] == '.') { + return -E_INVALID_ARGS; + } allFiledsName.emplace_back(tempParseName); tempParseName.clear(); } @@ -220,10 +223,10 @@ int JsonCommon::ParseNode(JsonObject &node, std::vector singlePath, auto nodeNew = node.GetNext(); ParseNode(nodeNew, fatherPath, resultPath, isFirstFloor); } - return 0; + return E_OK; } -std::vector> JsonCommon::ParsePath(const JsonObject &root) +std::vector> JsonCommon::ParsePath(const JsonObject &root, int &errCode) { std::vector> resultPath; auto projectionJson = root.GetChild(); @@ -231,7 +234,7 @@ std::vector> JsonCommon::ParsePath(const JsonObject &ro GLOGE("projectionJson is null"); } std::vector singlePath; - ParseNode(projectionJson, singlePath, resultPath, true); + errCode = ParseNode(projectionJson, singlePath, resultPath, true); return resultPath; } @@ -256,6 +259,26 @@ JsonFieldPath SplitePath(const JsonFieldPath &path, bool &isCollapse) return splitPath; } +JsonFieldPath ExpendPathForField(const JsonFieldPath &path, bool &isCollapse) +{ + JsonFieldPath splitPath; + const std::string &str = path.back(); + size_t start = 0; + size_t end = 0; + while ((end = str.find('.', start)) != std::string::npos) { + splitPath.push_back(str.substr(start, end - start)); + start = end + 1; + } + if (start < str.length()) { + splitPath.push_back(str.substr(start)); + } + isCollapse = (splitPath.size() > 1); + for (int i = 1; i < path.size(); i++) { + splitPath.emplace_back(path[i]); + } + return splitPath; +} + void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, std::function AppendFoo) { @@ -285,15 +308,179 @@ void JsonObjectIterator(const JsonObject &obj, JsonFieldPath path, } return; } + +bool IsNumber(const std::string &str) +{ + return std::all_of(str.begin(), str.end(), [](char c) { + return std::isdigit(c); + }); +} + +bool AddSpliteFiled(const JsonObject &src, const JsonObject &item, const JsonFieldPath &itemPath, int &externErrCode) +{ + int errCode = 0; + JsonFieldPath abandonPath; + JsonFieldPath hitPath = itemPath; + while (!hitPath.empty()) { + JsonObject srcFatherItem = src.FindItem(hitPath, errCode); + abandonPath.emplace_back(hitPath.back()); + if (!srcFatherItem.IsNull()) { + break; + } + hitPath.pop_back(); + } + if (!hitPath.empty()) { + JsonFieldPath preHitPath = hitPath; + preHitPath.pop_back(); + JsonObject preHitItem = src.FindItem(preHitPath, errCode); + JsonObject hitItem = preHitItem.GetObjectItem(hitPath.back(), errCode); + if (!abandonPath.empty()) { + abandonPath.pop_back(); + } + if (!hitItem.IsNull()) { + JsonFieldPath newHitPath; + for (int i = abandonPath.size() - 1; i > -1; i--) { + if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { + GLOGE("Add collapse item to object failed, path not exist."); + externErrCode = -E_DATA_CONFLICT; + return false; + } + if (IsNumber(abandonPath[i])) { + externErrCode = -E_DATA_CONFLICT; + return false; + } + (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) : + errCode = hitItem.AddItemToObject(abandonPath[i]); + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + newHitPath.emplace_back(abandonPath[i]); + hitItem = hitItem.FindItem(newHitPath, errCode); + newHitPath.pop_back(); + } + return false; + } + } + JsonObject hitItem = src.FindItem(hitPath, errCode); + JsonFieldPath newHitPath; + for (int i = abandonPath.size() - 1; i > -1; i--) { + if (hitItem.GetType() != JsonObject::Type::JSON_OBJECT) { + GLOGE("Add collapse item to object failed, path not exist."); + externErrCode = -E_DATA_CONFLICT; + return false; + } + if (IsNumber(abandonPath[i])) { + externErrCode = -E_DATA_CONFLICT; + return false; + } + (i == 0) ? errCode = hitItem.AddItemToObject(abandonPath[i], item) : + errCode = hitItem.AddItemToObject(abandonPath[i]); + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + newHitPath.emplace_back(abandonPath[i]); + hitItem = hitItem.FindItem(newHitPath, errCode); + newHitPath.pop_back(); + } + return false; +} + +bool JsonValueReplace(const JsonObject &src, const JsonFieldPath &fatherPath, const JsonObject &father, + const JsonObject &item, int &externErrCode) +{ + int errCode = 0; + JsonFieldPath granPaPath = fatherPath; + if (!granPaPath.empty()) { + granPaPath.pop_back(); + JsonObject fatherItem = src.FindItem(granPaPath, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + fatherItem.ReplaceItemInObject(item.GetItemFiled().c_str(), item, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + } else { + JsonObject fatherItem = src.FindItem(fatherPath, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + if (father.GetChild().IsNull()) { + externErrCode = -E_NO_DATA; + GLOGE("Replace falied, no data match"); + return false; + } + if (!item.GetItemFiled(errCode).empty()) { + fatherItem.ReplaceItemInObject(item.GetItemFiled().c_str(), item, errCode); + if (errCode != E_OK) { + return false; + } + } + } + return true; +} + +bool JsonNodeReplace(const JsonObject &src, const JsonFieldPath &itemPath, const JsonObject &father, + const JsonObject &item, int &externErrCode) +{ + int errCode = 0; + JsonFieldPath fatherPath = itemPath; + fatherPath.pop_back(); + if (!fatherPath.empty()) { + JsonObject fatherItem = src.FindItem(fatherPath, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + if (fatherItem.GetType() == JsonObject::Type::JSON_ARRAY && IsNumber(itemPath.back())) { + fatherItem.ReplaceItemInArray(std::stoi(itemPath.back()), item, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + } + return false; + } + fatherItem.ReplaceItemInObject(itemPath.back().c_str(), item, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + } else { + JsonObject fatherItem = src.FindItem(fatherPath, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + if (father.GetChild().IsNull()) { + externErrCode = -E_NO_DATA; + GLOGE("Replace falied, no data match"); + return false; + } + fatherItem.ReplaceItemInObject(itemPath.back().c_str(), item, errCode); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Find father item in source json object failed. %d", errCode); + return false; + } + } + return true; +} } -int JsonCommon::Append(const JsonObject &src, const JsonObject &add) +int JsonCommon::Append(const JsonObject &src, const JsonObject &add, bool isReplace) { int externErrCode = E_OK; + bool isAddedFlag = false; JsonObjectIterator(add, {}, - [&src, &externErrCode](const JsonFieldPath &path, const JsonObject &father, const JsonObject &item) { + [&src, &externErrCode, &isReplace, &isAddedFlag](const JsonFieldPath &path, + const JsonObject &father, const JsonObject &item) { bool isCollapse = false; - JsonFieldPath itemPath = SplitePath(path, isCollapse); + JsonFieldPath itemPath = ExpendPathForField(path, isCollapse); JsonFieldPath fatherPath = itemPath; fatherPath.pop_back(); int errCode = E_OK; @@ -304,38 +491,49 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add) GLOGE("Find item in source json object failed. %d", errCode); return false; } - if (srcItem.GetType() == JsonObject::Type::JSON_LEAF && item.GetType() == JsonObject::Type::JSON_LEAF) { - srcItem.SetItemValue(item.GetItemValue()); - return false; // Both leaf node, no need iterate - } else if (srcItem.GetType() != item.GetType()) { - JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); - if (errCode != E_OK) { - externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - GLOGE("Find father item in source json object failed. %d", errCode); - return false; - } - srcFatherItem.DeleteItemFromObject(itemPath.back()); - srcFatherItem.AddItemToObject(itemPath.back(), item); - return false; // Different node types, overwrite directly, skip child node + bool ret = JsonNodeReplace (src, itemPath, father, item, externErrCode); + if (!ret) { + return false; } - return true; // Both array or object + isAddedFlag = true; + return false; } else { - if (isCollapse) { - GLOGE("Add collapse item to object failed, path not exist."); - externErrCode = -E_DATA_CONFLICT; + if (isReplace) { + GLOGE("path not exist, replace failed"); + externErrCode = -E_NO_DATA; return false; } JsonObject srcFatherItem = src.FindItem(fatherPath, errCode); + std::string lastFieldName = itemPath.back(); + if (srcFatherItem.IsNull()) { + isAddedFlag = true; + AddSpliteFiled(src, item, itemPath, externErrCode); + return false; + } if (errCode == E_OK) { - errCode = srcFatherItem.AddItemToObject(itemPath.back(), item); - if (errCode != E_OK) { - externErrCode = (externErrCode == E_OK ? errCode : externErrCode); - GLOGE("Add item to object failed. %d", errCode); + if (isCollapse) { + errCode = srcFatherItem.AddItemToObject(itemPath.back(), item); + if (errCode != E_OK) { + externErrCode = (externErrCode == E_OK ? errCode : externErrCode); + GLOGE("Add item to object failed. %d", errCode); + return false; + } + isAddedFlag = true; return false; } - } else { + if (!isCollapse) { + bool ret = JsonValueReplace(src, fatherPath, father, item, externErrCode); + if (!ret) { + GLOGE("replace faild"); + return false; + } + isAddedFlag = true; + return false; // Different node types, overwrite directly, skip child node + } + } + if (!isAddedFlag) { + GLOGE("Add nothing because data conflict"); externErrCode = -E_DATA_CONFLICT; - GLOGE("Find father item in source json object failed. %d", errCode); } return false; // Source path not exist, overwrite directly, skip child node } @@ -343,7 +541,24 @@ int JsonCommon::Append(const JsonObject &src, const JsonObject &add) return externErrCode; } -bool JsonCommon::IsArrayMathch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched) +bool JsonCommon::isValueEqual(const ValueObject &srcValue, const ValueObject &targetValue) +{ + if (srcValue.GetValueType() == targetValue.GetValueType()) { + switch (srcValue.GetValueType()) { + case ValueObject::ValueType::VALUE_NULL: + return true; + case ValueObject::ValueType::VALUE_BOOL: + return srcValue.GetBoolValue() == targetValue.GetBoolValue() ? true : false; + case ValueObject::ValueType::VALUE_NUMBER: + return srcValue.GetDoubleValue() == targetValue.GetDoubleValue() ? true : false; + case ValueObject::ValueType::VALUE_STRING: + return srcValue.GetStringValue() == targetValue.GetStringValue() ? true : false; + } + } + return false; +} + +bool JsonCommon::IsArrayMatch(const JsonObject &src, const JsonObject &target, int &isAlreadyMatched) { JsonObject srcChild = src.GetChild(); JsonObject targetObj = target; @@ -398,7 +613,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, } if (srcItem.GetType() == JsonObject::Type::JSON_LEAF && item.GetType() == JsonObject::Type::JSON_LEAF && !isAlreadyMatched) { - bool isEqual = (srcItem.GetItemValue() == item.GetItemValue()); + bool isEqual = isValueEqual(srcItem.GetItemValue(), item.GetItemValue()); if (!isEqual) { GLOGI("Filter value is No equal with src"); isMatchFlag = isEqual; @@ -408,7 +623,7 @@ bool JsonCommon::JsonEqualJudge(JsonFieldPath &itemPath, const JsonObject &src, } else if (srcItem.GetType() != item.GetType()) { if (srcItem.GetType() == JsonObject::Type::JSON_ARRAY) { GLOGI("srcItem Type is ARRAY, item Type is not ARRAY"); - bool isEqual = IsArrayMathch(srcItem, item, isAlreadyMatched); + bool isEqual = IsArrayMatch(srcItem, item, isAlreadyMatched); if (!isEqual) { isMatchFlag = isEqual; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp index 071591b8c314499eb73cbe1068224ba0d61932b0..bc88d8796229b67f6ac181a742216337556c5a26 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.cpp @@ -127,6 +127,66 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< return E_OK; } +bool CheckCommon::CheckFilter(const std::string &filter, std::string &idStr, int &errCode) +{ + if (filter.empty()) { + errCode = -E_INVALID_ARGS; + GLOGE("Check filter invalid. %d", errCode); + return false; + } + + JsonObject filterObject = JsonObject::Parse(filter, errCode, true); + if (errCode != E_OK) { + GLOGE("Parse filter failed. %d", errCode); + return false; + } + + JsonObject filterId = filterObject.GetObjectItem("_id", errCode); + if (errCode != E_OK || filterId.GetItemValue().GetValueType() != ValueObject::ValueType::VALUE_STRING) { + GLOGE("Check filter '_id' not found or type not string."); + errCode = -E_INVALID_ARGS; + return false; + } + + idStr = filterId.GetItemValue().GetStringValue(); + return true; +} + +bool CheckCommon::CheckDocument(const std::string &updateStr, int &errCode) +{ + if (updateStr.empty()) { + errCode = -E_INVALID_ARGS; + return false; + } + + JsonObject updateObj = JsonObject::Parse(updateStr, errCode); + if (updateObj.IsNull() || errCode != E_OK) { + GLOGE("Parse update document failed. %d", errCode); + return false; + } + std::vector> updatePath; + updatePath = JsonCommon::ParsePath(updateObj, errCode); + if (errCode != E_OK) { + return false; + } + for (auto singlePath : updatePath) { + if (singlePath.size() > JSON_DEEP_MAX) { + GLOGE("filter's json deep is deeper than JSON_DEEP_MAX"); + errCode = -E_INVALID_ARGS; + return false; + } + } + + JsonObject filterId = updateObj.GetObjectItem("_id", errCode); + if (errCode != -E_NOT_FOUND) { + GLOGE("Can not change '_id' with update document failed."); + errCode = -E_INVALID_ARGS; + return false; + } + + return true; +} + int CheckCommon::CheckIdFormat(JsonObject &filterJson) { auto filterObjChild = filterJson.GetChild(); @@ -177,6 +237,37 @@ int CheckCommon::CheckDocument(JsonObject &documentObj) return E_OK; } +bool CheckCommon::CheckUpdata(JsonObject &updataObj, std::vector> &path) +{ + if (updataObj.GetDeep() > JSON_DEEP_MAX) { + GLOGE("projectionObj's json deep is deeper than JSON_DEEP_MAX"); + return -E_INVALID_ARGS; + } + for (int i = 0; i < path.size(); i++) { + for (int j = 0; j < path[i].size(); j++) { + for (auto oneChar : path[i][j]) { + if (!((isalpha(oneChar)) || (isdigit(oneChar)) || ('_' == oneChar))) { + return false; + } + } + } + if (!path[i].empty() && !path[i][0].empty() && isdigit(path[i][0][0])) { + return false; + } + } + for (auto singlePath: path) { + if (singlePath.size() > JSON_DEEP_MAX) { + return false; + } + } + bool isIdExist = true; + CheckIdFormat(updataObj, isIdExist); + if (isIdExist) { + return false; + } + return true; +} + bool CheckCommon::CheckProjection(JsonObject &projectionObj, std::vector> &path) { if (projectionObj.GetDeep() > JSON_DEEP_MAX) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h index eaf089bf77dd93ee2ff42ecdba7798bb4403d040..46c9f7f3f25ea5541c3c5f241fb99ef8b1ac4d9b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/document_check.h @@ -30,9 +30,12 @@ public: static bool CheckCollectionName(const std::string &collectionName, std::string &lowerCaseName, int &errCode); static int CheckFilter(JsonObject &document); static int CheckFilter(JsonObject &document, bool &isOnlyId, std::vector> &filterPath); + static bool CheckFilter(const std::string &filter, std::string &idStr, int &errCode); static int CheckIdFormat(JsonObject &data); static int CheckIdFormat(JsonObject &data, bool &isIdExisit); static int CheckDocument(JsonObject &document); + static bool CheckUpdata(JsonObject &updata, std::vector> &path); + static bool CheckDocument(const std::string &updateStr, int &errCode); static bool CheckProjection(JsonObject &projectionObj, std::vector> &path); }; using Key = std::vector; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp index c19584c0cef76652632f87ad802472f1e82c053d..216facd921e9b3111f9c9b9584cfa3f718495c28 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/document/grd_document_api.cpp @@ -45,27 +45,30 @@ int GRD_DropCollection(GRD_DB *db, const char *collectionName, unsigned int flag int GRD_UpdateDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *update, unsigned int flags) { - if (db == nullptr || db->store_ == nullptr) { + if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || filter == nullptr || update == nullptr) { return GRD_INVALID_ARGS; } - - std::string name = (collectionName == nullptr ? "" : collectionName); - std::string filterStr = (filter == nullptr ? "" : filter); - std::string updateStr = (update == nullptr ? "" : update); - int ret = db->store_->UpdateDocument(name, filterStr, updateStr, flags); + int ret = db->store_->UpdateDocument(collectionName, filter, update, flags); + if (ret == 1) { + return 1; // The amount of text updated + } else if (ret == 0) { + return 0; + } return TrasnferDocErr(ret); } int GRD_UpsertDoc(GRD_DB *db, const char *collectionName, const char *filter, const char *document, unsigned int flags) { - if (db == nullptr || db->store_ == nullptr) { + if (db == nullptr || db->store_ == nullptr || collectionName == nullptr || filter == nullptr || + document == nullptr) { return GRD_INVALID_ARGS; } - - std::string name = (collectionName == nullptr ? "" : collectionName); - std::string filterStr = (filter == nullptr ? "" : filter); - std::string documentStr = (document == nullptr ? "" : document); - int ret = db->store_->UpsertDocument(name, filterStr, documentStr, flags); + int ret = db->store_->UpsertDocument(collectionName, filter, document, flags); + if (ret == 1) { + return 1; // The amount of text updated + } else if (ret == 0) { + return 0; + } return TrasnferDocErr(ret); } @@ -109,6 +112,9 @@ int GRD_FindDoc(GRD_DB *db, const char *collectionName, Query query, unsigned in || query.projection == nullptr) { return GRD_INVALID_ARGS; } + if (db->store_->IsCollectionOpening(collectionName)) { + return GRD_RESOURCE_BUSY; + } GRD_ResultSet *grdResultSet = new (std::nothrow)GRD_ResultSet(); if (grdResultSet == nullptr) { GLOGE("Memory allocation failed!"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h index 06e7bbeea54dae8f45f6899cac23bb9d0e5c92dc..9c5576697e75459ba868b99cd39c7823b34fc15f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/executor/include/grd_format_config.h @@ -22,7 +22,7 @@ extern "C" { #endif // __cplusplus #define COLLECTION_LENS_MAX (512 * 1024) -#define JSON_LENS_MAX (512 * 1024) +#define JSON_LENS_MAX (1024 * 1024) #define JSON_DEEP_MAX (4) #define KEY_ID ("_id") diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h index 387ec5b4e1537e412db214a1f607a55da6d37b88..194af3d3b1770fa445bf11e5456da3b083f8a998 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/collection.h @@ -35,7 +35,7 @@ public: int IsCollectionExists(int &errCode); int UpsertDocument(const std::string &id, const std::string &document, bool isReplace = true); bool FindDocument(); - int UpdateDocument(const std::string &id, const std::string &document); + int UpdateDocument(const std::string &id, const std::string &document, bool isReplace = false); private: std::string name_; KvStoreExecutor *executor_ = nullptr; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h index 6f159683b4aa4939307949173f8e37a83b1e4e37..24eea19a707955af8eb2ca86a05c4393f3dc0e20 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/doc_errno.h @@ -33,7 +33,7 @@ constexpr int E_COLLECTION_CONFLICT = E_BASE + 15; constexpr int E_NO_DATA = E_BASE + 16; constexpr int E_NOT_PERMIT = E_BASE + 17; constexpr int E_DATA_CONFLICT = E_BASE + 18; -constexpr int E_INVALID_COLL_NAME_FORMAT = E_BASE + 18; +constexpr int E_INVALID_COLL_NAME_FORMAT = E_BASE + 19; constexpr int E_INVALID_JSON_FORMAT = E_BASE + 40; constexpr int E_JSON_PATH_NOT_EXISTS = E_BASE + 41; constexpr int E_RESOURCE_BUSY = E_BASE + 50; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h index d01360a1175b56c8e23563d592fa6d7cf6867b6b..7f1da94fbee6d5d9bcb974fa70cdc1c3ece06535 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/include/document_store.h @@ -41,6 +41,7 @@ public: int FindDocument(const std::string &collection, const std::string &filter, const std::string &projection, int flags, GRD_ResultSet *grdResultSet); KvStoreExecutor *GetExecutor(int errCode); + bool IsCollectionOpening(const std::string collection); int EraseCollection(const std::string collectionName); private: int GetViewType(JsonObject &jsonObj, bool &viewType); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp index 8c6d7970cf3449db99247ffe3d843275832b85ba..6d22b01066f169e18d5bfbe60b5d0d9bef4e1c2b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/collection.cpp @@ -22,6 +22,8 @@ #include "log_print.h" namespace DocumentDB { +const int JSON_LENS_MAX = 1024 * 1024; + Collection::Collection(const std::string &name, KvStoreExecutor *executor) : executor_(executor) { std::string lowerCaseName = name; @@ -88,7 +90,6 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen if (executor_ == nullptr) { return -E_INVALID_ARGS; } - int errCode = E_OK; bool isCollExist = executor_->IsCollectionExists(name_, errCode); if (errCode != E_OK) { @@ -100,7 +101,7 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen return -E_NO_DATA; } - JsonObject upsertValue = JsonObject::Parse(document, errCode); + JsonObject upsertValue = JsonObject::Parse(document, errCode, true); if (errCode != E_OK) { GLOGD("Parse upsert value failed. %d", errCode); return errCode; @@ -108,38 +109,39 @@ int Collection::UpsertDocument(const std::string &id, const std::string &documen Key keyId(id.begin(), id.end()); Value valSet(document.begin(), document.end()); - if (!isReplace) { Value valueGot; errCode = executor_->GetData(name_, keyId, valueGot); std::string valueGotStr = std::string(valueGot.begin(), valueGot.end()); - if (errCode != E_OK && errCode != -E_NOT_FOUND) { - GLOGE("Get original document failed. %d", errCode); + GLOGW("Get original document failed. %d", errCode); return errCode; } else if (errCode == E_OK) { // document has been inserted GLOGD("Document has been inserted, append value."); - JsonObject originValue = JsonObject::Parse(valueGotStr, errCode); + JsonObject originValue = JsonObject::Parse(valueGotStr, errCode, true); if (errCode != E_OK) { GLOGD("Parse original value failed. %d %s", errCode, valueGotStr.c_str()); return errCode; } - errCode = JsonCommon::Append(originValue, upsertValue); + errCode = JsonCommon::Append(originValue, upsertValue, isReplace); if (errCode != E_OK) { 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"); + return -E_OVER_LIMIT; + } valSet = {valStr.begin(), valStr.end()}; } } - return executor_->PutData(name_, keyId, valSet); } -int Collection::UpdateDocument(const std::string &id, const std::string &update) +int Collection::UpdateDocument(const std::string &id, const std::string &update, bool isReplace) { if (executor_ == nullptr) { return -E_INVALID_ARGS; @@ -173,21 +175,22 @@ int Collection::UpdateDocument(const std::string &id, const std::string &update) GLOGE("Get original document failed. %d", errCode); return errCode; } - GLOGD("Update document value."); JsonObject originValue = JsonObject::Parse(valueGotStr, errCode); if (errCode != E_OK) { GLOGD("Parse original value failed. %d %s", errCode, valueGotStr.c_str()); return errCode; } - - errCode = JsonCommon::Append(originValue, updateValue); + errCode = JsonCommon::Append(originValue, updateValue, isReplace); if (errCode != E_OK) { GLOGD("Append value failed. %d", errCode); return errCode; } - std::string valStr = originValue.Print(); + if (valStr.length() + 1 > JSON_LENS_MAX) { + GLOGE("document's length is too long"); + return -E_OVER_LIMIT; + } Value valSet(valStr.begin(), valStr.end()); return executor_->PutData(name_, keyId, valSet); } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp index 8a1a6f3bb9369ec7a663596d4f1c5522cbd1547d..c15cc0c11b403629b5ffd3a97dd0935ae6468485 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/doc_errno.cpp @@ -53,6 +53,9 @@ int TrasnferDocErr(int err) case -E_INVALID_CONFIG_VALUE: outErr = GRD_INVALID_CONFIG_VALUE; break; + case -E_DATA_CONFLICT: + outErr = GRD_DATA_CONFLICT; + break; case -E_COLLECTION_CONFLICT: outErr = GRD_COLLECTION_CONFLICT; break; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp index 6d252f108ef454bbd062c0e8436bcf93a8499b6f..0638c2477916638a4a147ad4d14fcf92e739233b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/interface/src/document_store.cpp @@ -23,7 +23,9 @@ #include "grd_resultset_inner.h" namespace DocumentDB { -const int JSON_LENS_MAX = 512 * 1024; +const int COLLECTION_LENS_MAX = 512 * 1024; +const int JSON_LENS_MAX = 1024 * 1024; +const int JSON_DEEP_MAX = 4; constexpr const char *KEY_ID = "_id"; const bool caseSensitive = true; @@ -111,55 +113,6 @@ int DocumentStore::DropCollection(const std::string &name, int flags) return E_OK; } -namespace { -bool CheckFilter(const std::string &filter, std::string &idStr, int &errCode) -{ - if (filter.empty()) { - errCode = -E_INVALID_ARGS; - GLOGE("Check filter invalid. %d", errCode); - return false; - } - - JsonObject filterObject = JsonObject::Parse(filter, errCode, true); - if (errCode != E_OK) { - GLOGE("Parse filter failed. %d", errCode); - return false; - } - - JsonObject filterId = filterObject.GetObjectItem("_id", errCode); - if (errCode != E_OK || filterId.GetItemValue().GetValueType() != ValueObject::ValueType::VALUE_STRING) { - GLOGE("Check filter '_id' not found or type not string."); - errCode = -E_INVALID_ARGS; - return false; - } - - idStr = filterId.GetItemValue().GetStringValue(); - return true; -} - -bool CheckDocument(const std::string &updateStr, int &errCode) -{ - if (updateStr.empty()) { - errCode = -E_INVALID_ARGS; - return false; - } - - JsonObject updateObj = JsonObject::Parse(updateStr, errCode); - if (updateObj.IsNull() || errCode != E_OK) { - GLOGE("Parse update document failed. %d", errCode); - return false; - } - - JsonObject filterId = updateObj.GetObjectItem("_id", errCode); - if (errCode != -E_NOT_FOUND) { - GLOGE("Can not change '_id' with update document failed."); - return false; - } - - return true; -} -} - int DocumentStore::UpdateDocument(const std::string &collection, const std::string &filter, const std::string &update, int flags) { @@ -169,28 +122,70 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri GLOGE("Check collection name invalid. %d", errCode); return errCode; } - - std::string idStr; - if (!CheckFilter(filter, idStr, errCode)) { - GLOGE("Check update filter failed. %d", errCode); + JsonObject updateObj = JsonObject::Parse(update, errCode, true); + if (errCode != E_OK) { + GLOGE("update Parsed faild"); return errCode; } - - if (!CheckDocument(update, errCode)) { - GLOGE("Check update document failed. %d", errCode); - return errCode; + std::vector> allPath; + if (update != "{}") { + allPath = JsonCommon::ParsePath(updateObj, errCode); + if (errCode != E_OK) { + GLOGE("updateObj ParsePath faild"); + return errCode; + } + if (!CheckCommon::CheckUpdata(updateObj, allPath)) { + GLOGE("Updata format unvalid"); + return -E_INVALID_ARGS; + } } - - if (flags != 0) { + if (flags != GRD_DOC_APPEND && flags != GRD_DOC_REPLACE) { GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - - std::string docId(idStr.begin(), idStr.end()); - + JsonObject filterObj = JsonObject::Parse(filter, errCode, caseSensitive); + if (errCode != E_OK) { + GLOGE("filter Parsed faild"); + return errCode; + } + std::vector> filterAllPath; + filterAllPath = JsonCommon::ParsePath(filterObj, errCode); + if (errCode != E_OK) { + GLOGE("filter ParsePath faild"); + return errCode; + } + bool isOnlyId = true; + auto coll = Collection(collection, executor_); + errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); + if (errCode != E_OK) { + return errCode; + } + bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); + if (isOnlyId) { + auto filterObjChild = filterObj.GetChild(); + auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + std::string docId = idValue.GetStringValue(); + std::lock_guard lock(dbMutex_); + errCode = coll.UpdateDocument(docId, update, isReplace); + if (errCode == E_OK) { + errCode = 1; // upsert one record. + } else if (errCode == -E_NOT_FOUND) { + errCode = E_OK; + } + return errCode; + } + ResultSet resultSet; + InitResultSet(this, collection, filter, resultSet); std::lock_guard lock(dbMutex_); - auto coll = Collection(lowerCaseCollName, executor_); - errCode = coll.UpdateDocument(docId, update); + errCode = resultSet.GetNext(); + if (errCode == -E_NO_DATA) { + return 0; // The amount of text updated + } else if (errCode != E_OK) { + return errCode; + } + std::string docId; + resultSet.GetKey(docId); + errCode = coll.UpdateDocument(docId, update, isReplace); if (errCode == E_OK) { errCode = 1; // update one record. } else if (errCode == -E_NOT_FOUND) { @@ -208,31 +203,73 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri GLOGE("Check collection name invalid. %d", errCode); return errCode; } - - std::string idStr; - if (!CheckFilter(filter, idStr, errCode)) { - GLOGE("Check upsert filter failed. %d", errCode); + JsonObject documentObj = JsonObject::Parse(document, errCode, true); + if (errCode != E_OK) { + GLOGE("document Parsed faild"); return errCode; } - - if (!CheckDocument(document, errCode)) { - GLOGE("Check upsert document failed. %d", errCode); - return errCode; + std::vector> allPath; + if (document != "{}") { + allPath = JsonCommon::ParsePath(documentObj, errCode); + if (errCode != E_OK) { + return errCode; + } + if (!CheckCommon::CheckUpdata(documentObj, allPath)) { + GLOGE("updata format unvalid"); + return -E_INVALID_ARGS; + } } - if (flags != GRD_DOC_APPEND && flags != GRD_DOC_REPLACE) { GLOGE("Check flags invalid."); return -E_INVALID_ARGS; } - - std::string docId(idStr.begin(), idStr.end()); + JsonObject filterObj = JsonObject::Parse(filter, errCode, caseSensitive); + if (errCode != E_OK) { + GLOGE("filter Parsed faild"); + return errCode; + } + std::vector> filterAllPath; + filterAllPath = JsonCommon::ParsePath(filterObj, errCode); + if (errCode != E_OK) { + return errCode; + } + bool isOnlyId = true; bool isReplace = ((flags & GRD_DOC_REPLACE) == GRD_DOC_REPLACE); - + auto coll = Collection(collection, executor_); + errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); + if (errCode != E_OK) { + return errCode; + } + if (isOnlyId) { + std::lock_guard lock(dbMutex_); + auto filterObjChild = filterObj.GetChild(); + ValueObject idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID); + std::string docId = idValue.GetStringValue(); + JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); + documentObj.InsertItemObject(0, idObj); + std::string addedIdDocument = documentObj.Print(); + errCode = coll.UpsertDocument(docId, addedIdDocument, isReplace); + if (errCode == E_OK) { + errCode = 1; // upsert one record. + } + return errCode; + } + bool isIdExist; + auto filterObjChild = filterObj.GetChild(); + auto idValue = JsonCommon::GetValueByFiled(filterObjChild, KEY_ID, isIdExist); + if (!isIdExist) { + return -E_INVALID_ARGS; + } std::lock_guard lock(dbMutex_); - auto coll = Collection(lowerCaseCollName, executor_); - errCode = coll.UpsertDocument(docId, document, isReplace); + std::string docId = idValue.GetStringValue(); + JsonObject idObj = filterObj.GetObjectItem(KEY_ID, errCode); + documentObj.InsertItemObject(0, idObj); + std::string addedIdDocument = documentObj.Print(); + errCode = coll.UpsertDocument(docId, addedIdDocument, isReplace); if (errCode == E_OK) { errCode = 1; // upsert one record. + } else if (errCode == -E_NOT_FOUND) { + errCode = E_OK; } return errCode; } @@ -302,7 +339,10 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj); + filterAllPath = JsonCommon::ParsePath(filterObj, errCode); + if (errCode != E_OK) { + return errCode; + } bool isOnlyId = true; errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { @@ -355,7 +395,10 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string return errCode; } std::vector> filterAllPath; - filterAllPath = JsonCommon::ParsePath(filterObj); + filterAllPath = JsonCommon::ParsePath(filterObj, errCode); + if (errCode != E_OK) { + return errCode; + } bool isOnlyId = true; errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { @@ -373,7 +416,10 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string bool viewType = false; std::vector> allPath; if (projection != "{}") { - allPath = JsonCommon::ParsePath(projectionObj); + allPath = JsonCommon::ParsePath(projectionObj, errCode); + if (errCode != E_OK) { + return errCode; + } if (!CheckCommon::CheckProjection(projectionObj, allPath)) { GLOGE("projection format unvalid"); return -E_INVALID_ARGS; @@ -387,10 +433,6 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string if (flags == GRD_DOC_ID_DISPLAY) { ifShowId = true; } - if (collections_.find(collection) != collections_.end()) { - GLOGE("DB is resource busy"); - return -E_RESOURCE_BUSY; - } auto coll = Collection(collection, executor_); std::lock_guard lock(dbMutex_); if (!coll.FindDocument()) { @@ -406,6 +448,14 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string } return ret; } + +bool DocumentStore::IsCollectionOpening(const std::string collection) { + if (collections_.find(collection) != collections_.end()) { + GLOGE("DB is resource busy"); + return true; + } + return false; +} int DocumentStore::EraseCollection(const std::string collectionName) { if (collections_.find(collectionName) != collections_.end()) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h index cdaefb875e75e60b2e77ca23ad6db58ca4935856..bde5710410ec74d947292b2c887770b2250b738d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/include/json_object.h @@ -74,9 +74,13 @@ public: int DeleteItemFromObject(const std::string &field); int AddItemToObject(const JsonObject &item); int AddItemToObject(const std::string &fieldName, const JsonObject &item); + int AddItemToObject(const std::string &fieldName); ValueObject GetItemValue() const; + void ReplaceItemInArray(const int &index, const JsonObject &newItem, int &errCode); + void ReplaceItemInObject(const std::string &filedName, const JsonObject &newItem, int &errCode); void SetItemValue(const ValueObject &value) const; + int InsertItemObject(int which, const JsonObject &newItem); std::string GetItemFiled() const; std::string GetItemFiled(int &errCode) const; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp index 0c3de7c99020dd0d56e841856e4c84aef1c1b752..1c883fd544af0572066525fbe992c8e8a42d2321 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/json_object.cpp @@ -21,6 +21,9 @@ namespace DocumentDB { namespace { +const int COLLECTION_LENS_MAX = 512 * 1024; +const int JSON_LENS_MAX = 1024 * 1024; + bool IsNumber(const std::string &str) { return std::all_of(str.begin(), str.end(), [](char c) { @@ -318,20 +321,47 @@ int JsonObject::AddItemToObject(const std::string &fieldName, const JsonObject & } if (IsNumber(fieldName) && n <= std::stoi(fieldName)) { GLOGE("Add item object to array over size."); - return -E_DATA_CONFLICT; + return -E_NO_DATA; } } + if (cjson_->type != cJSON_Object) { + GLOGE("type conflict."); + return -E_DATA_CONFLICT; + } cJSON *cpoyItem = cJSON_Duplicate(item.cjson_, true); cJSON_AddItemToObject(cjson_, fieldName.c_str(), cpoyItem); return E_OK; } +int JsonObject::AddItemToObject(const std::string &fieldName) +{ + // TODO: check item exist + if (cjson_->type == cJSON_Array) { + int n = 0; + cJSON *child = cjson_->child; + while (child != nullptr) { + child = child->next; + n++; + } + if (IsNumber(fieldName) && n <= std::stoi(fieldName)) { + GLOGE("Add item object to array over size."); + return -E_NO_DATA; + } + } + if (cjson_->type != cJSON_Object) { + GLOGE("type conflict."); + return -E_DATA_CONFLICT; + } + cJSON *emptyitem = cJSON_CreateObject(); + cJSON_AddItemToObject(cjson_, fieldName.c_str(), emptyitem); + return E_OK; +} + ValueObject JsonObject::GetItemValue() const { if (cjson_ == nullptr) { return ValueObject(); } - ValueObject value; switch (cjson_->type) { case cJSON_False: @@ -353,6 +383,31 @@ ValueObject JsonObject::GetItemValue() const return value; } +void JsonObject::ReplaceItemInObject(const std::string &filedName, const JsonObject &newItem, int &errCode) +{ + if (!newItem.IsNull() || !this->IsNull()) { + if (this->GetType() == JsonObject::Type::JSON_OBJECT) { + if (!(this->GetObjectItem(filedName.c_str(), errCode).IsNull())) { + cJSON *copyItem = cJSON_Duplicate(newItem.cjson_, true); + cJSON_ReplaceItemInObjectCaseSensitive(this->cjson_, filedName.c_str(), copyItem); + } else { + cJSON *copyItem = cJSON_Duplicate(newItem.cjson_, true); + cJSON_AddItemToObject(this->cjson_, filedName.c_str(), copyItem); + } + } + } +} + +void JsonObject::ReplaceItemInArray(const int &index, const JsonObject &newItem, int &errCode) +{ + if (!newItem.IsNull() || !this->IsNull()) { + if (this->GetType() == JsonObject::Type::JSON_ARRAY) { + cJSON *copyItem = cJSON_Duplicate(newItem.cjson_, true); + cJSON_ReplaceItemInArray(this->cjson_, index, copyItem); + } + } +} + void JsonObject::SetItemValue(const ValueObject &value) const { if (cjson_ == nullptr) { @@ -370,6 +425,20 @@ void JsonObject::SetItemValue(const ValueObject &value) const } } +int JsonObject::InsertItemObject(int which, const JsonObject &newItem) +{ + if (cjson_ == nullptr) { + return E_OK; + } + if (newItem.IsNull()) { + GLOGD("Add null object."); + return E_OK; + } + cJSON *cpoyItem = cJSON_Duplicate(newItem.cjson_, true); + cJSON_InsertItemInArray(cjson_, which, cpoyItem); + return E_OK; +} + std::string JsonObject::GetItemFiled() const { if (cjson_ == nullptr) { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp index 9af80fa7621ce48d23c18fda23731270bb72d97e..ff2b47ed9c1fbc3bc205bc0c32143afbc54d863b 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/src/oh_adapter/src/sqlite_store_executor_impl.cpp @@ -86,7 +86,6 @@ int SqliteStoreExecutor::PutData(const std::string &collName, const Key &key, co if (dbHandle_ == nullptr) { return -E_ERROR; } - std::string sql = "INSERT OR REPLACE INTO '" + collName + "' VALUES (?,?);"; int errCode = SQLiteUtils::ExecSql(dbHandle_, sql, [key, value](sqlite3_stmt *stmt) { SQLiteUtils::BindBlobToStatement(stmt, 1, key); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp index c442be61c3ec63b644da27d40c9d1bd535193cd8..0b503eee43f15c21f9daa8491f6b806e4637627a 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_api_test.cpp @@ -70,8 +70,8 @@ HWTEST_F(DocumentDBApiTest, OpenDBTest001, TestSize.Level0) EXPECT_EQ(GRD_CreateCollection(db, "student", "", 0), GRD_OK); - EXPECT_EQ(GRD_UpsertDoc(db, "student", R""({"_id":"10001"})"", R""({"name":"Tom","age":23})"", 0), 1); - EXPECT_EQ(GRD_UpsertDoc(db, "student", R""({"_id":"10001"})"", R""({"name":"Tom","age":23})"", 0), 1); + EXPECT_EQ(GRD_UpsertDoc(db, "student", R""({"_id":"10001"})"", R""({"_id":"10001", "name":"Tom","age":23})"", 0), 1); + EXPECT_EQ(GRD_UpsertDoc(db, "student", R""({"_id":"10001"})"", R""({"_id":"10001", "name":"Tom","age":23})"", 0), 1); EXPECT_EQ(GRD_DropCollection(db, "student", 0), GRD_OK); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp index 3295851de1d4ded49d00fa1db003b5320300ba31..6808d5f66d0db3223134fa9e9d7a075b287150bd 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_data_test.cpp @@ -310,7 +310,7 @@ HWTEST_F(DocumentDBDataTest, UpdateDataTest006, TestSize.Level0) { std::string filter = R""({"_id":"1234"})""; std::string document = R""({"name":"Tmono","age":18,"addr":{"city":"shanghai","postal":200001}})""; - std::vector invalidFlags = {1, 2, 4, 8, 1024, UINT32_MAX}; + std::vector invalidFlags = {2, 4, 8, 1024, UINT32_MAX}; for (auto flag : invalidFlags) { GLOGD("UpdateDataTest006: update data with flag: %u", flag); EXPECT_EQ(GRD_UpdateDoc(g_db, g_coll, filter.c_str(), document.c_str(), flag), GRD_INVALID_ARGS); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp index 6ce6906314540efd35bf2a9e716477f54ec81cdc..8558a0ef473c48930328c339b13db6c22ac7a52f 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_delete_test.cpp @@ -350,3 +350,31 @@ HWTEST_F(DocumentDeleteApiTest, DeleteDBTest011, TestSize.Level1) EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } +/** + * @tc.name: DocumentDelete012 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(DocumentDeleteApiTest, DeleteDBTest012, TestSize.Level1) +{ + /** + * @tc.step1: Create filter with _id and get the record according to filter condition. + * @tc.expected: step1. GRD_OK + */ + const char *filter = "{\"_id\" : \"1\"}"; + const char *filter2 = "{\"subject.info\" : \"exam\"}"; + GRD_ResultSet *resultSet = nullptr; + Query query = {filter, "{}"}; + EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 0, &resultSet), GRD_OK); + EXPECT_EQ(GRD_DeleteDoc(g_db, COLLECTION_NAME, filter2, 0), 1); + /** + * @tc.step2: Invoke GRD_Next to get the next matching value. Release resultSet. + * @tc.expected: step2. Cannot get next record, return GRD_NO_DATA. + */ + EXPECT_EQ(GRD_Next(resultSet), GRD_NO_DATA); + EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); +} + + diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp index 674c2cbd1c1705fcf354cf656ccb4882446eb322..4d5ea66348bebe0f5f230f50489bf3f8f74e733d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_find_test.cpp @@ -1481,14 +1481,46 @@ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest056, TestSize.Level1) EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); } + /** - * @tc.name: DocumentFindApiTest057 + * @tc.name: DocumentFindApiTest056 * @tc.desc: Test findDoc with no _id. * @tc.type: FUNC * @tc.require: * @tc.author: mazhao */ HWTEST_F(DocumentFindApiTest, DocumentFindApiTest057, TestSize.Level1) +{ + /** + * @tc.steps: step1. Create filter with _id and get the record according to filter condition. + * @tc.expected: step1. Succeed to get the record, the matching record is g_document6. + */ + const char *filter = "{\"personInfo\" : {\"school\":\"B\"}}"; + GRD_ResultSet *resultSet = nullptr; + const char *projection = "{\"version\": 1}"; + Query query = {filter, projection}; + EXPECT_EQ(GRD_FindDoc(g_db, COLLECTION_NAME, query, 1, &resultSet), GRD_OK); + EXPECT_EQ(GRD_Next(resultSet), GRD_OK); + EXPECT_EQ(GRD_Next(resultSet), GRD_OK); + char *value = NULL; + EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_OK); + //CompareValue(value, g_document6); + EXPECT_EQ(GRD_FreeValue(value), GRD_OK); + /** + * @tc.steps: step2. Invoke GRD_Next to get the next matching value. Release resultSet. + * @tc.expected: step2. Cannot get next record, return GRD_NO_DATA. + */ + // EXPECT_EQ(GRD_GetValue(resultSet, &value), GRD_NOT_AVAILABLE); + EXPECT_EQ(GRD_FreeResultSet(resultSet), GRD_OK); +} +/** + * @tc.name: DocumentFindApiTest058 + * @tc.desc: Test findDoc with no _id. + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(DocumentFindApiTest, DocumentFindApiTest058, TestSize.Level1) { /** * @tc.steps: step1. Create filter with _id and get the record according to filter condition. diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp index 5f75c67404f2ade831571bc88514917d6160664d..0dd1a43c116b3e434aec86f3d6fb6fa5de414420 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/api/documentdb_insert_test.cpp @@ -18,6 +18,7 @@ #include "grd_base/grd_db_api.h" #include "grd_document/grd_document_api.h" #include "grd_base/grd_error.h" + using namespace testing::ext; namespace { std::string path = "./document.db"; @@ -751,4 +752,73 @@ HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest039, TestSize.Level1) string document_midlle2(MAX_ID_LENS, 'k'); document = document1 + document2 + document_midlle2 + document4 + document5; EXPECT_EQ(GRD_InsertDoc(g_db, RIGHT_COLLECTION_NAME, document.c_str(), 0), GRD_OK); -} \ No newline at end of file +} + +/** + * @tc.name: DocumentUpdataApiTest040 + * @tc.desc: Insert a filter which _id value's lens is larger than MAX_ID_LENS + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest040, TestSize.Level1) +{ + const char *filter ="{\"_id\" : \"1\"}"; + const char *updata1 = "{\"objectInfo.child.child.level.extra\" : {\"hasChild\" : true}}"; + const char *updata2 = "{\"objectInfo.child.child\" : {\"child\":{\"child\":null}}}"; + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata2, 0), GRD_INVALID_ARGS); +} + + +/** + * @tc.name: DocumentUpdataApiTest041 + * @tc.desc: Insert a filter which _id value's lens is larger than MAX_ID_LENS + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest041, TestSize.Level1) +{ + const char *filter ="{\"_id\" : \"1\"}"; + const char *updata1 = "{\"_id\" : \"6\"}"; + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata1, 0), GRD_INVALID_ARGS); +} + +/** + * @tc.name: DocumentUpdataApiTest042 + * @tc.desc: Insert a filter which _id value's lens is larger than MAX_ID_LENS + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest042, TestSize.Level1) +{ + const char *filter ="{\"_id\" : \"1\"}"; + const char *updata1 = "{\"age$\" : \"21\"}"; + const char *updata2 = "{\"bonus..traffic\" : 100}"; + const char *updata3 = "{\"0item\" : 100}"; + const char *updata4 = "{\"item\" : 1.79769313486232e308}"; + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata1, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata2, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata3, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, updata4, 0), GRD_INVALID_ARGS); +} + +/** + * @tc.name: DocumentUpdataApiTest043 + * @tc.desc: Insert a filter which _id value's lens is larger than MAX_ID_LENS + * @tc.type: FUNC + * @tc.require: + * @tc.author: mazhao + */ +HWTEST_F(DocumentInsertApiTest, DocumentInsertApiTest043, TestSize.Level1) +{ + const char *filter ="{\"_id\" : \"1\"}"; + const char *updata1 = "{\"age\" : 21}"; + const char *updata2 = "{\"bonus..traffic\" : 100}"; + EXPECT_EQ(GRD_UpdateDoc(g_db, NULL, filter, updata1, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(g_db, "", filter, updata1, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(NULL, RIGHT_COLLECTION_NAME, filter, updata1, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, NULL, updata1, 0), GRD_INVALID_ARGS); + EXPECT_EQ(GRD_UpdateDoc(g_db, RIGHT_COLLECTION_NAME, filter, NULL, 0), GRD_INVALID_ARGS); +} diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp index d56a103a826c88180d07d97f4f794c335201aa13..0172c48d1b25d5bdb36914ea4beab17a55fbd2f6 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd_simple/test/unittest/oh_adapter/documentdb_json_common_test.cpp @@ -1,574 +1,574 @@ -/* -* 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. -*/ - -#include -#include - -#include "documentdb_test_utils.h" -#include "doc_errno.h" -#include "json_common.h" -#include "log_print.h" - -using namespace DocumentDB; -using namespace testing::ext; -using namespace DocumentDBUnitTest; - -class DocumentDBJsonCommonTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); -}; - -void DocumentDBJsonCommonTest::SetUpTestCase(void) -{ -} - -void DocumentDBJsonCommonTest::TearDownTestCase(void) -{ -} - -void DocumentDBJsonCommonTest::SetUp(void) -{ -} - -void DocumentDBJsonCommonTest::TearDown(void) -{ -} - -/** - * @tc.name: OpenDBTest001 - * @tc.desc: Test open document db - * @tc.type: FUNC - * @tc.require: - * @tc.author: lianhuix - */ -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) -{ - std::string document = R""({"name":"Tmn","age":18,"addr":{"city":"shanghai","postal":200001}})""; - std::string updateDoc = R""({"name":"Xue","case":{"field1":1,"field2":"string","field3":[1,2,3]},"age":28,"addr":{"city":"shenzhen","postal":518000}})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"case", "field1"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetIntValue(), 1); - - JsonObject itemName = src.FindItem({"name"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Xue"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) -{ - std::string document = R""({"name":"Tmn","case":2,"age":[1,2,3],"addr":{"city":"shanghai","postal":200001}})""; - std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"grade":99,"age":18,"addr": - [{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"grade"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetIntValue(), 99); // 99: grade - - JsonObject itemName = src.FindItem({"name", "1"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Neco"); -} - - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) -{ - std::string document = R""({"name":["Tmn","BB","Alice"],"age":[1,2,3],"addr":[{"city":"shanghai","postal":200001},{"city":"wuhan","postal":430000}]})""; - std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"age":18,"addr":[{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - - GLOGD("result: %s", src.Print().c_str()); - JsonObject itemCase = src.FindItem({"addr", "1", "city"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "beijing"); // 99: grade - - JsonObject itemName = src.FindItem({"name", "1"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Neco"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest004, TestSize.Level0) -{ - std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name.5":"GG"})"";; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); - GLOGD("result: %s", src.Print().c_str()); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) -{ - std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name.2":"GG"})"";; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "2"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest006, TestSize.Level0) -{ - std::string document = R""({"name":{"first":"Tno","last":"moray"}})""; - std::string updateDoc = R""({"name":{"midle.AA":"GG"}})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "midle.AA"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest007, TestSize.Level0) -{ - std::string document = R""({"name":{"first":["XX","CC"],"last":"moray"}})""; - std::string updateDoc = R""({"name.first.0":"LL"})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "LL"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest008, TestSize.Level0) -{ - std::string document = R""({"name":{"first":"XX","last":"moray"}})""; - std::string updateDoc = R""({"name":{"first":["XXX","BBB","CCC"]}})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "XXX"); -} - - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest009, TestSize.Level0) -{ - std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; - std::string updateDoc = R""({"name":{"first":"XX"}})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "first"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "XX"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest010, TestSize.Level0) -{ - std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; - std::string updateDoc = R""({"name":{"first":{"XX":"AA"}}})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "first", "XX"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "AA"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest011, TestSize.Level0) -{ - std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; - std::string updateDoc = R""({"name.last.AA.B":"Mnado"})""; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - - EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); - GLOGD("result: %s", src.Print().c_str()); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest012, TestSize.Level0) -{ - std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name.first":"GG"})"";; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); - GLOGD("result: %s", src.Print().c_str()); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) -{ - std::string document = R""({"name":["Tmn","BB","Alice"]})""; - std::string updateDoc = R""({"name":{"first":"GG"}})"";; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) -{ - std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; - std::string updateDoc = R""({"name.0":"GG"})"";; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); - GLOGD("result: %s", src.Print().c_str()); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest015, TestSize.Level0) -{ - std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; - std::string updateDoc = R""({"name.first":["GG","MM"]})"";; - - int errCode = E_OK; - JsonObject src = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject add = JsonObject::Parse(updateDoc, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(JsonCommon::Append(src, add), E_OK); - GLOGD("result: %s", src.Print().c_str()); - - JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); - EXPECT_EQ(errCode, E_OK); - EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest001, TestSize.Level0) -{ - std::string document = R""({"name":{"first": {"job" : "it"}}, "t1" : {"second":"Lang"}})""; - std::string filter = R""({"name":{"first": {"job" : "it"}}, "t1" : {"second":"Lang"}})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); - - std::string document2 = R""({"name":{"first": {"job" : "it"}, "t1" : {"second":"Lang"}}})""; - std::string filter2 = R""({"name":{"first": {"job" : "NoEqual"}}, "t1" : {"second":"Lang"}})""; - int errCode2 = E_OK; - JsonObject srcObj2 = JsonObject::Parse(document2, errCode2); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj2 = JsonObject::Parse(filter2, errCode2); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj2, errCode), false); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest002, TestSize.Level0) -{ - std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"instock": {"warehouse":"A", "qty":5}})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest003, TestSize.Level0) -{ - std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": "GG"})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), false); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest004, TestSize.Level0) -{ - std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": "GG"})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), false); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest005, TestSize.Level0) -{ - std::string document = R""({"item": ["GG", "AA"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": ["GG", "AA"]})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest006, TestSize.Level0) -{ - std::string document = R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item.0": "GG"})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest007, TestSize.Level0) -{ - std::string document = R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": ["GG", {"gender":"girl"}]})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest008, TestSize.Level0) -{ - std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"item": {"gender":"girl"}})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest009, TestSize.Level0) -{ - std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"qty" : 16, "warehouse":"A"}, - {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"instock.warehouse": "A"})"";; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest010, TestSize.Level0) -{ - std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A"}, - {"warehouse":"C", "qty":15}]})""; - std::string filter = R""({"instock.warehouse": "C"})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest011, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; - std::string filter = R""({"instock" : {"warehose" : "A", "qty" : 5}})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest012, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; - std::string filter = R""({"instock" : {"warehose" : "A", "bad" : "2" ,"qty" : 5}})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), false); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest013, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; - std::string filter = R""({"instock.qty" : 15})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest014, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; - std::string filter = R""({"instock.1.qty" : 15})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest015, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "qty" : 25, "tags" : ["blank", "red"], "dim_cm" : [14, 21]})""; - std::string filter = R""({"tags" : ["blank", "red"]})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest016, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "qty" : 25, "tags" : {"value" : null}, "dim_cm" : [14, 21]})""; - std::string filter = R""({"tags" : {"value" : null}})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest017, TestSize.Level0) -{ - std::string document = R""({"item" : "journal", "qty" : 25, "dim_cm" : [14, 21]})""; - std::string filter = R""({"tags" : {"value" : null}})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest018, TestSize.Level0) -{ - std::string document = "{\"_id\" : \"2\", \"name\":\"doc2\",\"item\": 1, \"personInfo\":\ - [1, \"my string\", {\"school\":\"AB\", \"age\" : 51}, true, {\"school\":\"CD\", \"age\" : 15}, false]}"; - std::string filter = R""({"_id" : "2"})""; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest019, TestSize.Level0) -{ - const char *document = "{\"_id\" : \"1\", \"name\":\"doc1\",\"item\":\"journal\",\"personInfo\":\ - {\"school\":\"AB\", \"age\" : 51}}"; - const char *filter = "{\"personInfo.school\" : \"AB\"}"; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest020, TestSize.Level0) -{ - const char *document = "{\"_id\" : \"3\", \"name\":\"doc3\",\"item\":\"notebook\",\"personInfo\":\ - [{\"school\":\"C\", \"age\" : 5}]}"; - const char *filter = "{\"personInfo\" : [{\"school\":\"C\", \"age\" : 5}]}"; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} - -HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest021, TestSize.Level0) -{ - const char *document = "{\"_id\" : \"15\", \"name\":\"doc15\",\"personInfo\":[{\"school\":\"C\", \"age\" : 5}]}"; - const char *filter = "{\"item\" : null, \"personInfo\" : [{\"school\":\"C\", \"age\" : 5}]}"; - int errCode = E_OK; - JsonObject srcObj = JsonObject::Parse(document, errCode); - EXPECT_EQ(errCode, E_OK); - JsonObject filterObj = JsonObject::Parse(filter, errCode); - EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); -} \ No newline at end of file +// /* +// * 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. +// */ + +// #include +// #include + +// #include "documentdb_test_utils.h" +// #include "doc_errno.h" +// #include "json_common.h" +// #include "log_print.h" + +// using namespace DocumentDB; +// using namespace testing::ext; +// using namespace DocumentDBUnitTest; + +// class DocumentDBJsonCommonTest : public testing::Test { +// public: +// static void SetUpTestCase(void); +// static void TearDownTestCase(void); +// void SetUp(); +// void TearDown(); +// }; + +// void DocumentDBJsonCommonTest::SetUpTestCase(void) +// { +// } + +// void DocumentDBJsonCommonTest::TearDownTestCase(void) +// { +// } + +// void DocumentDBJsonCommonTest::SetUp(void) +// { +// } + +// void DocumentDBJsonCommonTest::TearDown(void) +// { +// } + +// /** +// * @tc.name: OpenDBTest001 +// * @tc.desc: Test open document db +// * @tc.type: FUNC +// * @tc.require: +// * @tc.author: lianhuix +// */ +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest001, TestSize.Level0) +// { +// std::string document = R""({"name":"Tmn","age":18,"addr":{"city":"shanghai","postal":200001}})""; +// std::string updateDoc = R""({"name":"Xue","case":{"field1":1,"field2":"string","field3":[1,2,3]},"age":28,"addr":{"city":"shenzhen","postal":518000}})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"case", "field1"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetIntValue(), 1); + +// JsonObject itemName = src.FindItem({"name"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Xue"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest002, TestSize.Level0) +// { +// std::string document = R""({"name":"Tmn","case":2,"age":[1,2,3],"addr":{"city":"shanghai","postal":200001}})""; +// std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"grade":99,"age":18,"addr": +// [{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"grade"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetIntValue(), 99); // 99: grade + +// JsonObject itemName = src.FindItem({"name", "1"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Neco"); +// } + + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest003, TestSize.Level0) +// { +// std::string document = R""({"name":["Tmn","BB","Alice"],"age":[1,2,3],"addr":[{"city":"shanghai","postal":200001},{"city":"wuhan","postal":430000}]})""; +// std::string updateDoc = R""({"name":["Xue","Neco","Lip"],"age":18,"addr":[{"city":"shanghai","postal":200001},{"city":"beijing","postal":100000}]})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); + +// GLOGD("result: %s", src.Print().c_str()); +// JsonObject itemCase = src.FindItem({"addr", "1", "city"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "beijing"); // 99: grade + +// JsonObject itemName = src.FindItem({"name", "1"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemName.GetItemValue().GetStringValue(), "Neco"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest004, TestSize.Level0) +// { +// std::string document = R""({"name":["Tmn","BB","Alice"]})""; +// std::string updateDoc = R""({"name.5":"GG"})"";; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); +// GLOGD("result: %s", src.Print().c_str()); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest005, TestSize.Level0) +// { +// std::string document = R""({"name":["Tmn","BB","Alice"]})""; +// std::string updateDoc = R""({"name.2":"GG"})"";; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "2"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest006, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":"Tno","last":"moray"}})""; +// std::string updateDoc = R""({"name":{"midle.AA":"GG"}})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "midle.AA"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest007, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":["XX","CC"],"last":"moray"}})""; +// std::string updateDoc = R""({"name.first.0":"LL"})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "LL"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest008, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":"XX","last":"moray"}})""; +// std::string updateDoc = R""({"name":{"first":["XXX","BBB","CCC"]}})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "XXX"); +// } + + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest009, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; +// std::string updateDoc = R""({"name":{"first":"XX"}})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "first"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "XX"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest010, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; +// std::string updateDoc = R""({"name":{"first":{"XX":"AA"}}})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "first", "XX"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "AA"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest011, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":["XXX","BBB","CCC"],"last":"moray"}})""; +// std::string updateDoc = R""({"name.last.AA.B":"Mnado"})""; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); + +// EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); +// GLOGD("result: %s", src.Print().c_str()); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest012, TestSize.Level0) +// { +// std::string document = R""({"name":["Tmn","BB","Alice"]})""; +// std::string updateDoc = R""({"name.first":"GG"})"";; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); +// GLOGD("result: %s", src.Print().c_str()); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest013, TestSize.Level0) +// { +// std::string document = R""({"name":["Tmn","BB","Alice"]})""; +// std::string updateDoc = R""({"name":{"first":"GG"}})"";; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest014, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; +// std::string updateDoc = R""({"name.0":"GG"})"";; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), -E_DATA_CONFLICT); +// GLOGD("result: %s", src.Print().c_str()); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectAppendTest015, TestSize.Level0) +// { +// std::string document = R""({"name":{"first":"Xue","second":"Lang"}})""; +// std::string updateDoc = R""({"name.first":["GG","MM"]})"";; + +// int errCode = E_OK; +// JsonObject src = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject add = JsonObject::Parse(updateDoc, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(JsonCommon::Append(src, add), E_OK); +// GLOGD("result: %s", src.Print().c_str()); + +// JsonObject itemCase = src.FindItem({"name", "first", "0"}, errCode); +// EXPECT_EQ(errCode, E_OK); +// EXPECT_EQ(itemCase.GetItemValue().GetStringValue(), "GG"); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest001, TestSize.Level0) +// { +// std::string document = R""({"name":{"first": {"job" : "it"}}, "t1" : {"second":"Lang"}})""; +// std::string filter = R""({"name":{"first": {"job" : "it"}}, "t1" : {"second":"Lang"}})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); + +// std::string document2 = R""({"name":{"first": {"job" : "it"}, "t1" : {"second":"Lang"}}})""; +// std::string filter2 = R""({"name":{"first": {"job" : "NoEqual"}}, "t1" : {"second":"Lang"}})""; +// int errCode2 = E_OK; +// JsonObject srcObj2 = JsonObject::Parse(document2, errCode2); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj2 = JsonObject::Parse(filter2, errCode2); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj2, filterObj2, errCode), false); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest002, TestSize.Level0) +// { +// std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"instock": {"warehouse":"A", "qty":5}})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest003, TestSize.Level0) +// { +// std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"item": "GG"})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), false); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest004, TestSize.Level0) +// { +// std::string document = R""({"item": [{"gender":"girl"}, "GG"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"item": "GG"})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), false); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest005, TestSize.Level0) +// { +// std::string document = R""({"item": ["GG", "AA"], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"item": ["GG", "AA"]})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest006, TestSize.Level0) +// { +// std::string document = R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"item.0": "GG"})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest007, TestSize.Level0) +// { +// std::string document = R""({"item": ["GG", {"gender":"girl"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"item": ["GG", {"gender":"girl"}]})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest008, TestSize.Level0) +// { +// std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A", "qty":5}, {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"item": {"gender":"girl"}})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest009, TestSize.Level0) +// { +// std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"qty" : 16, "warehouse":"A"}, +// {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"instock.warehouse": "A"})"";; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest010, TestSize.Level0) +// { +// std::string document = R""({"item": ["GG", {"gender":"girl", "hobby" : "IT"}], "instock": [{"warehouse":"A"}, +// {"warehouse":"C", "qty":15}]})""; +// std::string filter = R""({"instock.warehouse": "C"})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest011, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; +// std::string filter = R""({"instock" : {"warehose" : "A", "qty" : 5}})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest012, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; +// std::string filter = R""({"instock" : {"warehose" : "A", "bad" : "2" ,"qty" : 5}})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), false); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest013, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; +// std::string filter = R""({"instock.qty" : 15})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest014, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "instock" : [{"warehose" : "A", "qty" : 5}, {"warehose" : "C", "qty" : 15}]})""; +// std::string filter = R""({"instock.1.qty" : 15})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest015, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "qty" : 25, "tags" : ["blank", "red"], "dim_cm" : [14, 21]})""; +// std::string filter = R""({"tags" : ["blank", "red"]})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest016, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "qty" : 25, "tags" : {"value" : null}, "dim_cm" : [14, 21]})""; +// std::string filter = R""({"tags" : {"value" : null}})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest017, TestSize.Level0) +// { +// std::string document = R""({"item" : "journal", "qty" : 25, "dim_cm" : [14, 21]})""; +// std::string filter = R""({"tags" : {"value" : null}})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest018, TestSize.Level0) +// { +// std::string document = "{\"_id\" : \"2\", \"name\":\"doc2\",\"item\": 1, \"personInfo\":\ +// [1, \"my string\", {\"school\":\"AB\", \"age\" : 51}, true, {\"school\":\"CD\", \"age\" : 15}, false]}"; +// std::string filter = R""({"_id" : "2"})""; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest019, TestSize.Level0) +// { +// const char *document = "{\"_id\" : \"1\", \"name\":\"doc1\",\"item\":\"journal\",\"personInfo\":\ +// {\"school\":\"AB\", \"age\" : 51}}"; +// const char *filter = "{\"personInfo.school\" : \"AB\"}"; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest020, TestSize.Level0) +// { +// const char *document = "{\"_id\" : \"3\", \"name\":\"doc3\",\"item\":\"notebook\",\"personInfo\":\ +// [{\"school\":\"C\", \"age\" : 5}]}"; +// const char *filter = "{\"personInfo\" : [{\"school\":\"C\", \"age\" : 5}]}"; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } + +// HWTEST_F(DocumentDBJsonCommonTest, JsonObjectisFilterCheckTest021, TestSize.Level0) +// { +// const char *document = "{\"_id\" : \"15\", \"name\":\"doc15\",\"personInfo\":[{\"school\":\"C\", \"age\" : 5}]}"; +// const char *filter = "{\"item\" : null, \"personInfo\" : [{\"school\":\"C\", \"age\" : 5}]}"; +// int errCode = E_OK; +// JsonObject srcObj = JsonObject::Parse(document, errCode); +// EXPECT_EQ(errCode, E_OK); +// JsonObject filterObj = JsonObject::Parse(filter, errCode); +// EXPECT_EQ(JsonCommon::IsJsonNodeMatch(srcObj, filterObj, errCode), true); +// } \ No newline at end of file