summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoruzhas <[email protected]>2022-09-20 16:38:56 +0300
committeruzhas <[email protected]>2022-09-20 16:38:56 +0300
commitd0052234ac49197133b2a0249c1e95cea8adca59 (patch)
tree8100d9791e3c12b2af17ac90eb0a9e18fefc1872
parent61c28b2874402d529f3401d4715ce66cd86d420a (diff)
fq public HTTP API lib, rework error structure
-rw-r--r--ydb/core/public_http/CMakeLists.txt3
-rw-r--r--ydb/core/public_http/fq_handlers.h54
-rw-r--r--ydb/core/public_http/protos/CMakeLists.txt32
-rw-r--r--ydb/core/public_http/protos/fq.proto105
4 files changed, 166 insertions, 28 deletions
diff --git a/ydb/core/public_http/CMakeLists.txt b/ydb/core/public_http/CMakeLists.txt
index 80ab96584fb..5470a8ce84b 100644
--- a/ydb/core/public_http/CMakeLists.txt
+++ b/ydb/core/public_http/CMakeLists.txt
@@ -6,6 +6,7 @@
# original buildsystem will not be accepted.
+add_subdirectory(protos)
add_library(ydb-core-public_http)
target_compile_options(ydb-core-public_http PRIVATE
@@ -21,8 +22,8 @@ target_link_libraries(ydb-core-public_http PUBLIC
ydb-core-http_proxy
core-grpc_services-local_rpc
ydb-core-protos
+ core-public_http-protos
core-viewer-json
- core-viewer-protos
yq-libs-result_formatter
yql-public-issue
)
diff --git a/ydb/core/public_http/fq_handlers.h b/ydb/core/public_http/fq_handlers.h
index ff3aeaf2d85..9670b331069 100644
--- a/ydb/core/public_http/fq_handlers.h
+++ b/ydb/core/public_http/fq_handlers.h
@@ -7,7 +7,7 @@
#include <ydb/core/protos/services.pb.h>
#include <ydb/core/grpc_services/grpc_request_proxy.h>
#include <ydb/core/grpc_services/service_yq.h>
-#include <ydb/core/viewer/protos/fq.pb.h>
+#include <ydb/core/public_http/protos/fq.pb.h>
#include <ydb/core/yq/libs/result_formatter/result_formatter.h>
namespace NKikimr::NPublicHttp {
@@ -53,9 +53,9 @@ void FqConvert(const RepeatedPtrField<T>& src, RepeatedPtrField<U>& dst) {
}
}
-void FqConvert(const Ydb::Operations::Operation& src, FederatedQueryHttp::Error& dst) {
- SIMPLE_COPY_FIELD(status);
- SIMPLE_COPY_MUTABLE_FIELD(issues);
+void FqConvert(const Ydb::Operations::Operation& src, FQHttp::Error& dst) {
+ SIMPLE_COPY_RENAME_FIELD(status, message);
+ SIMPLE_COPY_MUTABLE_RENAME_FIELD(issues, details);
}
#define FQ_CONVERT_QUERY_CONTENT(srcType, dstType) \
@@ -66,10 +66,10 @@ void FqConvert(const srcType& src, dstType& dst) { \
SIMPLE_COPY_FIELD(description); \
}
-FQ_CONVERT_QUERY_CONTENT(FederatedQueryHttp::CreateQueryRequest, YandexQuery::QueryContent);
-FQ_CONVERT_QUERY_CONTENT(YandexQuery::QueryContent, FederatedQueryHttp::GetQueryResult);
+FQ_CONVERT_QUERY_CONTENT(FQHttp::CreateQueryRequest, YandexQuery::QueryContent);
+FQ_CONVERT_QUERY_CONTENT(YandexQuery::QueryContent, FQHttp::GetQueryResult);
-void FqConvert(const FederatedQueryHttp::CreateQueryRequest& src, YandexQuery::CreateQueryRequest& dst) {
+void FqConvert(const FQHttp::CreateQueryRequest& src, YandexQuery::CreateQueryRequest& dst) {
FqConvert(src, *dst.mutable_content());
dst.set_execute_mode(YandexQuery::RUN);
@@ -86,43 +86,43 @@ void FqConvert(const FederatedQueryHttp::CreateQueryRequest& src, YandexQuery::C
content.set_automatic(true);
}
-void FqConvert(const YandexQuery::CreateQueryResult& src, FederatedQueryHttp::CreateQueryResult& dst) {
+void FqConvert(const YandexQuery::CreateQueryResult& src, FQHttp::CreateQueryResult& dst) {
SIMPLE_COPY_RENAME_FIELD(query_id, id);
}
-void FqConvert(const YandexQuery::CommonMeta& src, FederatedQueryHttp::QueryMeta& dst) {
+void FqConvert(const YandexQuery::CommonMeta& src, FQHttp::QueryMeta& dst) {
SIMPLE_COPY_MUTABLE_FIELD(created_at);
}
-void FqConvert(const YandexQuery::QueryMeta& src, FederatedQueryHttp::QueryMeta& dst) {
+void FqConvert(const YandexQuery::QueryMeta& src, FQHttp::QueryMeta& dst) {
SIMPLE_COPY_MUTABLE_FIELD(submitted_at);
SIMPLE_COPY_MUTABLE_FIELD(finished_at);
FqConvert(src.common(), dst);
}
-FederatedQueryHttp::GetQueryResult::ComputeStatus RemapQueryStatus(YandexQuery::QueryMeta::ComputeStatus status) {
+FQHttp::GetQueryResult::ComputeStatus RemapQueryStatus(YandexQuery::QueryMeta::ComputeStatus status) {
switch (status) {
case YandexQuery::QueryMeta::COMPLETED:
- return FederatedQueryHttp::GetQueryResult::COMPLETED;
+ return FQHttp::GetQueryResult::COMPLETED;
case YandexQuery::QueryMeta::ABORTED_BY_USER:
[[fallthrough]];
case YandexQuery::QueryMeta::ABORTED_BY_SYSTEM:
[[fallthrough]];
case YandexQuery::QueryMeta::FAILED:
- return FederatedQueryHttp::GetQueryResult::FAILED;
+ return FQHttp::GetQueryResult::FAILED;
default:
- return FederatedQueryHttp::GetQueryResult::RUNNING;
+ return FQHttp::GetQueryResult::RUNNING;
}
}
-void FqConvert(const YandexQuery::ResultSetMeta& src, FederatedQueryHttp::ResultSetMeta& dst) {
+void FqConvert(const YandexQuery::ResultSetMeta& src, FQHttp::ResultSetMeta& dst) {
SIMPLE_COPY_FIELD(rows_count);
SIMPLE_COPY_FIELD(truncated);
}
-void FqConvert(const YandexQuery::Query& src, FederatedQueryHttp::GetQueryResult& dst) {
+void FqConvert(const YandexQuery::Query& src, FQHttp::GetQueryResult& dst) {
FQ_CONVERT_FIELD(meta);
FqConvert(src.content(), dst);
@@ -137,28 +137,28 @@ void FqConvert(const YandexQuery::Query& src, FederatedQueryHttp::GetQueryResult
dst.mutable_issues()->MergeFrom(src.transient_issue());
}
-void FqConvert(const FederatedQueryHttp::GetQueryRequest& src, YandexQuery::DescribeQueryRequest& dst) {
+void FqConvert(const FQHttp::GetQueryRequest& src, YandexQuery::DescribeQueryRequest& dst) {
SIMPLE_COPY_FIELD(query_id);
}
-void FqConvert(const YandexQuery::DescribeQueryResult& src, FederatedQueryHttp::GetQueryResult& dst) {
+void FqConvert(const YandexQuery::DescribeQueryResult& src, FQHttp::GetQueryResult& dst) {
FqConvert(src.query(), dst);
}
-void FqConvert(const FederatedQueryHttp::GetQueryStatusRequest& src, YandexQuery::GetQueryStatusRequest& dst) {
+void FqConvert(const FQHttp::GetQueryStatusRequest& src, YandexQuery::GetQueryStatusRequest& dst) {
SIMPLE_COPY_FIELD(query_id);
}
-void FqConvert(const YandexQuery::GetQueryStatusResult& src, FederatedQueryHttp::GetQueryStatusResult& dst) {
+void FqConvert(const YandexQuery::GetQueryStatusResult& src, FQHttp::GetQueryStatusResult& dst) {
dst.set_status(RemapQueryStatus(src.status()));
}
-void FqConvert(const FederatedQueryHttp::StopQueryRequest& src, YandexQuery::ControlQueryRequest& dst) {
+void FqConvert(const FQHttp::StopQueryRequest& src, YandexQuery::ControlQueryRequest& dst) {
SIMPLE_COPY_FIELD(query_id);
dst.set_action(YandexQuery::ABORT);
}
-void FqConvert(const FederatedQueryHttp::GetResultDataRequest& src, YandexQuery::GetResultDataRequest& dst) {
+void FqConvert(const FQHttp::GetResultDataRequest& src, YandexQuery::GetResultDataRequest& dst) {
SIMPLE_COPY_FIELD(query_id);
SIMPLE_COPY_FIELD(result_set_index);
SIMPLE_COPY_FIELD(offset);
@@ -169,7 +169,7 @@ void FqConvert(const FederatedQueryHttp::GetResultDataRequest& src, YandexQuery:
}
}
-void FqConvert(const YandexQuery::GetResultDataResult& src, FederatedQueryHttp::GetResultDataResult& dst) {
+void FqConvert(const YandexQuery::GetResultDataResult& src, FQHttp::GetResultDataResult& dst) {
SIMPLE_COPY_MUTABLE_FIELD(result_set);
}
@@ -178,7 +178,7 @@ void FqPackToJson(TStringStream& json, const T& httpResult, const TJsonSettings&
TProtoToJson::ProtoToJson(json, httpResult, jsonSettings);
}
-void FqPackToJson(TStringStream& json, const FederatedQueryHttp::GetResultDataResult& httpResult, const TJsonSettings&) {
+void FqPackToJson(TStringStream& json, const FQHttp::GetResultDataResult& httpResult, const TJsonSettings&) {
auto resultSet = NYdb::TResultSet(httpResult.result_set());
NJson::TJsonValue v;
NYq::FormatResultSet(v, resultSet, true, true);
@@ -304,7 +304,7 @@ public:
auto* typedResponse = static_cast<TGrpcProtoResponseType*>(resp);
if (!typedResponse->operation().result().template Is<TGrpcProtoResultType>()) {
TStringStream json;
- auto* httpResult = google::protobuf::Arena::CreateMessage<FederatedQueryHttp::Error>(resp->GetArena());
+ auto* httpResult = google::protobuf::Arena::CreateMessage<FQHttp::Error>(resp->GetArena());
FqConvert(typedResponse->operation(), *httpResult);
FqPackToJson(json, *httpResult, jsonSettings);
@@ -337,8 +337,8 @@ public:
: TBase(request, &NGRpcService::Create##internalAction##RequestOperationCall) {} \
}
-#define DECLARE_YQ_GRPC_ACTOR(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FederatedQueryHttp::action##Request, YandexQuery::internalAction##Result, FederatedQueryHttp::action##Result, YandexQuery::internalAction##Response)
-#define DECLARE_YQ_GRPC_ACTOR_WIHT_EMPTY_RESULT(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FederatedQueryHttp::action##Request, YandexQuery::internalAction##Result, ::google::protobuf::Empty, YandexQuery::internalAction##Response)
+#define DECLARE_YQ_GRPC_ACTOR(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FQHttp::action##Request, YandexQuery::internalAction##Result, FQHttp::action##Result, YandexQuery::internalAction##Response)
+#define DECLARE_YQ_GRPC_ACTOR_WIHT_EMPTY_RESULT(action, internalAction) DECLARE_YQ_GRPC_ACTOR_IMPL(action, internalAction, YandexQuery::internalAction##Request, FQHttp::action##Request, YandexQuery::internalAction##Result, ::google::protobuf::Empty, YandexQuery::internalAction##Response)
DECLARE_YQ_GRPC_ACTOR(CreateQuery, CreateQuery);
DECLARE_YQ_GRPC_ACTOR(GetQuery, DescribeQuery);
diff --git a/ydb/core/public_http/protos/CMakeLists.txt b/ydb/core/public_http/protos/CMakeLists.txt
new file mode 100644
index 00000000000..d8028f197d3
--- /dev/null
+++ b/ydb/core/public_http/protos/CMakeLists.txt
@@ -0,0 +1,32 @@
+
+# This file was gererated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(core-public_http-protos)
+target_link_libraries(core-public_http-protos PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ ydb-core-protos
+ contrib-libs-protobuf
+)
+target_proto_messages(core-public_http-protos PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/public_http/protos/fq.proto
+)
+target_proto_addincls(core-public_http-protos
+ ./
+ ${CMAKE_SOURCE_DIR}/
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/contrib/libs/protobuf/src
+)
+target_proto_outs(core-public_http-protos
+ --cpp_out=${CMAKE_BINARY_DIR}/
+ --cpp_styleguide_out=${CMAKE_BINARY_DIR}/
+)
diff --git a/ydb/core/public_http/protos/fq.proto b/ydb/core/public_http/protos/fq.proto
new file mode 100644
index 00000000000..42144184202
--- /dev/null
+++ b/ydb/core/public_http/protos/fq.proto
@@ -0,0 +1,105 @@
+syntax = "proto3";
+option cc_enable_arenas = true;
+
+package FQHttp;
+
+import "ydb/public/api/protos/annotations/validation.proto";
+import "ydb/public/api/protos/ydb_issue_message.proto";
+import "ydb/public/api/protos/ydb_status_codes.proto";
+import "ydb/public/api/protos/ydb_value.proto";
+import "google/protobuf/timestamp.proto";
+import "ydb/public/api/protos/yq.proto";
+
+////////////////////////////////////////////////////////////
+
+message Error {
+ Ydb.StatusIds.StatusCode message = 1;
+ repeated Ydb.Issue.IssueMessage details = 2;
+}
+
+message QueryMeta {
+ google.protobuf.Timestamp created_at = 1;
+ google.protobuf.Timestamp submitted_at = 2;
+ google.protobuf.Timestamp finished_at = 3;
+}
+
+message Column {
+ string name = 1;
+ string type = 2;
+}
+
+message ResultSetMeta {
+ int64 rows_count = 1 [(Ydb.value) = ">= 0"];
+ bool truncated = 2;
+}
+
+message CreateQueryRequest {
+ YandexQuery.QueryContent.QueryType type = 1;
+ string name = 2 [(Ydb.length).le = 1024];
+ string text = 3 [(Ydb.length).le = 102400]; // The text of the query itself
+ string description = 4 [(Ydb.length).le = 10240]; // Description of the query, there can be any text
+}
+
+message CreateQueryResult {
+ string id = 1 [(Ydb.length).le = 1024];
+}
+
+message GetQueryRequest {
+ string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}];
+}
+
+message GetQueryResult {
+ enum ComputeStatus {
+ COMPUTE_STATUS_UNSPECIFIED = 0;
+ RUNNING = 1;
+ COMPLETED = 2;
+ FAILED = 3;
+ }
+
+ string id = 1;
+ YandexQuery.QueryContent.QueryType type = 2;
+ string name = 3 [(Ydb.length).le = 1024];
+ string description = 4 [(Ydb.length).le = 10240]; // Description of the query, there can be any text
+ ComputeStatus status = 5;
+ string text = 6 [(Ydb.length).le = 102400]; // The text of the query itself
+ QueryMeta meta = 7;
+ repeated Ydb.Issue.IssueMessage issues = 8;
+ repeated ResultSetMeta result_sets = 9;
+}
+
+message GetQueryStatusRequest {
+ string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}];
+}
+
+message GetQueryStatusResult {
+ GetQueryResult.ComputeStatus status = 1;
+}
+
+message DeleteQueryRequest {
+ string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}];
+}
+
+message DeleteQueryResult {
+}
+
+message StopQueryRequest {
+ string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}];
+}
+
+message StopQueryResult {
+}
+
+message GetResultDataRequest {
+ string query_id = 1 [(Ydb.length).range = {min: 1, max: 1024}];
+ int32 result_set_index = 2 [(Ydb.value) = ">= 0"];
+ int64 offset = 3 [(Ydb.value) = ">= 0"];
+ int64 limit = 4 [(Ydb.value) = "[1; 1000]"];
+}
+
+message RowData {
+ repeated string data = 1;
+}
+
+message GetResultDataResult {
+ Ydb.ResultSet result_set = 1;
+}