forked from ydb-platform/ydb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
24-3: Describe VIEW for YDB CLI (ydb-platform#9513) (ydb-platform#10356)
- Loading branch information
Showing
34 changed files
with
650 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
ydb/public/sdk/cpp/client/draft/ut/helpers/grpc_services/scripting.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
ydb/public/sdk/cpp/client/draft/ut/helpers/grpc_services/scripting.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
ydb/public/sdk/cpp/client/draft/ut/helpers/grpc_services/view.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
ydb/public/sdk/cpp/client/draft/ut/helpers/grpc_services/view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
LIBRARY() | ||
|
||
PEERDIR( | ||
ydb/public/api/grpc | ||
ydb/public/api/grpc/draft | ||
) | ||
|
||
SRCS( | ||
grpc_services/scripting.cpp | ||
grpc_services/view.cpp | ||
) | ||
|
||
END() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.