-
Notifications
You must be signed in to change notification settings - Fork 606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe VIEW for YDB CLI #9513
Merged
jepett0
merged 5 commits into
ydb-platform:main
from
jepett0:VIEW.cli_describe.1.backup.1
Oct 10, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e41e74d
Describe VIEW for YDB CLI
jepett0 63c2b5d
review fix
jepett0 b678139
Test view SDK with a dummy GRPC service
jepett0 abaa158
ydb scheme describe functional tests for views
jepett0 770d9be
Merge branch 'main' into VIEW.cli_describe.1.backup.1
jepett0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are wondering, all describe requests sent to tx proxy are going through both: