diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp index e63cfbfffcfa0b77d4ca74a99f3abcb0cb2c365d..3605f794d9a0bb6b72fee7cea8d6c075dfe25b46 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/common/src/json_common.cpp @@ -176,6 +176,7 @@ bool JsonCommon::CheckProjectionField(JsonObject &jsonObj, int &errCode) namespace { int SplitFieldName(const std::string &fieldName, std::vector &allFieldsName, int &insertCount) { + 用现有的c++函数,没必要自己搞一个,对于报错的情况单独处理,【优先级:中】 std::string tempParseName; std::string priFieldName = fieldName; for (size_t j = 0; j < priFieldName.size(); j++) { @@ -187,6 +188,7 @@ int SplitFieldName(const std::string &fieldName, std::vector &allFi (priFieldName[j] == '.' && j == priFieldName.size() - 1)) { return -E_INVALID_ARGS; } + 这里就可以做tempParseName校验,后面就没必要校验了 allFieldsName.emplace_back(tempParseName); insertCount++; tempParseName.clear(); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp index 01513f9f83652c107f714e2e1e4e41d288db0c66..1d9f68452eebea5e36f597c8f6eaa7ec5376770e 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/executor/document/check_common.cpp @@ -59,6 +59,7 @@ bool CheckCommon::CheckCollectionName(const std::string &collectionName, std::st errCode = -E_OVER_LIMIT; return false; } + // 直接先转成小写字母,直接比较就行,不然里面每次都转一次,没必要【优先级:低】 if (CheckCollectionNamePrefix(collectionName, COLLECTION_PREFIX_GRD) || CheckCollectionNamePrefix(collectionName, COLLECTION_PREFIX_GM_SYS)) { GLOGE("Collection name is illegal"); @@ -95,6 +96,7 @@ int CheckCommon::CheckFilter(JsonObject &filterObj, bool &isOnlyId, std::vector< return -E_INVALID_ARGS; } for (auto oneChar : filterPath[i][j]) { + 抽象个校验函数出来,【优先级:高】,分filter,update, 和普通的document if (!((isalpha(oneChar)) || (isdigit(oneChar)) || (oneChar == '_'))) { return -E_INVALID_ARGS; } diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h index f7c7b0954c7fb32892cc6ef8f4ddfda918e4e427..5ce3097c8ddb9f53bea68908cdb6c522a6cc9bf5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/projection_tree.h @@ -28,6 +28,7 @@ struct ProjectionNode { std::unordered_map sonNode; bool isDeepest; int Deep; + 不用存viewType,每个viewType都要一样,前面要校验,【优先级:中】 int ViewType; ProjectionNode() { diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h index ea1bcf42589521a15d4fcd6e963578e360ce56c2..b565e6024ebcbca439140a57d20e977884c6e6f5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/include/result_set.h @@ -48,16 +48,23 @@ private: int GetNextWithField(); DocumentStore *store_ = nullptr; + 存小写的就行,提供个根据collectionName获取实际表名函数,【优先级:中】 std::string collectionName_; + 没必要记录key_,没用到是不是可以删掉 + 记录string id就可以,没用上的删掉,如果id是空,代表非id查询,如果id非空代表不带id查询,后面的isOnlyId_没用【优先级:高】 ValueObject key_; + filter_不要记录字符串,记录成JsonObject,【优先级:高】 std::string filter_; bool ifShowId_ = false; bool viewType_ = false; bool ifField_ = false; bool isOnlyId_ = false; + projectionPath_跟projectionTree_是不是重复,只用projectionPath_能否解决问题 ProjectionTree projectionTree_; std::vector> projectionPath_; + 不用记录index_ size_t index_ = 0; + matchDatas_记录一个就行,不能所有都获取,【优先级:高】 std::vector> matchDatas_; }; } // namespace DocumentDB diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp index cf29ac15ed53e1bb3ad86ea237cc810ac32e091d..566a469ddb8c990d18c7df3e5706061b71a5cf94 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/document_store.cpp @@ -187,6 +187,7 @@ int DocumentStore::UpdateDocument(const std::string &collection, const std::stri if (errCode != E_OK) { return errCode; } + 统一先走resultSet,根据resultSet的结果来做处理,代码复用,优先级【高】 std::string docId; int count = 0; auto coll = Collection(collection, executor_); @@ -285,6 +286,7 @@ int DocumentStore::UpsertDocument(const std::string &collection, const std::stri int count = 0; std::string targetDocument; std::string docId; + 统一先走resultSet,根据resultSet的结果来做处理,代码复用,优先级【高】 if (isOnlyId) { auto filterObjChild = filterObj.GetChild(); ValueObject idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); @@ -415,6 +417,7 @@ int DocumentStore::DeleteDocument(const std::string &collection, const std::stri return errCode; } std::string id; + 统一先走resultSet,根据resultSet的结果来做处理,代码复用,优先级【高】 if (isOnlyId) { auto filterObjChild = filterObj.GetChild(); auto idValue = JsonCommon::GetValueInSameLevel(filterObjChild, KEY_ID); @@ -458,6 +461,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("Check collection name invalid. %d", errCode); return errCode; } + 后面直接用小写的来,里面就不用多做转换了【优先级:高】 if (filter.length() >= JSON_LENS_MAX || projection.length() >= JSON_LENS_MAX) { GLOGE("args length is too long"); return -E_OVER_LIMIT; @@ -472,11 +476,14 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string if (errCode != E_OK) { return errCode; } + isOnlyId含义要改,std::string id即可,只要filter条件带id,把id取出来,【优先级:高】 + 这个标记不应该只判断是不是只有id一个查询条件,只要filter里面都带id都走id查询 bool isOnlyId = true; errCode = CheckCommon::CheckFilter(filterObj, isOnlyId, filterAllPath); if (errCode != E_OK) { return errCode; } + 这个校验往前移动,【优先级:高】 if (projection.length() >= JSON_LENS_MAX) { GLOGE("projection's length is too long"); return -E_OVER_LIMIT; @@ -497,6 +504,7 @@ int DocumentStore::FindDocument(const std::string &collection, const std::string GLOGE("GetViewType failed"); return -E_INVALID_ARGS; } + 这个校验什么?如果只是校验field是不是只在ParsePath里面弄就好了,【优先级:高】 errCode = CheckCommon::CheckProjection(projectionObj, allPath); if (errCode != E_OK) { GLOGE("projection format unvalid"); diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp index 3981807385ed74a08080e07f1894625983d7db6f..c72fc04a336ac6efe66f519155df2b1584d065e5 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/interface/src/result_set.cpp @@ -49,6 +49,7 @@ int ResultSet::Init(DocumentStore *store, const std::string collectionName, cons int ResultSet::Init(DocumentStore *store, const std::string collectionName, const std::string &filter) { + ifField_意义在哪里 ifField_ = true; store_ = store; collectionName_ = collectionName; @@ -105,6 +106,9 @@ int ResultSet::GetNextWithField() int ResultSet::GetNextInner(bool isNeedCheckTable) { + 【优先级:高】 + 这里分两种情况,一种是根据id查询,一种是全表扫描,这里不用启动事务,如果这种情况,move就返回end + 如果是全表扫描,第一次启动读事务,把statement记录下来,每次取一条数据,这里如果到达末尾了根据错误码判断,就不用index int errCode = E_OK; if (isNeedCheckTable) { std::string lowerCaseName = collectionName_; diff --git a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp index e607ed65f85618c61776f179868ea17b270cf999..bc583ec21e67c2d445daf17b038bb94417f1196d 100644 --- a/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp +++ b/services/distributeddataservice/service/data_share/gaussdb_rd/src/oh_adapter/src/json_object.cpp @@ -181,8 +181,10 @@ int JsonObject::Init(const std::string &str, bool isFilter) GLOGE("after Parse,cjson_'s type is not cJSON_Object"); return -E_INVALID_ARGS; } - int ret = 0; + 【优先级: 高】 + 这里面可以不单单校验number,如果是非filter以及update,则field格式可以一起校验,后面就不用校验这种场景field格式了 + 不过filter,update的field可以再后面拆分field时候校验 CheckNumber(cjson_, ret); if (ret == -E_INVALID_ARGS) { GLOGE("Int value is larger than double");