Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ydb/core/driver_lib/run/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
#include <ydb/services/ydb/ydb_scheme.h>
#include <ydb/services/ydb/ydb_scripting.h>
#include <ydb/services/ydb/ydb_table.h>
#include <ydb/services/view/grpc_service.h>

#include <ydb/core/fq/libs/init/init.h>

Expand Down Expand Up @@ -586,6 +587,8 @@ void TKikimrRunner::InitializeGRpc(const TKikimrRunConfig& runConfig) {
names["query_service"] = &hasQueryService;
TServiceCfg hasKeyValue = services.empty();
names["keyvalue"] = &hasKeyValue;
TServiceCfg hasView = services.empty();
names["view"] = &hasView;

std::unordered_set<TString> enabled;
for (const auto& name : services) {
Expand Down Expand Up @@ -841,6 +844,11 @@ void TKikimrRunner::InitializeGRpc(const TKikimrRunConfig& runConfig) {
grpcRequestProxies[0]));
}

if (hasView) {
server.AddService(new NGRpcService::TGRpcViewService(ActorSystem.Get(), Counters,
grpcRequestProxies[0], hasView.IsRlAllowed()));
}

if (ModuleFactories) {
for (const auto& service : ModuleFactories->GrpcServiceFactory.Create(enabled, disabled, ActorSystem.Get(), Counters, grpcRequestProxies[0])) {
server.AddService(service);
Expand Down
1 change: 1 addition & 0 deletions ydb/core/driver_lib/run/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ PEERDIR(
ydb/services/deprecated/persqueue_v0
ydb/services/persqueue_v1
ydb/services/rate_limiter
ydb/services/view
ydb/services/ydb
)

Expand Down
94 changes: 94 additions & 0 deletions ydb/core/grpc_services/rpc_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include "rpc_scheme_base.h"
#include "service_view.h"

#include <ydb/core/grpc_services/base/base.h>
#include <ydb/core/tx/schemeshard/schemeshard.h>
#include <ydb/core/ydb_convert/ydb_convert.h>
#include <ydb/library/actors/core/actor.h>
#include <ydb/library/actors/core/hfunc.h>
#include <ydb/public/api/protos/draft/ydb_view.pb.h>

namespace NKikimr::NGRpcService {

using namespace Ydb;

using TEvDescribeView = TGrpcRequestOperationCall<View::DescribeViewRequest, View::DescribeViewResponse>;

class TDescribeViewRPC : public TRpcSchemeRequestActor<TDescribeViewRPC, TEvDescribeView> {
using TBase = TRpcSchemeRequestActor<TDescribeViewRPC, TEvDescribeView>;

public:
using TBase::TBase;

void Bootstrap() {
DescribeScheme();
}

void PassAway() override {
TBase::PassAway();
}

private:
void DescribeScheme() {
auto ev = std::make_unique<TEvTxUserProxy::TEvNavigate>();
SetAuthToken(ev, *Request_);
SetDatabase(ev.get(), *Request_);
ev->Record.MutableDescribePath()->SetPath(GetProtoRequest()->path());

Send(MakeTxProxyID(), ev.release());
Become(&TDescribeViewRPC::StateDescribeScheme);
}

STATEFN(StateDescribeScheme) {
switch (ev->GetTypeRewrite()) {
HFunc(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle);
default:
return TBase::StateWork(ev);
}
}

void Handle(NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev, const TActorContext& ctx) {
const auto& record = ev->Get()->GetRecord();
const auto& desc = record.GetPathDescription();

if (record.HasReason()) {
Request_->RaiseIssue(NYql::TIssue(record.GetReason()));
}

switch (record.GetStatus()) {
case NKikimrScheme::StatusSuccess:
if (desc.GetSelf().GetPathType() != NKikimrSchemeOp::EPathTypeView) {
auto message = TStringBuilder() << "Expected a view, but got: " << desc.GetSelf().GetPathType();
Request_->RaiseIssue(NYql::TIssue(message));
return Reply(StatusIds::SCHEME_ERROR, ctx);
}

ConvertDirectoryEntry(desc.GetSelf(), Result_.mutable_self(), true);
Result_.set_query_text(desc.GetViewDescription().GetQueryText());

return ReplyWithResult(StatusIds::SUCCESS, Result_, ctx);

case NKikimrScheme::StatusPathDoesNotExist:
case NKikimrScheme::StatusSchemeError:
return Reply(StatusIds::SCHEME_ERROR, ctx);

case NKikimrScheme::StatusAccessDenied:
return Reply(StatusIds::UNAUTHORIZED, ctx);

case NKikimrScheme::StatusNotAvailable:
return Reply(StatusIds::UNAVAILABLE, ctx);

default:
return Reply(StatusIds::GENERIC_ERROR, ctx);
}
}

private:
View::DescribeViewResult Result_;
};

void DoDescribeView(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider& f) {
f.RegisterActor(new TDescribeViewRPC(p.release()));
}

}
12 changes: 12 additions & 0 deletions ydb/core/grpc_services/service_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <memory>

namespace NKikimr::NGRpcService {

class IRequestOpCtx;
class IFacilityProvider;

void DoDescribeView(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider& f);

}
1 change: 1 addition & 0 deletions ydb/core/grpc_services/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SRCS(
rpc_stream_execute_scan_query.cpp
rpc_stream_execute_yql_script.cpp
rpc_whoami.cpp
rpc_view.cpp
table_settings.cpp

rpc_common/rpc_common_kqp_session.cpp
Expand Down
1 change: 1 addition & 0 deletions ydb/public/api/grpc/draft/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SRCS(
ydb_maintenance_v1.proto
ydb_logstore_v1.proto
ydb_dynamic_config_v1.proto
ydb_view_v1.proto
)

PEERDIR(
Expand Down
10 changes: 10 additions & 0 deletions ydb/public/api/grpc/draft/ydb_view_v1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package Ydb.View.V1;
option java_package = "com.yandex.ydb.view.v1";

import "ydb/public/api/protos/draft/ydb_view.proto";

service ViewService {
rpc DescribeView(View.DescribeViewRequest) returns (View.DescribeViewResponse);
}
28 changes: 28 additions & 0 deletions ydb/public/api/protos/draft/ydb_view.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";
option cc_enable_arenas = true;

package Ydb.View;
option java_package = "com.yandex.ydb.view";

import "ydb/public/api/protos/annotations/validation.proto";
import "ydb/public/api/protos/ydb_operation.proto";
import "ydb/public/api/protos/ydb_scheme.proto";

message DescribeViewRequest {
Ydb.Operations.OperationParams operation_params = 1;
// The path to the view.
string path = 2 [(required) = true];
}

message DescribeViewResponse {
// The result of the request will be inside the operation proto.
Ydb.Operations.Operation operation = 1;
}

message DescribeViewResult {
// Description of a generic scheme object.
Ydb.Scheme.Entry self = 1;

// View-specific fields.
string query_text = 2;
}
1 change: 1 addition & 0 deletions ydb/public/api/protos/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ SRCS(
draft/ydb_maintenance.proto
draft/ydb_logstore.proto
draft/ydb_dynamic_config.proto
draft/ydb_view.proto
ydb_federation_discovery.proto
persqueue_error_codes_v1.proto
ydb_auth.proto
Expand Down
48 changes: 48 additions & 0 deletions ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ int TCommandDescribe::PrintPathResponse(TDriver& driver, const NScheme::TDescrib
return DescribeTopic(driver);
case NScheme::ESchemeEntryType::CoordinationNode:
return DescribeCoordinationNode(driver);
case NScheme::ESchemeEntryType::View:
return DescribeView(driver);
default:
return DescribeEntryDefault(entry);
}
Expand Down Expand Up @@ -425,6 +427,52 @@ int TCommandDescribe::DescribeCoordinationNode(const TDriver& driver) {
return PrintCoordinationNodeResponse(description);
}

int TCommandDescribe::PrintViewResponse(const NYdb::NView::TDescribeViewResult& result) const {
switch (OutputFormat) {
case EOutputFormat::Default:
case EOutputFormat::Pretty:
return PrintViewResponsePretty(result);
case EOutputFormat::Json:
Cerr << "Warning! Option --json is deprecated and will be removed soon. "
<< "Use \"--format proto-json-base64\" option instead." << Endl;
[[fallthrough]];
case EOutputFormat::ProtoJsonBase64:
return PrintViewResponseProtoJsonBase64(result);
default:
throw TMisuseException() << "This command doesn't support " << OutputFormat << " output format";
}
return EXIT_SUCCESS;
}

int TCommandDescribe::PrintViewResponsePretty(const NYdb::NView::TDescribeViewResult& result) const {
Cout << "\nQuery text:\n" << result.GetViewDescription().GetQueryText() << Endl;
return EXIT_SUCCESS;
}

int TCommandDescribe::PrintViewResponseProtoJsonBase64(const NYdb::NView::TDescribeViewResult& result) const {
TString json;
google::protobuf::util::JsonPrintOptions jsonOpts;
jsonOpts.preserve_proto_field_names = true;
auto conversionStatus = google::protobuf::util::MessageToJsonString(
NYdb::TProtoAccessor::GetProto(result),
&json,
jsonOpts
);
if (conversionStatus.ok()) {
Cout << json << Endl;
return EXIT_SUCCESS;
}
Cerr << "Error occurred while converting result proto to json: " << TString(conversionStatus.message().ToString()) << Endl;
return EXIT_FAILURE;
}

int TCommandDescribe::DescribeView(const TDriver& driver) {
NView::TViewClient client(driver);
auto result = client.DescribeView(Path, {}).ExtractValueSync();
ThrowOnError(result);
return PrintViewResponse(result);
}

namespace {
void PrintColumns(const NTable::TTableDescription& tableDescription) {
if (!tableDescription.GetTableColumns().size()) {
Expand Down
6 changes: 6 additions & 0 deletions ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <ydb/public/lib/ydb_cli/common/format.h>
#include <ydb/public/lib/ydb_cli/common/recursive_remove.h>
#include <ydb/public/sdk/cpp/client/draft/ydb_view.h>
#include <ydb/public/sdk/cpp/client/ydb_coordination/coordination.h>
#include <ydb/public/sdk/cpp/client/ydb_scheme/scheme.h>
#include <ydb/public/sdk/cpp/client/ydb_table/table.h>
Expand Down Expand Up @@ -71,6 +72,11 @@ class TCommandDescribe : public TYdbOperationCommand, public TCommandWithPath, p
int PrintCoordinationNodeResponsePretty(const NYdb::NCoordination::TNodeDescription& result) const;
int PrintCoordinationNodeResponseProtoJsonBase64(const NYdb::NCoordination::TNodeDescription& result) const;

int DescribeView(const TDriver& driver);
int PrintViewResponse(const NYdb::NView::TDescribeViewResult& result) const;
int PrintViewResponsePretty(const NYdb::NView::TDescribeViewResult& result) const;
int PrintViewResponseProtoJsonBase64(const NYdb::NView::TDescribeViewResult& result) const;

template<typename TDescriptionType>
void PrintPermissionsIfNeeded(const TDescriptionType& description) {
if (ShowPermissions) {
Expand Down
16 changes: 16 additions & 0 deletions ydb/public/sdk/cpp/client/draft/ut/helpers/grpc_server.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>

namespace NYdb {

template<class TService>
std::unique_ptr<grpc::Server> StartGrpcServer(const TString& address, TService& service) {
grpc::ServerBuilder builder;
builder.AddListeningPort(address, grpc::InsecureServerCredentials());
builder.RegisterService(&service);
return builder.BuildAndStart();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "scripting.h"

namespace NYdb::NScripting {

grpc::Status TMockSlyDbProxy::ExecuteYql(
grpc::ServerContext* context,
const Ydb::Scripting::ExecuteYqlRequest* request,
Ydb::Scripting::ExecuteYqlResponse* response
) {
context->AddInitialMetadata("key", "value");
Y_UNUSED(request);

// Just to make sdk core happy
auto* op = response->mutable_operation();
op->set_ready(true);
op->set_status(Ydb::StatusIds::SUCCESS);
op->mutable_result();

return grpc::Status::OK;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <ydb/public/api/grpc/ydb_scripting_v1.grpc.pb.h>

namespace NYdb::NScripting {

class TMockSlyDbProxy : public Ydb::Scripting::V1::ScriptingService::Service
{
public:
grpc::Status ExecuteYql(
grpc::ServerContext* context,
const Ydb::Scripting::ExecuteYqlRequest* request,
Ydb::Scripting::ExecuteYqlResponse* response) override;
};

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "view.h"

namespace NYdb::NView {

grpc::Status TViewDummyService::DescribeView(
grpc::ServerContext* context,
const Ydb::View::DescribeViewRequest* request,
Ydb::View::DescribeViewResponse* response
) {
Y_UNUSED(context);
Y_UNUSED(request);

auto* op = response->mutable_operation();
op->set_ready(true);
op->set_status(Ydb::StatusIds::SUCCESS);

Ydb::View::DescribeViewResult describeResult;
describeResult.set_query_text(DummyQueryText);
op->mutable_result()->PackFrom(describeResult);

return grpc::Status::OK;
}

}
18 changes: 18 additions & 0 deletions ydb/public/sdk/cpp/client/draft/ut/helpers/grpc_services/view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <ydb/public/api/grpc/draft/ydb_view_v1.grpc.pb.h>

namespace NYdb::NView {

constexpr const char* DummyQueryText = "select 42";

class TViewDummyService : public Ydb::View::V1::ViewService::Service
{
public:
grpc::Status DescribeView(
grpc::ServerContext* context,
const Ydb::View::DescribeViewRequest* request,
Ydb::View::DescribeViewResponse* response) override;
};

}
Loading
Loading