Skip to content

Commit

Permalink
Merge branch 'main' into use-latest-arrow-version
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanglei1949 authored Aug 22, 2024
2 parents 91cab05 + 890b7ec commit 29bda85
Show file tree
Hide file tree
Showing 40 changed files with 1,277 additions and 614 deletions.
34 changes: 16 additions & 18 deletions docs/flex/interactive/development/dev_and_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,27 +214,25 @@ The Compiler service could be started as a subprocess of the AdminService. This
```


### Mapping of Internal Code to Http Error Code
### Error Code

Runtime errors are categorized, assigned an error code, and included in the HTTP response body (only for non-200 HTTP responses).
The mapping between status codes and HTTP codes is shown in the table below.

Internally we use [`StatusCode`](https://github.com/alibaba/GraphScope/blob/main/flex/utils/result.h) to record the runtime errors.
The mapping between statusCode and http code is shown in the following table.

| Code | HTTP Code |
| ----------------------------------- | ----------- |
| gs::StatusCode::OK | 200 |
| gs::StatusCode::InValidArgument | 400 |
| gs::StatusCode::UnsupportedOperator | 400 |
| gs::StatusCode::AlreadyExists | 409 |
| gs::StatusCode::NotExists | 404 |
| gs::StatusCode::CodegenError | 500 |
| gs::StatusCode::UninitializedStatus | 500 |
| gs::StatusCode::InvalidSchema | 400 |
| gs::StatusCode::PermissionError | 403 |
| gs::StatusCode::IllegalOperation | 400 |
| gs::StatusCode::InternalError | 500 |
| gs::StatusCode::InvalidImportFile | 400 |
| gs::StatusCode::IOError | 500 |
| gs::StatusCode::NotFound | 404 |
| gs::StatusCode::QueryFailed | 500 |
| OK(0) | 200 |
| INVALID_ARGUMENT(2) | 400 |
| UNSUPPORTED_OPERATION(11) | 400 |
| NOT_FOUND(4) | 404 |
| ALREADY_EXISTS(5) | 409 |
| PERMISSION_DENIED(8) | 403 |
| CODEGEN_ERROR(100) | 500 |
| INVALID_SCHEMA(101) | 400 |
| ILLEGAL_OPERATION(102) | 400 |
| INTERNAL_ERROR(103) | 500 |
| INVALID_IMPORT_FILE(104) | 400 |
| IO_ERROR(105) | 500 |
| QUERY_FAILED(106) | 500 |
| default | 500 |
4 changes: 2 additions & 2 deletions flex/engines/graph_db/database/graph_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ Result<bool> GraphDB::Open(const GraphDBConfig& config) {
graph_.Open(data_dir, config.memory_level);
} catch (std::exception& e) {
LOG(ERROR) << "Exception: " << e.what();
return Result<bool>(StatusCode::InternalError,
return Result<bool>(StatusCode::INTERNAL_ERROR,
"Exception: " + std::string(e.what()), false);
}

if ((!create_empty_graph) && (!graph_.schema().Equals(schema))) {
LOG(ERROR) << "Schema inconsistent..\n";
return Result<bool>(StatusCode::InternalError,
return Result<bool>(StatusCode::INTERNAL_ERROR,
"Schema of work directory is not compatible with the "
"graph schema",
false);
Expand Down
66 changes: 38 additions & 28 deletions flex/engines/graph_db/database/graph_db_operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Result<std::string> GraphDBOperations::CreateVertex(
(input_json.contains("edge_request") == true &&
input_json["edge_request"].is_array() == false)) {
return Result<std::string>(
StatusCode::InvalidSchema,
StatusCode::INVALID_SCHEMA,
"Invalid input json, vertex_request and edge_request should be array "
"and not empty");
}
Expand All @@ -55,7 +55,7 @@ Result<std::string> GraphDBOperations::CreateVertex(
}
} catch (std::exception& e) {
return Result<std::string>(
StatusCode::InvalidSchema,
StatusCode::INVALID_SCHEMA,
" Bad input parameter : " + std::string(e.what()));
}
auto insert_result =
Expand All @@ -74,7 +74,7 @@ Result<std::string> GraphDBOperations::CreateEdge(GraphDBSession& session,
// Check if the input json contains edge_request
if (input_json.is_array() == false || input_json.size() == 0) {
return Result<std::string>(
StatusCode::InvalidSchema,
StatusCode::INVALID_SCHEMA,
"Invalid input json, edge_request should be array and not empty");
}
const Schema& schema = session.schema();
Expand All @@ -85,7 +85,7 @@ Result<std::string> GraphDBOperations::CreateEdge(GraphDBSession& session,
}
} catch (std::exception& e) {
return Result<std::string>(
StatusCode::InvalidSchema,
StatusCode::INVALID_SCHEMA,
" Bad input parameter : " + std::string(e.what()));
}
auto insert_result = insertEdge(std::move(edge_data), session);
Expand All @@ -106,7 +106,7 @@ Result<std::string> GraphDBOperations::UpdateVertex(
vertex_data.push_back(inputVertex(input_json, schema, session));
} catch (std::exception& e) {
return Result<std::string>(
StatusCode::InvalidSchema,
StatusCode::INVALID_SCHEMA,
" Bad input parameter : " + std::string(e.what()));
}
auto update_result = updateVertex(std::move(vertex_data), session);
Expand All @@ -127,7 +127,7 @@ Result<std::string> GraphDBOperations::UpdateEdge(GraphDBSession& session,
edge_data.push_back(inputEdge(input_json, schema, session));
} catch (std::exception& e) {
return Result<std::string>(
StatusCode::InvalidSchema,
StatusCode::INVALID_SCHEMA,
" Bad input parameter : " + std::string(e.what()));
}
auto update_result = updateEdge(std::move(edge_data), session);
Expand Down Expand Up @@ -192,6 +192,10 @@ Result<std::string> GraphDBOperations::GetEdge(
result["edge_label"] = edge_label;
result["src_primary_key_value"] = src_pk_value;
result["dst_primary_key_value"] = dst_pk_value;
if (property_name.empty()) {
result["properties"] = nlohmann::json::array();
return Result<std::string>(result.dump());
}
auto get_result = getEdge(std::move(edge_data), property_name, session);
if (get_result.ok()) {
result["properties"] = get_result.value();
Expand All @@ -202,13 +206,13 @@ Result<std::string> GraphDBOperations::GetEdge(
Result<std::string> GraphDBOperations::DeleteVertex(
GraphDBSession& session, nlohmann::json&& input_json) {
// not implemented
return Result<std::string>(StatusCode::Unimplemented,
return Result<std::string>(StatusCode::UNIMPLEMENTED,
"delete_vertex is not implemented");
}
Result<std::string> GraphDBOperations::DeleteEdge(GraphDBSession& session,
nlohmann::json&& input_json) {
// not implemented
return Result<std::string>(StatusCode::Unimplemented,
return Result<std::string>(StatusCode::UNIMPLEMENTED,
"delete_edge is not implemented");
}

Expand Down Expand Up @@ -249,12 +253,15 @@ EdgeData GraphDBOperations::inputEdge(const nlohmann::json& edge_json,
edge.src_pk_value = Any(jsonToString(edge_json["src_primary_key_value"]));
edge.dst_pk_value = Any(jsonToString(edge_json["dst_primary_key_value"]));
// Check that all parameters in the parameter
if (edge_json["properties"].size() != 1) {
if (edge_json["properties"].size() > 1) {
throw std::runtime_error(
"size should be 1(only support single property edge)");
}
edge.property_value = Any(jsonToString(edge_json["properties"][0]["value"]));
std::string property_name = edge_json["properties"][0]["name"];
std::string property_name = "";
if (edge_json["properties"].size() == 1) {
edge.property_value = Any(jsonToString(edge_json["properties"][0]["value"]));
property_name = edge_json["properties"][0]["name"];
}
auto check_result = checkEdgeSchema(schema, edge, src_label, dst_label,
edge_label, property_name);
if (check_result.ok() == false) {
Expand Down Expand Up @@ -291,7 +298,7 @@ Status GraphDBOperations::checkVertexSchema(
}
return Status::OK();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema,
return Status(StatusCode::INVALID_SCHEMA,
" Bad input parameter : " + std::string(e.what()));
}
}
Expand All @@ -305,14 +312,17 @@ Status GraphDBOperations::checkEdgeSchema(const Schema& schema, EdgeData& edge,
edge.src_label_id = schema.get_vertex_label_id(src_label);
edge.dst_label_id = schema.get_vertex_label_id(dst_label);
edge.edge_label_id = schema.get_edge_label_id(edge_label);
auto &result = schema.get_edge_property_names(edge.src_label_id, edge.dst_label_id,
edge.edge_label_id);
if (is_get) {
property_name = schema.get_edge_property_names(
edge.src_label_id, edge.dst_label_id, edge.edge_label_id)[0];
if (result.size() >= 1) {
property_name = result[0];
} else {
property_name = "";
}
} else {
// update or add
if (property_name !=
schema.get_edge_property_names(edge.src_label_id, edge.dst_label_id,
edge.edge_label_id)[0]) {
if (property_name != (result.size() >= 1 ? result[0] : "")) {
throw std::runtime_error("property name not match");
}
PropertyType colType = schema.get_edge_property(
Expand All @@ -328,7 +338,7 @@ Status GraphDBOperations::checkEdgeSchema(const Schema& schema, EdgeData& edge,
std::get<0>(schema.get_vertex_primary_key(edge.dst_label_id)[0]));
return Status::OK();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema,
return Status(StatusCode::INVALID_SCHEMA,
" Bad input parameter : " + std::string(e.what()));
}
}
Expand Down Expand Up @@ -358,7 +368,7 @@ Status GraphDBOperations::checkEdgeExistsWithInsert(
}
}
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand Down Expand Up @@ -388,7 +398,7 @@ Status GraphDBOperations::checkEdgeExists(
}
}
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand All @@ -407,7 +417,7 @@ Status GraphDBOperations::checkVertexExists(
}
txn.Commit();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand Down Expand Up @@ -435,7 +445,7 @@ Status GraphDBOperations::singleInsertVertex(
}
txnWrite.Commit();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand Down Expand Up @@ -464,7 +474,7 @@ Status GraphDBOperations::multiInsert(std::vector<VertexData>&& vertex_data,
}
txnWrite.Commit();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand Down Expand Up @@ -502,7 +512,7 @@ Status GraphDBOperations::singleInsertEdge(std::vector<EdgeData>&& edge_data,
}
txnWrite.Commit();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand Down Expand Up @@ -543,7 +553,7 @@ Status GraphDBOperations::updateVertex(std::vector<VertexData>&& vertex_data,
}
txnWrite.Commit();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand Down Expand Up @@ -580,7 +590,7 @@ Status GraphDBOperations::updateEdge(std::vector<EdgeData>&& edge_data,
dst_vid, edge.edge_label_id, edge.property_value);
txn2.Commit();
} catch (std::exception& e) {
return Status(StatusCode::InvalidSchema, e.what());
return Status(StatusCode::INVALID_SCHEMA, e.what());
}
return Status::OK();
}
Expand All @@ -606,7 +616,7 @@ Result<nlohmann::json> GraphDBOperations::getVertex(
txn.Commit();
return Result<nlohmann::json>(result);
} catch (std::exception& e) {
return Result<nlohmann::json>(Status(StatusCode::InvalidSchema, e.what()));
return Result<nlohmann::json>(Status(StatusCode::INVALID_SCHEMA, e.what()));
}
}

Expand Down Expand Up @@ -643,7 +653,7 @@ Result<nlohmann::json> GraphDBOperations::getEdge(
txn.Commit();
return Result<nlohmann::json>(result);
} catch (std::exception& e) {
return Result<nlohmann::json>(Status(StatusCode::InvalidSchema, e.what()));
return Result<nlohmann::json>(Status(StatusCode::INVALID_SCHEMA, e.what()));
}
}

Expand Down
16 changes: 8 additions & 8 deletions flex/engines/graph_db/database/graph_db_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Result<std::vector<char>> GraphDBSession::Eval(const std::string& input) {

if (input.size() < 2) {
return Result<std::vector<char>>(
StatusCode::InValidArgument,
StatusCode::INVALID_ARGUMENT,
"Invalid input, input size: " + std::to_string(input.size()),
std::vector<char>());
}
Expand All @@ -134,7 +134,7 @@ Result<std::vector<char>> GraphDBSession::Eval(const std::string& input) {
AppBase* app = GetApp(type);
if (!app) {
return Result<std::vector<char>>(
StatusCode::NotFound,
StatusCode::NOT_FOUND,
"Procedure not found, id:" + std::to_string((int) type), result_buffer);
}

Expand Down Expand Up @@ -167,7 +167,7 @@ Result<std::vector<char>> GraphDBSession::Eval(const std::string& input) {
.count());
++query_num_;
return Result<std::vector<char>>(
StatusCode::QueryFailed,
StatusCode::QUERY_FAILED,
"Query failed for procedure id:" + std::to_string((int) type),
result_buffer);
}
Expand Down Expand Up @@ -237,15 +237,15 @@ GraphDBSession::parse_query_type_from_cypher_json(
} catch (const nlohmann::json::parse_error& e) {
LOG(ERROR) << "Fail to parse json from input content: " << e.what();
return Result<std::pair<uint8_t, std::string_view>>(gs::Status(
StatusCode::InternalError,
StatusCode::INTERNAL_ERROR,
"Fail to parse json from input content:" + std::string(e.what())));
}
auto query_name = j["query_name"].get<std::string>();
const auto& app_name_to_path_index = schema().GetPlugins();
if (app_name_to_path_index.count(query_name) <= 0) {
LOG(ERROR) << "Query name is not registered: " << query_name;
return Result<std::pair<uint8_t, std::string_view>>(gs::Status(
StatusCode::NotFound, "Query name is not registered: " + query_name));
StatusCode::NOT_FOUND, "Query name is not registered: " + query_name));
}
if (j.contains("arguments")) {
for (auto& arg : j["arguments"]) {
Expand All @@ -263,19 +263,19 @@ GraphDBSession::parse_query_type_from_cypher_internal(
if (!cur_query.ParseFromArray(str_view.data(), str_view.size())) {
LOG(ERROR) << "Fail to parse query from input content";
return Result<std::pair<uint8_t, std::string_view>>(gs::Status(
StatusCode::InternalError, "Fail to parse query from input content"));
StatusCode::INTERNAL_ERROR, "Fail to parse query from input content"));
}
auto query_name = cur_query.query_name().name();
if (query_name.empty()) {
LOG(ERROR) << "Query name is empty";
return Result<std::pair<uint8_t, std::string_view>>(
gs::Status(StatusCode::NotFound, "Query name is empty"));
gs::Status(StatusCode::NOT_FOUND, "Query name is empty"));
}
const auto& app_name_to_path_index = schema().GetPlugins();
if (app_name_to_path_index.count(query_name) <= 0) {
LOG(ERROR) << "Query name is not registered: " << query_name;
return Result<std::pair<uint8_t, std::string_view>>(gs::Status(
StatusCode::NotFound, "Query name is not registered: " + query_name));
StatusCode::NOT_FOUND, "Query name is not registered: " + query_name));
}
return std::make_pair(app_name_to_path_index.at(query_name).second, str_view);
}
Expand Down
2 changes: 1 addition & 1 deletion flex/engines/graph_db/database/graph_db_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class GraphDBSession {

} else {
return Result<std::pair<uint8_t, std::string_view>>(
gs::Status(StatusCode::InValidArgument,
gs::Status(StatusCode::INVALID_ARGUMENT,
"Invalid input tag: " + std::to_string(input_tag)));
}
}
Expand Down
Loading

0 comments on commit 29bda85

Please sign in to comment.