1
- #include " service_table.h"
2
- #include < ydb/core/grpc_services/base/base.h>
3
-
4
1
#include " rpc_calls.h"
5
2
#include " rpc_scheme_base.h"
6
-
7
3
#include " service_table.h"
8
- #include " rpc_common/rpc_common.h"
4
+
5
+ #include < ydb/core/base/path.h>
9
6
#include < ydb/core/base/table_index.h>
7
+ #include < ydb/core/grpc_services/base/base.h>
8
+ #include < ydb/core/grpc_services/rpc_common/rpc_common.h>
10
9
#include < ydb/core/tx/schemeshard/schemeshard.h>
11
10
#include < ydb/core/ydb_convert/table_description.h>
12
11
#include < ydb/core/ydb_convert/ydb_convert.h>
@@ -23,25 +22,84 @@ using TEvDescribeTableRequest = TGrpcRequestOperationCall<Ydb::Table::DescribeTa
23
22
class TDescribeTableRPC : public TRpcSchemeRequestActor <TDescribeTableRPC, TEvDescribeTableRequest> {
24
23
using TBase = TRpcSchemeRequestActor<TDescribeTableRPC, TEvDescribeTableRequest>;
25
24
25
+ TString OverrideName;
26
+
27
+ static bool ShowPrivatePath (const TString& path) {
28
+ if (AppData ()->AllowPrivateTableDescribeForTest ) {
29
+ return true ;
30
+ }
31
+
32
+ if (path.EndsWith (TStringBuilder () << " /" << NTableIndex::ImplTable)) {
33
+ return true ;
34
+ }
35
+
36
+ return false ;
37
+ }
38
+
26
39
public:
27
40
TDescribeTableRPC (IRequestOpCtx* msg)
28
41
: TBase(msg) {}
29
42
30
43
void Bootstrap (const TActorContext &ctx) {
31
44
TBase::Bootstrap (ctx);
32
45
33
- SendProposeRequest (ctx);
46
+ const auto & path = GetProtoRequest ()->path ();
47
+ const auto paths = NKikimr::SplitPath (path);
48
+ if (paths.empty ()) {
49
+ Request_->RaiseIssue (NYql::TIssue (" Invalid path" ));
50
+ return Reply (Ydb::StatusIds::BAD_REQUEST, ctx);
51
+ }
52
+
53
+ auto navigate = MakeHolder<NSchemeCache::TSchemeCacheNavigate>();
54
+ navigate->DatabaseName = CanonizePath (Request_->GetDatabaseName ().GetOrElse (" " ));
55
+ auto & entry = navigate->ResultSet .emplace_back ();
56
+ entry.Path = paths;
57
+ entry.Operation = NSchemeCache::TSchemeCacheNavigate::OpList;
58
+ entry.SyncVersion = true ;
59
+ entry.ShowPrivatePath = ShowPrivatePath (path);
60
+
61
+ Send (MakeSchemeCacheID (), new TEvTxProxySchemeCache::TEvNavigateKeySet (navigate));
34
62
Become (&TDescribeTableRPC::StateWork);
35
63
}
36
64
37
65
private:
38
66
void StateWork (TAutoPtr<IEventHandle>& ev) {
39
67
switch (ev->GetTypeRewrite ()) {
68
+ HFunc (TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle );
40
69
HFunc (NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle );
41
70
default : TBase::StateWork (ev);
42
71
}
43
72
}
44
73
74
+ void Handle (TEvTxProxySchemeCache::TEvNavigateKeySetResult::TPtr& ev, const TActorContext& ctx) {
75
+ auto * navigate = ev->Get ()->Request .Get ();
76
+
77
+ Y_ABORT_UNLESS (navigate->ResultSet .size () == 1 );
78
+ const auto & entry = navigate->ResultSet .front ();
79
+
80
+ if (navigate->ErrorCount > 0 ) {
81
+ switch (entry.Status ) {
82
+ case NSchemeCache::TSchemeCacheNavigate::EStatus::PathErrorUnknown:
83
+ case NSchemeCache::TSchemeCacheNavigate::EStatus::RootUnknown:
84
+ return Reply (Ydb::StatusIds::SCHEME_ERROR, ctx);
85
+ default :
86
+ return Reply (Ydb::StatusIds::UNAVAILABLE, ctx);
87
+ }
88
+ }
89
+
90
+ if (entry.Kind == NSchemeCache::TSchemeCacheNavigate::KindIndex) {
91
+ auto list = entry.ListNodeEntry ;
92
+ if (!list || list->Children .size () != 1 ) {
93
+ return Reply (Ydb::StatusIds::SCHEME_ERROR, ctx);
94
+ }
95
+
96
+ OverrideName = entry.Path .back ();
97
+ SendProposeRequest (CanonizePath (ChildPath (entry.Path , list->Children .at (0 ).Name )), ctx);
98
+ } else {
99
+ SendProposeRequest (GetProtoRequest ()->path (), ctx);
100
+ }
101
+ }
102
+
45
103
void Handle (NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev, const TActorContext& ctx) {
46
104
const auto & record = ev->Get ()->GetRecord ();
47
105
const auto status = record.GetStatus ();
@@ -54,9 +112,10 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
54
112
case NKikimrScheme::StatusSuccess: {
55
113
const auto & pathDescription = record.GetPathDescription ();
56
114
Ydb::Scheme::Entry* selfEntry = describeTableResult.mutable_self ();
57
- selfEntry->set_name (pathDescription.GetSelf ().GetName ());
58
- selfEntry->set_type (static_cast <Ydb::Scheme::Entry::Type>(pathDescription.GetSelf ().GetPathType ()));
59
115
ConvertDirectoryEntry (pathDescription.GetSelf (), selfEntry, true );
116
+ if (OverrideName) {
117
+ selfEntry->set_name (OverrideName);
118
+ }
60
119
61
120
if (pathDescription.HasColumnTableDescription ()) {
62
121
const auto & tableDescription = pathDescription.GetColumnTableDescription ();
@@ -137,9 +196,8 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
137
196
}
138
197
}
139
198
140
- void SendProposeRequest (const TActorContext & ctx) {
199
+ void SendProposeRequest (const TString& path, const TActorContext& ctx) {
141
200
const auto req = GetProtoRequest ();
142
- const TString path = req->path ();
143
201
144
202
std::unique_ptr<TEvTxUserProxy::TEvNavigate> navigateRequest (new TEvTxUserProxy::TEvNavigate ());
145
203
SetAuthToken (navigateRequest, *Request_);
@@ -154,9 +212,7 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
154
212
record->MutableOptions ()->SetReturnPartitionStats (true );
155
213
}
156
214
157
- if (AppData (ctx)->AllowPrivateTableDescribeForTest || path.EndsWith (TStringBuilder () << " /" << NTableIndex::ImplTable)) {
158
- record->MutableOptions ()->SetShowPrivateTable (true );
159
- }
215
+ record->MutableOptions ()->SetShowPrivateTable (ShowPrivatePath (path));
160
216
161
217
ctx.Send (MakeTxProxyID (), navigateRequest.release ());
162
218
}
0 commit comments