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>
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>
9
9
#include < ydb/core/tx/schemeshard/schemeshard.h>
10
10
#include < ydb/core/ydb_convert/table_description.h>
11
11
#include < ydb/core/ydb_convert/ydb_convert.h>
@@ -22,25 +22,84 @@ using TEvDescribeTableRequest = TGrpcRequestOperationCall<Ydb::Table::DescribeTa
22
22
class TDescribeTableRPC : public TRpcSchemeRequestActor <TDescribeTableRPC, TEvDescribeTableRequest> {
23
23
using TBase = TRpcSchemeRequestActor<TDescribeTableRPC, TEvDescribeTableRequest>;
24
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 (" /indexImplTable" )) {
33
+ return true ;
34
+ }
35
+
36
+ return false ;
37
+ }
38
+
25
39
public:
26
40
TDescribeTableRPC (IRequestOpCtx* msg)
27
41
: TBase(msg) {}
28
42
29
43
void Bootstrap (const TActorContext &ctx) {
30
44
TBase::Bootstrap (ctx);
31
45
32
- 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));
33
62
Become (&TDescribeTableRPC::StateWork);
34
63
}
35
64
36
65
private:
37
66
void StateWork (TAutoPtr<IEventHandle>& ev) {
38
67
switch (ev->GetTypeRewrite ()) {
68
+ HFunc (TEvTxProxySchemeCache::TEvNavigateKeySetResult, Handle );
39
69
HFunc (NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult, Handle );
40
70
default : TBase::StateWork (ev);
41
71
}
42
72
}
43
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
+
44
103
void Handle (NSchemeShard::TEvSchemeShard::TEvDescribeSchemeResult::TPtr& ev, const TActorContext& ctx) {
45
104
const auto & record = ev->Get ()->GetRecord ();
46
105
const auto status = record.GetStatus ();
@@ -53,9 +112,10 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
53
112
case NKikimrScheme::StatusSuccess: {
54
113
const auto & pathDescription = record.GetPathDescription ();
55
114
Ydb::Scheme::Entry* selfEntry = describeTableResult.mutable_self ();
56
- selfEntry->set_name (pathDescription.GetSelf ().GetName ());
57
- selfEntry->set_type (static_cast <Ydb::Scheme::Entry::Type>(pathDescription.GetSelf ().GetPathType ()));
58
115
ConvertDirectoryEntry (pathDescription.GetSelf (), selfEntry, true );
116
+ if (OverrideName) {
117
+ selfEntry->set_name (OverrideName);
118
+ }
59
119
60
120
if (pathDescription.HasColumnTableDescription ()) {
61
121
const auto & tableDescription = pathDescription.GetColumnTableDescription ();
@@ -136,9 +196,8 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
136
196
}
137
197
}
138
198
139
- void SendProposeRequest (const TActorContext & ctx) {
199
+ void SendProposeRequest (const TString& path, const TActorContext& ctx) {
140
200
const auto req = GetProtoRequest ();
141
- const TString path = req->path ();
142
201
143
202
std::unique_ptr<TEvTxUserProxy::TEvNavigate> navigateRequest (new TEvTxUserProxy::TEvNavigate ());
144
203
SetAuthToken (navigateRequest, *Request_);
@@ -153,9 +212,7 @@ class TDescribeTableRPC : public TRpcSchemeRequestActor<TDescribeTableRPC, TEvDe
153
212
record->MutableOptions ()->SetReturnPartitionStats (true );
154
213
}
155
214
156
- if (AppData (ctx)->AllowPrivateTableDescribeForTest || path.EndsWith (" /indexImplTable" )) {
157
- record->MutableOptions ()->SetShowPrivateTable (true );
158
- }
215
+ record->MutableOptions ()->SetShowPrivateTable (ShowPrivatePath (path));
159
216
160
217
ctx.Send (MakeTxProxyID (), navigateRequest.release ());
161
218
}
0 commit comments