Update resources name in HTTP module (#1545)

* set preload_table correctly (fix #1524)

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* update res name in http module (fix #1544)

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* add bool convertor function

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* fix test fail

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* optimize update config method & add boolean conversion comments

Signed-off-by: Yhz <yinghao.zou@zilliz.com>

* remove comments

Signed-off-by: Yhz <yinghao.zou@zilliz.com>
This commit is contained in:
BossZou 2020-03-07 20:56:01 +08:00 committed by GitHub
parent 0fd9bf8e70
commit 0fcdc31c7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 499 additions and 477 deletions

View File

@ -90,6 +90,7 @@ Please mark all change in change log and use the issue from GitHub
- \#1448 General proto api for NNS libraries
- \#1480 Add return code for AVX512 selection
- \#1524 Update config "preload_table" description
- \#1544 Update resources name in HTTP module
## Task
- \#1327 Exclude third-party code from codebeat

View File

@ -14,7 +14,6 @@
#include <string>
#include "server/Config.h"
#include "utils/Log.h"
namespace milvus {
namespace server {

View File

@ -549,9 +549,14 @@ Config::UpdateFileConfigFromMem(const std::string& parent_key, const std::string
// convert value string to standard string stored in yaml file
std::string value_str;
if (child_key == CONFIG_CACHE_CACHE_INSERT_DATA || child_key == CONFIG_STORAGE_S3_ENABLE ||
child_key == CONFIG_METRIC_ENABLE_MONITOR || child_key == CONFIG_GPU_RESOURCE_ENABLE) {
value_str =
(value == "True" || value == "true" || value == "On" || value == "on" || value == "1") ? "true" : "false";
child_key == CONFIG_METRIC_ENABLE_MONITOR || child_key == CONFIG_GPU_RESOURCE_ENABLE ||
child_key == CONFIG_WAL_ENABLE || child_key == CONFIG_WAL_RECOVERY_ERROR_IGNORE) {
bool ok = false;
status = StringHelpFunctions::ConvertToBoolean(value, ok);
if (!status.ok()) {
return status;
}
value_str = ok ? "true" : "false";
} else if (child_key == CONFIG_GPU_RESOURCE_SEARCH_RESOURCES ||
child_key == CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES) {
std::vector<std::string> vec;
@ -593,7 +598,6 @@ Config::UpdateFileConfigFromMem(const std::string& parent_key, const std::string
}
// values of gpu resources are sequences, need to remove old here
std::regex reg("\\S*");
if (child_key == CONFIG_GPU_RESOURCE_SEARCH_RESOURCES || child_key == CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES) {
while (getline(conf_fin, line)) {
if (line.find("- gpu") != std::string::npos)
@ -1853,7 +1857,8 @@ Config::SetDBConfigBackendUrl(const std::string& value) {
Status
Config::SetDBConfigPreloadTable(const std::string& value) {
CONFIG_CHECK(CheckDBConfigPreloadTable(value));
return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRELOAD_TABLE, value);
std::string cor_value = value == "*" ? "\'*\'" : value;
return SetConfigValueInMem(CONFIG_DB, CONFIG_DB_PRELOAD_TABLE, cor_value);
}
Status

View File

@ -208,14 +208,14 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(TablesOptions)
ENDPOINT("OPTIONS", "/tables", TablesOptions) {
ENDPOINT("OPTIONS", "/collections", TablesOptions) {
return createResponse(Status::CODE_204, "No Content");
}
ADD_CORS(CreateTable)
ENDPOINT("POST", "/tables", CreateTable, BODY_DTO(TableRequestDto::ObjectWrapper, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/tables\'");
ENDPOINT("POST", "/collections", CreateTable, BODY_DTO(TableRequestDto::ObjectWrapper, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/collections\'");
tr.RecordSection("Received request.");
WebRequestHandler handler = WebRequestHandler();
@ -238,8 +238,8 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(ShowTables)
ENDPOINT("GET", "/tables", ShowTables, QUERIES(const QueryParams&, query_params)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/tables\'");
ENDPOINT("GET", "/collections", ShowTables, QUERIES(const QueryParams&, query_params)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/collections\'");
tr.RecordSection("Received request.");
WebRequestHandler handler = WebRequestHandler();
@ -265,21 +265,21 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(TableOptions)
ENDPOINT("OPTIONS", "/tables/{table_name}", TableOptions) {
ENDPOINT("OPTIONS", "/collections/{collection_name}", TableOptions) {
return createResponse(Status::CODE_204, "No Content");
}
ADD_CORS(GetTable)
ENDPOINT("GET", "/tables/{table_name}", GetTable,
PATH(String, table_name), QUERIES(const QueryParams&, query_params)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/tables/" + table_name->std_str() + "\'");
ENDPOINT("GET", "/collections/{collection_name}", GetTable,
PATH(String, collection_name), QUERIES(const QueryParams&, query_params)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/collections/" + collection_name->std_str() + "\'");
tr.RecordSection("Received request.");
WebRequestHandler handler = WebRequestHandler();
String response_str;
auto status_dto = handler.GetTable(table_name, query_params, response_str);
auto status_dto = handler.GetTable(collection_name, query_params, response_str);
std::shared_ptr<OutgoingResponse> response;
switch (status_dto->code->getValue()) {
@ -302,14 +302,14 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(DropTable)
ENDPOINT("DELETE", "/tables/{table_name}", DropTable, PATH(String, table_name)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "DELETE \'/tables/" + table_name->std_str() + "\'");
ENDPOINT("DELETE", "/collections/{collection_name}", DropTable, PATH(String, collection_name)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "DELETE \'/collections/" + collection_name->std_str() + "\'");
tr.RecordSection("Received request.");
WebRequestHandler handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.DropTable(table_name);
auto status_dto = handler.DropTable(collection_name);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_204, status_dto);
@ -330,21 +330,21 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(IndexOptions)
ENDPOINT("OPTIONS", "/tables/{table_name}/indexes", IndexOptions) {
ENDPOINT("OPTIONS", "/collections/{collection_name}/indexes", IndexOptions) {
return createResponse(Status::CODE_204, "No Content");
}
ADD_CORS(CreateIndex)
ENDPOINT("POST", "/tables/{table_name}/indexes", CreateIndex,
PATH(String, table_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/tables/" + table_name->std_str() + "/indexes\'");
ENDPOINT("POST", "/tables/{collection_name}/indexes", CreateIndex,
PATH(String, collection_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/tables/" + collection_name->std_str() + "/indexes\'");
tr.RecordSection("Received request.");
auto handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.CreateIndex(table_name, body);
auto status_dto = handler.CreateIndex(collection_name, body);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_201, status_dto);
@ -365,14 +365,14 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(GetIndex)
ENDPOINT("GET", "/tables/{table_name}/indexes", GetIndex, PATH(String, table_name)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/tables/" + table_name->std_str() + "/indexes\'");
ENDPOINT("GET", "/collections/{collection_name}/indexes", GetIndex, PATH(String, collection_name)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/collections/" + collection_name->std_str() + "/indexes\'");
tr.RecordSection("Received request.");
auto handler = WebRequestHandler();
OString result;
auto status_dto = handler.GetIndex(table_name, result);
auto status_dto = handler.GetIndex(collection_name, result);
std::shared_ptr<OutgoingResponse> response;
switch (status_dto->code->getValue()) {
@ -395,14 +395,14 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(DropIndex)
ENDPOINT("DELETE", "/tables/{table_name}/indexes", DropIndex, PATH(String, table_name)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "DELETE \'/tables/" + table_name->std_str() + "/indexes\'");
ENDPOINT("DELETE", "/collections/{collection_name}/indexes", DropIndex, PATH(String, collection_name)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "DELETE \'/collections/" + collection_name->std_str() + "/indexes\'");
tr.RecordSection("Received request.");
auto handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.DropIndex(table_name);
auto status_dto = handler.DropIndex(collection_name);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_204, status_dto);
@ -423,21 +423,21 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(PartitionsOptions)
ENDPOINT("OPTIONS", "/tables/{table_name}/partitions", PartitionsOptions) {
ENDPOINT("OPTIONS", "/collections/{collection_name}/partitions", PartitionsOptions) {
return createResponse(Status::CODE_204, "No Content");
}
ADD_CORS(CreatePartition)
ENDPOINT("POST", "/tables/{table_name}/partitions",
CreatePartition, PATH(String, table_name), BODY_DTO(PartitionRequestDto::ObjectWrapper, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/tables/" + table_name->std_str() + "/partitions\'");
ENDPOINT("POST", "/collections/{collection_name}/partitions",
CreatePartition, PATH(String, collection_name), BODY_DTO(PartitionRequestDto::ObjectWrapper, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/collections/" + collection_name->std_str() + "/partitions\'");
tr.RecordSection("Received request.");
auto handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.CreatePartition(table_name, body);
auto status_dto = handler.CreatePartition(collection_name, body);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_201, status_dto);
@ -457,9 +457,9 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(ShowPartitions)
ENDPOINT("GET", "/tables/{table_name}/partitions", ShowPartitions,
PATH(String, table_name), QUERIES(const QueryParams&, query_params)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/tables/" + table_name->std_str() + "/partitions\'");
ENDPOINT("GET", "/collections/{collection_name}/partitions", ShowPartitions,
PATH(String, collection_name), QUERIES(const QueryParams&, query_params)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "GET \'/collections/" + collection_name->std_str() + "/partitions\'");
tr.RecordSection("Received request.");
auto offset = query_params.get("offset");
@ -469,7 +469,7 @@ class WebController : public oatpp::web::server::api::ApiController {
auto handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.ShowPartitions(table_name, query_params, partition_list_dto);
auto status_dto = handler.ShowPartitions(collection_name, query_params, partition_list_dto);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_200, partition_list_dto);
@ -488,16 +488,16 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(DropPartition)
ENDPOINT("DELETE", "/tables/{table_name}/partitions", DropPartition,
PATH(String, table_name), BODY_STRING(String, body)) {
ENDPOINT("DELETE", "/collections/{collection_name}/partitions", DropPartition,
PATH(String, collection_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) +
"DELETE \'/tables/" + table_name->std_str() + "/partitions\'");
"DELETE \'/collections/" + collection_name->std_str() + "/partitions\'");
tr.RecordSection("Received request.");
auto handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.DropPartition(table_name, body);
auto status_dto = handler.DropPartition(collection_name, body);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_204, status_dto);
@ -517,14 +517,14 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(ShowSegments)
ENDPOINT("GET", "/tables/{table_name}/segments", ShowSegments,
PATH(String, table_name), QUERIES(const QueryParams&, query_params)) {
ENDPOINT("GET", "/collections/{collection_name}/segments", ShowSegments,
PATH(String, collection_name), QUERIES(const QueryParams&, query_params)) {
auto offset = query_params.get("offset");
auto page_size = query_params.get("page_size");
auto handler = WebRequestHandler();
String response;
auto status_dto = handler.ShowSegments(table_name, query_params, response);
auto status_dto = handler.ShowSegments(collection_name, query_params, response);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
@ -541,14 +541,14 @@ class WebController : public oatpp::web::server::api::ApiController {
*
* GetSegmentVector
*/
ENDPOINT("GET", "/tables/{table_name}/segments/{segment_name}/{info}", GetSegmentInfo,
PATH(String, table_name), PATH(String, segment_name), PATH(String, info), QUERIES(const QueryParams&, query_params)) {
ENDPOINT("GET", "/collections/{collection_name}/segments/{segment_name}/{info}", GetSegmentInfo,
PATH(String, collection_name), PATH(String, segment_name), PATH(String, info), QUERIES(const QueryParams&, query_params)) {
auto offset = query_params.get("offset");
auto page_size = query_params.get("page_size");
auto handler = WebRequestHandler();
String response;
auto status_dto = handler.GetSegmentInfo(table_name, segment_name, info, query_params, response);
auto status_dto = handler.GetSegmentInfo(collection_name, segment_name, info, query_params, response);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
@ -562,7 +562,7 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(VectorsOptions)
ENDPOINT("OPTIONS", "/tables/{table_name}/vectors", VectorsOptions) {
ENDPOINT("OPTIONS", "/collections/{collection_name}/vectors", VectorsOptions) {
return createResponse(Status::CODE_204, "No Content");
}
@ -571,11 +571,11 @@ class WebController : public oatpp::web::server::api::ApiController {
*
* GetVectorByID ?id=
*/
ENDPOINT("GET", "/tables/{table_name}/vectors", GetVectors,
PATH(String, table_name), QUERIES(const QueryParams&, query_params)) {
ENDPOINT("GET", "/collections/{collection_name}/vectors", GetVectors,
PATH(String, collection_name), QUERIES(const QueryParams&, query_params)) {
auto handler = WebRequestHandler();
String response;
auto status_dto = handler.GetVector(table_name, query_params, response);
auto status_dto = handler.GetVector(collection_name, query_params, response);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
@ -589,16 +589,16 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(Insert)
ENDPOINT("POST", "/tables/{table_name}/vectors", Insert,
PATH(String, table_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/tables/" + table_name->std_str() + "/vectors\'");
ENDPOINT("POST", "/collections/{collection_name}/vectors", Insert,
PATH(String, collection_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "POST \'/collections/" + collection_name->std_str() + "/vectors\'");
tr.RecordSection("Received request.");
auto ids_dto = VectorIdsDto::createShared();
WebRequestHandler handler = WebRequestHandler();
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.Insert(table_name, body, ids_dto);
auto status_dto = handler.Insert(collection_name, body, ids_dto);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createDtoResponse(Status::CODE_201, ids_dto);
@ -621,16 +621,16 @@ class WebController : public oatpp::web::server::api::ApiController {
* Search
* Delete by ID
* */
ENDPOINT("PUT", "/tables/{table_name}/vectors", VectorsOp,
PATH(String, table_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "PUT \'/tables/" + table_name->std_str() + "/vectors\'");
ENDPOINT("PUT", "/collections/{collection_name}/vectors", VectorsOp,
PATH(String, collection_name), BODY_STRING(String, body)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "PUT \'/collections/" + collection_name->std_str() + "/vectors\'");
tr.RecordSection("Received request.");
WebRequestHandler handler = WebRequestHandler();
OString result;
std::shared_ptr<OutgoingResponse> response;
auto status_dto = handler.VectorsOp(table_name, body, result);
auto status_dto = handler.VectorsOp(collection_name, body, result);
switch (status_dto->code->getValue()) {
case StatusCode::SUCCESS:
response = createResponse(Status::CODE_200, result);
@ -674,11 +674,6 @@ class WebController : public oatpp::web::server::api::ApiController {
ADD_CORS(SystemOp)
/**
* Load
* Compact
* Flush
*/
ENDPOINT("PUT", "/system/{Op}", SystemOp, PATH(String, Op), BODY_STRING(String, body_str)) {
TimeRecorder tr(std::string(WEB_LOG_PREFIX) + "PUT \'/system/" + Op->std_str() + "\'");
tr.RecordSection("Received request.");

View File

@ -25,7 +25,7 @@ namespace web {
class TableRequestDto : public oatpp::data::mapping::type::Object {
DTO_INIT(TableRequestDto, Object)
DTO_FIELD(String, table_name, "table_name");
DTO_FIELD(String, collection_name, "collection_name");
DTO_FIELD(Int64, dimension, "dimension");
DTO_FIELD(Int64, index_file_size, "index_file_size") = VALUE_TABLE_INDEX_FILE_SIZE_DEFAULT;
DTO_FIELD(String, metric_type, "metric_type") = VALUE_TABLE_METRIC_TYPE_DEFAULT;
@ -34,7 +34,7 @@ class TableRequestDto : public oatpp::data::mapping::type::Object {
class TableFieldsDto : public oatpp::data::mapping::type::Object {
DTO_INIT(TableFieldsDto, Object)
DTO_FIELD(String, table_name);
DTO_FIELD(String, collection_name);
DTO_FIELD(Int64, dimension);
DTO_FIELD(Int64, index_file_size);
DTO_FIELD(String, metric_type);
@ -46,13 +46,13 @@ class TableFieldsDto : public oatpp::data::mapping::type::Object {
class TableListDto : public OObject {
DTO_INIT(TableListDto, Object)
DTO_FIELD(List<String>::ObjectWrapper, table_names);
DTO_FIELD(List<String>::ObjectWrapper, collection_names);
};
class TableListFieldsDto : public OObject {
DTO_INIT(TableListFieldsDto, Object)
DTO_FIELD(List<TableFieldsDto::ObjectWrapper>::ObjectWrapper, tables);
DTO_FIELD(List<TableFieldsDto::ObjectWrapper>::ObjectWrapper, collections);
DTO_FIELD(Int64, count) = 0;
};

View File

@ -20,26 +20,6 @@ namespace web {
#include OATPP_CODEGEN_BEGIN(DTO)
class SearchRequestDto : public OObject {
DTO_INIT(SearchRequestDto, Object)
DTO_FIELD(Int64, topk);
DTO_FIELD(Int64, nprobe);
DTO_FIELD(List<String>::ObjectWrapper, tags);
DTO_FIELD(List<String>::ObjectWrapper, file_ids);
DTO_FIELD(List<List<Float32>::ObjectWrapper>::ObjectWrapper, records);
DTO_FIELD(List<List<Int64>::ObjectWrapper>::ObjectWrapper, records_bin);
};
class InsertRequestDto : public oatpp::data::mapping::type::Object {
DTO_INIT(InsertRequestDto, Object)
DTO_FIELD(String, tag) = VALUE_PARTITION_TAG_DEFAULT;
DTO_FIELD(List<List<Float32>::ObjectWrapper>::ObjectWrapper, records);
DTO_FIELD(List<List<Int64>::ObjectWrapper>::ObjectWrapper, records_bin);
DTO_FIELD(List<Int64>::ObjectWrapper, ids);
};
class VectorIdsDto : public oatpp::data::mapping::type::Object {
DTO_INIT(VectorIdsDto, Object)

View File

@ -109,6 +109,26 @@ WebRequestHandler::ParseQueryStr(const OQueryParams& query_params, const std::st
return Status::OK();
}
Status
WebRequestHandler::ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value,
bool nullable) {
auto query = query_params.get(key.c_str());
if (nullptr != query.get() && query->getSize() > 0) {
std::string value_str = query->std_str();
if (!ValidationUtil::ValidateStringIsBool(value_str).ok()) {
return Status(ILLEGAL_QUERY_PARAM, "Query param \'all_required\' must be a bool");
}
value = value_str == "True" || value_str == "true";
return Status::OK();
}
if (!nullable) {
return Status(QUERY_PARAM_LOSS, "Query param \"" + key + "\" is required");
}
return Status::OK();
}
void
WebRequestHandler::AddStatusToJson(nlohmann::json& json, int64_t code, const std::string& msg) {
json["code"] = (int64_t)code;
@ -142,9 +162,9 @@ WebRequestHandler::ParsePartitionStat(const milvus::server::PartitionStat& par_s
}
Status
WebRequestHandler::IsBinaryTable(const std::string& table_name, bool& bin) {
WebRequestHandler::IsBinaryTable(const std::string& collection_name, bool& bin) {
TableSchema schema;
auto status = request_handler_.DescribeTable(context_ptr_, table_name, schema);
auto status = request_handler_.DescribeTable(context_ptr_, collection_name, schema);
if (status.ok()) {
auto metric = engine::MetricType(schema.metric_type_);
bin = engine::MetricType::HAMMING == metric || engine::MetricType::JACCARD == metric ||
@ -187,26 +207,26 @@ WebRequestHandler::CopyRecordsFromJson(const nlohmann::json& json, engine::Vecto
///////////////////////// WebRequestHandler methods ///////////////////////////////////////
Status
WebRequestHandler::GetTableMetaInfo(const std::string& table_name, nlohmann::json& json_out) {
WebRequestHandler::GetTableMetaInfo(const std::string& collection_name, nlohmann::json& json_out) {
TableSchema schema;
auto status = request_handler_.DescribeTable(context_ptr_, table_name, schema);
auto status = request_handler_.DescribeTable(context_ptr_, collection_name, schema);
if (!status.ok()) {
return status;
}
int64_t count;
status = request_handler_.CountTable(context_ptr_, table_name, count);
status = request_handler_.CountTable(context_ptr_, collection_name, count);
if (!status.ok()) {
return status;
}
IndexParam index_param;
status = request_handler_.DescribeIndex(context_ptr_, table_name, index_param);
status = request_handler_.DescribeIndex(context_ptr_, collection_name, index_param);
if (!status.ok()) {
return status;
}
json_out["table_name"] = schema.table_name_;
json_out["collection_name"] = schema.table_name_;
json_out["dimension"] = schema.dimension_;
json_out["index_file_size"] = schema.index_file_size_;
json_out["index"] = IndexMap.at(engine::EngineType(index_param.index_type_));
@ -218,15 +238,15 @@ WebRequestHandler::GetTableMetaInfo(const std::string& table_name, nlohmann::jso
}
Status
WebRequestHandler::GetTableStat(const std::string& table_name, nlohmann::json& json_out) {
struct TableInfo table_info;
auto status = request_handler_.ShowTableInfo(context_ptr_, table_name, table_info);
WebRequestHandler::GetTableStat(const std::string& collection_name, nlohmann::json& json_out) {
struct TableInfo collection_info;
auto status = request_handler_.ShowTableInfo(context_ptr_, collection_name, collection_info);
if (status.ok()) {
json_out["count"] = table_info.total_row_num_;
json_out["count"] = collection_info.total_row_num_;
std::vector<nlohmann::json> par_stat_json;
for (auto& par : table_info.partitions_stat_) {
for (auto& par : collection_info.partitions_stat_) {
nlohmann::json par_json;
ParsePartitionStat(par, par_json);
par_stat_json.push_back(par_json);
@ -238,10 +258,10 @@ WebRequestHandler::GetTableStat(const std::string& table_name, nlohmann::json& j
}
Status
WebRequestHandler::GetSegmentVectors(const std::string& table_name, const std::string& segment_name, int64_t page_size,
int64_t offset, nlohmann::json& json_out) {
WebRequestHandler::GetSegmentVectors(const std::string& collection_name, const std::string& segment_name,
int64_t page_size, int64_t offset, nlohmann::json& json_out) {
std::vector<int64_t> vector_ids;
auto status = request_handler_.GetVectorIDs(context_ptr_, table_name, segment_name, vector_ids);
auto status = request_handler_.GetVectorIDs(context_ptr_, collection_name, segment_name, vector_ids);
if (!status.ok()) {
return status;
}
@ -251,7 +271,7 @@ WebRequestHandler::GetSegmentVectors(const std::string& table_name, const std::s
auto ids = std::vector<int64_t>(vector_ids.begin() + ids_begin, vector_ids.begin() + ids_end);
nlohmann::json vectors_json;
status = GetVectorsByIDs(table_name, ids, vectors_json);
status = GetVectorsByIDs(collection_name, ids, vectors_json);
nlohmann::json result_json;
if (vectors_json.empty()) {
@ -267,10 +287,10 @@ WebRequestHandler::GetSegmentVectors(const std::string& table_name, const std::s
}
Status
WebRequestHandler::GetSegmentIds(const std::string& table_name, const std::string& segment_name, int64_t page_size,
WebRequestHandler::GetSegmentIds(const std::string& collection_name, const std::string& segment_name, int64_t page_size,
int64_t offset, nlohmann::json& json_out) {
std::vector<int64_t> vector_ids;
auto status = request_handler_.GetVectorIDs(context_ptr_, table_name, segment_name, vector_ids);
auto status = request_handler_.GetVectorIDs(context_ptr_, collection_name, segment_name, vector_ids);
if (status.ok()) {
auto ids_begin = std::min(vector_ids.size(), (size_t)offset);
auto ids_end = std::min(vector_ids.size(), (size_t)(offset + page_size));
@ -310,12 +330,12 @@ WebRequestHandler::Cmd(const std::string& cmd, std::string& result_str) {
Status
WebRequestHandler::PreLoadTable(const nlohmann::json& json, std::string& result_str) {
if (!json.contains("table_name")) {
return Status(BODY_FIELD_LOSS, "Field \"load\" must contains table_name");
if (!json.contains("collection_name")) {
return Status(BODY_FIELD_LOSS, "Field \"load\" must contains collection_name");
}
auto table_name = json["table_name"];
auto status = request_handler_.PreloadTable(context_ptr_, table_name.get<std::string>());
auto collection_name = json["collection_name"];
auto status = request_handler_.PreloadTable(context_ptr_, collection_name.get<std::string>());
if (status.ok()) {
nlohmann::json result;
AddStatusToJson(result, status.code(), status.message());
@ -327,17 +347,17 @@ WebRequestHandler::PreLoadTable(const nlohmann::json& json, std::string& result_
Status
WebRequestHandler::Flush(const nlohmann::json& json, std::string& result_str) {
if (!json.contains("table_names")) {
return Status(BODY_FIELD_LOSS, "Field \"flush\" must contains table_names");
if (!json.contains("collection_names")) {
return Status(BODY_FIELD_LOSS, "Field \"flush\" must contains collection_names");
}
auto table_names = json["table_names"];
if (!table_names.is_array()) {
return Status(BODY_FIELD_LOSS, "Field \"table_names\" must be and array");
auto collection_names = json["collection_names"];
if (!collection_names.is_array()) {
return Status(BODY_FIELD_LOSS, "Field \"collection_names\" must be and array");
}
std::vector<std::string> names;
for (auto& name : table_names) {
for (auto& name : collection_names) {
names.emplace_back(name.get<std::string>());
}
@ -353,16 +373,16 @@ WebRequestHandler::Flush(const nlohmann::json& json, std::string& result_str) {
Status
WebRequestHandler::Compact(const nlohmann::json& json, std::string& result_str) {
if (!json.contains("table_name")) {
return Status(BODY_FIELD_LOSS, "Field \"compact\" must contains table_names");
if (!json.contains("collection_name")) {
return Status(BODY_FIELD_LOSS, "Field \"compact\" must contains collection_names");
}
auto table_name = json["table_name"];
if (!table_name.is_string()) {
return Status(BODY_FIELD_LOSS, "Field \"table_names\" must be a string");
auto collection_name = json["collection_name"];
if (!collection_name.is_string()) {
return Status(BODY_FIELD_LOSS, "Field \"collection_names\" must be a string");
}
auto name = table_name.get<std::string>();
auto name = collection_name.get<std::string>();
auto status = request_handler_.Compact(context_ptr_, name);
@ -463,7 +483,7 @@ WebRequestHandler::SetConfig(const nlohmann::json& json, std::string& result_str
}
Status
WebRequestHandler::Search(const std::string& table_name, const nlohmann::json& json, std::string& result_str) {
WebRequestHandler::Search(const std::string& collection_name, const nlohmann::json& json, std::string& result_str) {
if (!json.contains("topk")) {
return Status(BODY_FIELD_LOSS, "Field \'topk\' is required");
}
@ -497,7 +517,7 @@ WebRequestHandler::Search(const std::string& table_name, const nlohmann::json& j
}
bool bin_flag = false;
auto status = IsBinaryTable(table_name, bin_flag);
auto status = IsBinaryTable(collection_name, bin_flag);
if (!status.ok()) {
return status;
}
@ -513,7 +533,7 @@ WebRequestHandler::Search(const std::string& table_name, const nlohmann::json& j
}
TopKQueryResult result;
status = request_handler_.Search(context_ptr_, table_name, vectors_data, topk, json["params"], partition_tags,
status = request_handler_.Search(context_ptr_, collection_name, vectors_data, topk, json["params"], partition_tags,
file_id_vec, result);
if (!status.ok()) {
@ -547,7 +567,8 @@ WebRequestHandler::Search(const std::string& table_name, const nlohmann::json& j
}
Status
WebRequestHandler::DeleteByIDs(const std::string& table_name, const nlohmann::json& json, std::string& result_str) {
WebRequestHandler::DeleteByIDs(const std::string& collection_name, const nlohmann::json& json,
std::string& result_str) {
std::vector<int64_t> vector_ids;
if (!json.contains("ids")) {
return Status(BODY_FIELD_LOSS, "Field \"delete\" must contains \"ids\"");
@ -565,7 +586,7 @@ WebRequestHandler::DeleteByIDs(const std::string& table_name, const nlohmann::js
vector_ids.emplace_back(std::stol(id_str));
}
auto status = request_handler_.DeleteByID(context_ptr_, table_name, vector_ids);
auto status = request_handler_.DeleteByID(context_ptr_, collection_name, vector_ids);
nlohmann::json result_json;
AddStatusToJson(result_json, status.code(), status.message());
@ -575,13 +596,13 @@ WebRequestHandler::DeleteByIDs(const std::string& table_name, const nlohmann::js
}
Status
WebRequestHandler::GetVectorsByIDs(const std::string& table_name, const std::vector<int64_t>& ids,
WebRequestHandler::GetVectorsByIDs(const std::string& collection_name, const std::vector<int64_t>& ids,
nlohmann::json& json_out) {
std::vector<engine::VectorsData> vector_batch;
for (size_t i = 0; i < ids.size(); i++) {
auto vec_ids = std::vector<int64_t>(ids.begin() + i, ids.begin() + i + 1);
engine::VectorsData vectors_data;
auto status = request_handler_.GetVectorByID(context_ptr_, table_name, vec_ids, vectors_data);
auto status = request_handler_.GetVectorByID(context_ptr_, collection_name, vec_ids, vectors_data);
if (!status.ok()) {
return status;
}
@ -589,7 +610,7 @@ WebRequestHandler::GetVectorsByIDs(const std::string& table_name, const std::vec
}
bool bin;
auto status = IsBinaryTable(table_name, bin);
auto status = IsBinaryTable(collection_name, bin);
if (!status.ok()) {
return status;
}
@ -879,30 +900,31 @@ WebRequestHandler::SetGpuConfig(const GPUConfigDto::ObjectWrapper& gpu_config_dt
* Table {
*/
StatusDto::ObjectWrapper
WebRequestHandler::CreateTable(const TableRequestDto::ObjectWrapper& table_schema) {
if (nullptr == table_schema->table_name.get()) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Field \'table_name\' is missing")
WebRequestHandler::CreateTable(const TableRequestDto::ObjectWrapper& collection_schema) {
if (nullptr == collection_schema->collection_name.get()) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Field \'collection_name\' is missing")
}
if (nullptr == table_schema->dimension.get()) {
if (nullptr == collection_schema->dimension.get()) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Field \'dimension\' is missing")
}
if (nullptr == table_schema->index_file_size.get()) {
if (nullptr == collection_schema->index_file_size.get()) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Field \'index_file_size\' is missing")
}
if (nullptr == table_schema->metric_type.get()) {
if (nullptr == collection_schema->metric_type.get()) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Field \'metric_type\' is missing")
}
if (MetricNameMap.find(table_schema->metric_type->std_str()) == MetricNameMap.end()) {
if (MetricNameMap.find(collection_schema->metric_type->std_str()) == MetricNameMap.end()) {
RETURN_STATUS_DTO(ILLEGAL_METRIC_TYPE, "metric_type is illegal")
}
auto status = request_handler_.CreateTable(
context_ptr_, table_schema->table_name->std_str(), table_schema->dimension, table_schema->index_file_size,
static_cast<int64_t>(MetricNameMap.at(table_schema->metric_type->std_str())));
auto status =
request_handler_.CreateTable(context_ptr_, collection_schema->collection_name->std_str(),
collection_schema->dimension, collection_schema->index_file_size,
static_cast<int64_t>(MetricNameMap.at(collection_schema->metric_type->std_str())));
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -926,45 +948,41 @@ WebRequestHandler::ShowTables(const OQueryParams& query_params, OString& result)
}
bool all_required = false;
auto required = query_params.get("all_required");
if (nullptr != required.get()) {
auto required_str = required->std_str();
if (!ValidationUtil::ValidateStringIsBool(required_str).ok()) {
RETURN_STATUS_DTO(ILLEGAL_QUERY_PARAM, "Query param \'all_required\' must be a bool")
}
all_required = required_str == "True" || required_str == "true";
ParseQueryBool(query_params, "all_required", all_required);
if (!status.ok()) {
RETURN_STATUS_DTO(status.code(), status.message().c_str());
}
std::vector<std::string> tables;
status = request_handler_.ShowTables(context_ptr_, tables);
std::vector<std::string> collections;
status = request_handler_.ShowTables(context_ptr_, collections);
if (!status.ok()) {
ASSIGN_RETURN_STATUS_DTO(status)
}
if (all_required) {
offset = 0;
page_size = tables.size();
page_size = collections.size();
} else {
offset = std::min((size_t)offset, tables.size());
page_size = std::min(tables.size() - offset, (size_t)page_size);
offset = std::min((size_t)offset, collections.size());
page_size = std::min(collections.size() - offset, (size_t)page_size);
}
nlohmann::json tables_json;
nlohmann::json collections_json;
for (int64_t i = offset; i < page_size + offset; i++) {
nlohmann::json table_json;
status = GetTableMetaInfo(tables.at(i), table_json);
nlohmann::json collection_json;
status = GetTableMetaInfo(collections.at(i), collection_json);
if (!status.ok()) {
ASSIGN_RETURN_STATUS_DTO(status)
}
tables_json.push_back(table_json);
collections_json.push_back(collection_json);
}
nlohmann::json result_json;
result_json["count"] = tables.size();
if (tables_json.empty()) {
result_json["tables"] = std::vector<int64_t>();
result_json["count"] = collections.size();
if (collections_json.empty()) {
result_json["collections"] = std::vector<int64_t>();
} else {
result_json["tables"] = tables_json;
result_json["collections"] = collections_json;
}
result = result_json.dump().c_str();
@ -973,9 +991,9 @@ WebRequestHandler::ShowTables(const OQueryParams& query_params, OString& result)
}
StatusDto::ObjectWrapper
WebRequestHandler::GetTable(const OString& table_name, const OQueryParams& query_params, OString& result) {
if (nullptr == table_name.get()) {
RETURN_STATUS_DTO(PATH_PARAM_LOSS, "Path param \'table_name\' is required!");
WebRequestHandler::GetTable(const OString& collection_name, const OQueryParams& query_params, OString& result) {
if (nullptr == collection_name.get()) {
RETURN_STATUS_DTO(PATH_PARAM_LOSS, "Path param \'collection_name\' is required!");
}
std::string stat;
@ -986,11 +1004,11 @@ WebRequestHandler::GetTable(const OString& table_name, const OQueryParams& query
if (!stat.empty() && stat == "stat") {
nlohmann::json json;
status = GetTableStat(table_name->std_str(), json);
status = GetTableStat(collection_name->std_str(), json);
result = status.ok() ? json.dump().c_str() : "NULL";
} else {
nlohmann::json json;
status = GetTableMetaInfo(table_name->std_str(), json);
status = GetTableMetaInfo(collection_name->std_str(), json);
result = status.ok() ? json.dump().c_str() : "NULL";
}
@ -998,8 +1016,8 @@ WebRequestHandler::GetTable(const OString& table_name, const OQueryParams& query
}
StatusDto::ObjectWrapper
WebRequestHandler::DropTable(const OString& table_name) {
auto status = request_handler_.DropTable(context_ptr_, table_name->std_str());
WebRequestHandler::DropTable(const OString& collection_name) {
auto status = request_handler_.DropTable(context_ptr_, collection_name->std_str());
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -1035,9 +1053,9 @@ WebRequestHandler::CreateIndex(const OString& table_name, const OString& body) {
}
StatusDto::ObjectWrapper
WebRequestHandler::GetIndex(const OString& table_name, OString& result) {
WebRequestHandler::GetIndex(const OString& collection_name, OString& result) {
IndexParam param;
auto status = request_handler_.DescribeIndex(context_ptr_, table_name->std_str(), param);
auto status = request_handler_.DescribeIndex(context_ptr_, collection_name->std_str(), param);
if (status.ok()) {
nlohmann::json json_out;
@ -1051,8 +1069,8 @@ WebRequestHandler::GetIndex(const OString& table_name, OString& result) {
}
StatusDto::ObjectWrapper
WebRequestHandler::DropIndex(const OString& table_name) {
auto status = request_handler_.DropIndex(context_ptr_, table_name->std_str());
WebRequestHandler::DropIndex(const OString& collection_name) {
auto status = request_handler_.DropIndex(context_ptr_, collection_name->std_str());
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -1062,19 +1080,19 @@ WebRequestHandler::DropIndex(const OString& table_name) {
* Partition {
*/
StatusDto::ObjectWrapper
WebRequestHandler::CreatePartition(const OString& table_name, const PartitionRequestDto::ObjectWrapper& param) {
WebRequestHandler::CreatePartition(const OString& collection_name, const PartitionRequestDto::ObjectWrapper& param) {
if (nullptr == param->partition_tag.get()) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Field \'partition_tag\' is required")
}
auto status =
request_handler_.CreatePartition(context_ptr_, table_name->std_str(), param->partition_tag->std_str());
request_handler_.CreatePartition(context_ptr_, collection_name->std_str(), param->partition_tag->std_str());
ASSIGN_RETURN_STATUS_DTO(status)
}
StatusDto::ObjectWrapper
WebRequestHandler::ShowPartitions(const OString& table_name, const OQueryParams& query_params,
WebRequestHandler::ShowPartitions(const OString& collection_name, const OQueryParams& query_params,
PartitionListDto::ObjectWrapper& partition_list_dto) {
int64_t offset = 0;
auto status = ParseQueryInteger(query_params, "offset", offset);
@ -1104,7 +1122,7 @@ WebRequestHandler::ShowPartitions(const OString& table_name, const OQueryParams&
}
std::vector<PartitionParam> partitions;
status = request_handler_.ShowPartitions(context_ptr_, table_name->std_str(), partitions);
status = request_handler_.ShowPartitions(context_ptr_, collection_name->std_str(), partitions);
if (!status.ok()) {
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -1132,7 +1150,7 @@ WebRequestHandler::ShowPartitions(const OString& table_name, const OQueryParams&
}
StatusDto::ObjectWrapper
WebRequestHandler::DropPartition(const OString& table_name, const OString& body) {
WebRequestHandler::DropPartition(const OString& collection_name, const OString& body) {
std::string tag;
try {
auto json = nlohmann::json::parse(body->std_str());
@ -1142,7 +1160,7 @@ WebRequestHandler::DropPartition(const OString& table_name, const OString& body)
} catch (nlohmann::detail::type_error& e) {
RETURN_STATUS_DTO(BODY_PARSE_FAIL, e.what())
}
auto status = request_handler_.DropPartition(context_ptr_, table_name->std_str(), tag);
auto status = request_handler_.DropPartition(context_ptr_, collection_name->std_str(), tag);
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -1152,7 +1170,7 @@ WebRequestHandler::DropPartition(const OString& table_name, const OString& body)
* Segment {
*/
StatusDto::ObjectWrapper
WebRequestHandler::ShowSegments(const OString& table_name, const OQueryParams& query_params, OString& response) {
WebRequestHandler::ShowSegments(const OString& collection_name, const OQueryParams& query_params, OString& response) {
int64_t offset = 0;
auto status = ParseQueryInteger(query_params, "offset", offset);
if (!status.ok()) {
@ -1185,7 +1203,7 @@ WebRequestHandler::ShowSegments(const OString& table_name, const OQueryParams& q
}
TableInfo info;
status = request_handler_.ShowTableInfo(context_ptr_, table_name->std_str(), info);
status = request_handler_.ShowTableInfo(context_ptr_, collection_name->std_str(), info);
if (!status.ok()) {
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -1236,7 +1254,7 @@ WebRequestHandler::ShowSegments(const OString& table_name, const OQueryParams& q
}
StatusDto::ObjectWrapper
WebRequestHandler::GetSegmentInfo(const OString& table_name, const OString& segment_name, const OString& info,
WebRequestHandler::GetSegmentInfo(const OString& collection_name, const OString& segment_name, const OString& info,
const OQueryParams& query_params, OString& result) {
int64_t offset = 0;
auto status = ParseQueryInteger(query_params, "offset", offset);
@ -1260,10 +1278,10 @@ WebRequestHandler::GetSegmentInfo(const OString& table_name, const OString& segm
nlohmann::json json;
// Get vectors
if (re == "vectors") {
status = GetSegmentVectors(table_name->std_str(), segment_name->std_str(), page_size, offset, json);
status = GetSegmentVectors(collection_name->std_str(), segment_name->std_str(), page_size, offset, json);
// Get vector ids
} else if (re == "ids") {
status = GetSegmentIds(table_name->std_str(), segment_name->std_str(), page_size, offset, json);
status = GetSegmentIds(collection_name->std_str(), segment_name->std_str(), page_size, offset, json);
}
result = status.ok() ? json.dump().c_str() : "NULL";
@ -1276,14 +1294,14 @@ WebRequestHandler::GetSegmentInfo(const OString& table_name, const OString& segm
* Vector {
*/
StatusDto::ObjectWrapper
WebRequestHandler::Insert(const OString& table_name, const OString& body, VectorIdsDto::ObjectWrapper& ids_dto) {
WebRequestHandler::Insert(const OString& collection_name, const OString& body, VectorIdsDto::ObjectWrapper& ids_dto) {
if (nullptr == body.get() || body->getSize() == 0) {
RETURN_STATUS_DTO(BODY_FIELD_LOSS, "Request payload is required.")
}
// step 1: copy vectors
bool bin_flag;
auto status = IsBinaryTable(table_name->std_str(), bin_flag);
auto status = IsBinaryTable(collection_name->std_str(), bin_flag);
if (!status.ok()) {
ASSIGN_RETURN_STATUS_DTO(status)
}
@ -1318,7 +1336,7 @@ WebRequestHandler::Insert(const OString& table_name, const OString& body, Vector
}
// step 4: construct result
status = request_handler_.Insert(context_ptr_, table_name->std_str(), vectors, tag);
status = request_handler_.Insert(context_ptr_, collection_name->std_str(), vectors, tag);
if (status.ok()) {
ids_dto->ids = ids_dto->ids->createShared();
for (auto& id : vectors.id_array_) {
@ -1330,7 +1348,7 @@ WebRequestHandler::Insert(const OString& table_name, const OString& body, Vector
}
StatusDto::ObjectWrapper
WebRequestHandler::GetVector(const OString& table_name, const OQueryParams& query_params, OString& response) {
WebRequestHandler::GetVector(const OString& collection_name, const OQueryParams& query_params, OString& response) {
int64_t id = 0;
auto status = ParseQueryInteger(query_params, "id", id, false);
if (!status.ok()) {
@ -1340,7 +1358,7 @@ WebRequestHandler::GetVector(const OString& table_name, const OQueryParams& quer
std::vector<int64_t> ids = {id};
engine::VectorsData vectors;
nlohmann::json vectors_json;
status = GetVectorsByIDs(table_name->std_str(), ids, vectors_json);
status = GetVectorsByIDs(collection_name->std_str(), ids, vectors_json);
if (!status.ok()) {
response = "NULL";
ASSIGN_RETURN_STATUS_DTO(status)
@ -1360,7 +1378,7 @@ WebRequestHandler::GetVector(const OString& table_name, const OQueryParams& quer
}
StatusDto::ObjectWrapper
WebRequestHandler::VectorsOp(const OString& table_name, const OString& payload, OString& response) {
WebRequestHandler::VectorsOp(const OString& collection_name, const OString& payload, OString& response) {
auto status = Status::OK();
std::string result_str;
@ -1368,9 +1386,9 @@ WebRequestHandler::VectorsOp(const OString& table_name, const OString& payload,
nlohmann::json payload_json = nlohmann::json::parse(payload->std_str());
if (payload_json.contains("delete")) {
status = DeleteByIDs(table_name->std_str(), payload_json["delete"], result_str);
status = DeleteByIDs(collection_name->std_str(), payload_json["delete"], result_str);
} else if (payload_json.contains("search")) {
status = Search(table_name->std_str(), payload_json["search"], result_str);
status = Search(collection_name->std_str(), payload_json["search"], result_str);
} else {
status = Status(ILLEGAL_BODY, "Unknown body");
}

View File

@ -84,6 +84,9 @@ class WebRequestHandler {
Status
ParseQueryStr(const OQueryParams& query_params, const std::string& key, std::string& value, bool nullable = true);
Status
ParseQueryBool(const OQueryParams& query_params, const std::string& key, bool& value, bool nullable = true);
private:
void
AddStatusToJson(nlohmann::json& json, int64_t code, const std::string& msg);

View File

@ -12,9 +12,12 @@
#include "utils/StringHelpFunctions.h"
#include <fiu-local.h>
#include <algorithm>
#include <regex>
#include <string>
#include "utils/ValidationUtil.h"
namespace milvus {
namespace server {
@ -148,11 +151,21 @@ StringHelpFunctions::IsRegexMatch(const std::string& target_str, const std::stri
// regex match
std::regex pattern(pattern_str);
std::smatch results;
if (std::regex_match(target_str, results, pattern)) {
return true;
} else {
return false;
return std::regex_match(target_str, results, pattern);
}
Status
StringHelpFunctions::ConvertToBoolean(const std::string& str, bool& value) {
auto status = ValidationUtil::ValidateStringIsBool(str);
if (!status.ok()) {
return status;
}
std::string s = str;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
value = s == "true" || s == "on" || s == "yes" || s == "1";
return Status::OK();
}
} // namespace server

View File

@ -64,6 +64,12 @@ class StringHelpFunctions {
// regex grammar reference: http://www.cplusplus.com/reference/regex/ECMAScript/
static bool
IsRegexMatch(const std::string& target_str, const std::string& pattern);
// conversion rules refer to ValidationUtil::ValidateStringIsBool()
// "true", "on", "yes", "1" ==> true
// "false", "off", "no", "0", "" ==> false
static Status
ConvertToBoolean(const std::string& str, bool& value);
};
} // namespace server

File diff suppressed because it is too large Load Diff