1
1
#include " rpc_scheme_base.h"
2
2
#include " service_table.h"
3
3
4
- #include < ydb/core/base/path.h>
5
4
#include < ydb/core/grpc_services/base/base.h>
6
5
#include < ydb/public/api/protos/ydb_table.pb.h>
7
6
8
7
namespace NKikimr ::NGRpcService {
9
8
10
9
using namespace NActors ;
10
+ using namespace NYql ;
11
11
12
12
using TEvDescribeExternalDataSourceRequest = TGrpcRequestOperationCall<
13
13
Ydb::Table::DescribeExternalDataSourceRequest,
@@ -18,67 +18,69 @@ class TDescribeExternalDataSourceRPC : public TRpcSchemeRequestActor<TDescribeEx
18
18
using TBase = TRpcSchemeRequestActor<TDescribeExternalDataSourceRPC, TEvDescribeExternalDataSourceRequest>;
19
19
20
20
public:
21
- TDescribeExternalDataSourceRPC (IRequestOpCtx* msg)
22
- : TBase(msg)
23
- {}
24
-
25
- void Bootstrap (const TActorContext &ctx) {
26
- TBase::Bootstrap (ctx);
27
-
28
- const auto * request = GetProtoRequest ();
29
- const auto & path = request->path ();
30
- const auto paths = NKikimr::SplitPath (path);
31
- if (paths.empty ()) {
32
- Request_->RaiseIssue (NYql::TIssue (" Invalid path" ));
33
- return Reply (Ydb::StatusIds::BAD_REQUEST, ctx);
34
- }
35
21
36
- auto navigate = MakeHolder<NSchemeCache::TSchemeCacheNavigate>();
37
- navigate->DatabaseName = CanonizePath (Request_->GetDatabaseName ().GetOrElse (" " ));
38
- auto & entry = navigate->ResultSet .emplace_back ();
39
- entry.Path = std::move (paths);
40
- entry.Operation = NSchemeCache::TSchemeCacheNavigate::OpTable;
41
- entry.SyncVersion = true ;
22
+ using TBase::TBase;
42
23
43
- Send ( MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvNavigateKeySet (navigate));
44
- Become (&TDescribeExternalDataSourceRPC::StateWork );
24
+ void Bootstrap () {
25
+ DescribeScheme ( );
45
26
}
46
27
47
28
private:
48
- void StateWork (TAutoPtr<IEventHandle>& ev) {
29
+
30
+ void DescribeScheme () {
31
+ auto ev = std::make_unique<TEvTxUserProxy::TEvNavigate>();
32
+ SetAuthToken (ev, *Request_);
33
+ SetDatabase (ev.get (), *Request_);
34
+ ev->Record .MutableDescribePath ()->SetPath (GetProtoRequest ()->path ());
35
+
36
+ Send (MakeTxProxyID (), ev.release ());
37
+ Become (&TDescribeExternalDataSourceRPC::StateDescribeScheme);
38
+ }
39
+
40
+ STATEFN (StateDescribeScheme) {
49
41
switch (ev->GetTypeRewrite ()) {
50
- HFunc (TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle);
51
- default : TBase::StateWork (ev);
42
+ HFunc (NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle);
43
+ default :
44
+ return TBase::StateWork (ev);
52
45
}
53
46
}
54
47
55
- void Handle (TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev, const TActorContext& ctx) {
56
- const auto * navigate = ev->Get ()->Request .Get ();
48
+ void Handle (NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev, const TActorContext& ctx) {
49
+ const auto & record = ev->Get ()->GetRecord ();
50
+ const auto & pathDescription = record.GetPathDescription ();
57
51
58
- if (navigate-> ResultSet . size () != 1 ) {
59
- return Reply (Ydb::StatusIds::INTERNAL_ERROR, ctx );
52
+ if (record. HasReason () ) {
53
+ Request_-> RaiseIssue ( TIssue (record. GetReason ()) );
60
54
}
61
- const auto & entry = navigate->ResultSet .front ();
62
55
63
- if (navigate->ErrorCount > 0 ) {
64
- switch (entry.Status ) {
65
- case NSchemeCache::TSchemeCacheNavigate::EStatus::PathErrorUnknown:
66
- case NSchemeCache::TSchemeCacheNavigate::EStatus::RootUnknown:
56
+ switch (record.GetStatus ()) {
57
+ case NKikimrScheme::StatusSuccess: {
58
+ if (pathDescription.GetSelf ().GetPathType () != NKikimrSchemeOp::EPathTypeExternalDataSource) {
59
+ Request_->RaiseIssue (TIssue (
60
+ TStringBuilder () << " Unexpected path type: " << pathDescription.GetSelf ().GetPathType ()
61
+ ));
62
+ return Reply (Ydb::StatusIds::SCHEME_ERROR, ctx);
63
+ }
64
+
65
+ return ReplyWithResult (
66
+ Ydb::StatusIds::SUCCESS,
67
+ Ydb::Table::DescribeExternalDataSourceResult (), // to do: convert private protobuf to public
68
+ ctx
69
+ );
70
+ }
71
+ case NKikimrScheme::StatusPathDoesNotExist:
72
+ case NKikimrScheme::StatusSchemeError:
67
73
return Reply (Ydb::StatusIds::SCHEME_ERROR, ctx);
68
- default :
74
+
75
+ case NKikimrScheme::StatusAccessDenied:
76
+ return Reply (Ydb::StatusIds::UNAUTHORIZED, ctx);
77
+
78
+ case NKikimrScheme::StatusNotAvailable:
69
79
return Reply (Ydb::StatusIds::UNAVAILABLE, ctx);
70
- }
71
- }
72
- if (entry.Status != NSchemeCache::TSchemeCacheNavigate::EStatus::Ok) {
73
- // an invariant is broken: error count is equal to zero, but the status is not ok
74
- return Reply (Ydb::StatusIds::INTERNAL_ERROR, ctx);
75
- }
76
80
77
- // to do: fill the entire description from the received navigation entry
78
- Ydb::Table::DescribeExternalDataSourceResult description;
79
- const auto & properties = entry.ExternalDataSourceInfo ->Description .GetProperties ().GetProperties ();
80
- description.mutable_properties ()->insert (properties.begin (), properties.end ());
81
- return ReplyWithResult (Ydb::StatusIds::SUCCESS, description, ctx);
81
+ default :
82
+ return Reply (Ydb::StatusIds::GENERIC_ERROR, ctx);
83
+ }
82
84
}
83
85
};
84
86
0 commit comments