Skip to content

Commit 82dba10

Browse files
authored
Enable DROP VIEW from a folder, bugfix (#8066) (#8080)
1 parent 54e5a53 commit 82dba10

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

ydb/core/kqp/gateway/behaviour/view/manager.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <ydb/core/base/path.h>
44
#include <ydb/core/kqp/gateway/actors/scheme.h>
5+
#include <ydb/core/kqp/gateway/utils/scheme_helpers.h>
56
#include <ydb/core/tx/tx_proxy/proxy.h>
67

78
namespace NKikimr::NKqp {
@@ -36,6 +37,15 @@ std::pair<TString, TString> SplitPathByDb(const TString& objectId,
3637
return pathPair;
3738
}
3839

40+
std::pair<TString, TString> SplitPathByObjectId(const TString& objectId) {
41+
std::pair<TString, TString> pathPair;
42+
TString error;
43+
if (!NSchemeHelpers::TrySplitTablePath(objectId, pathPair, error)) {
44+
ythrow TBadArgumentException() << error;
45+
}
46+
return pathPair;
47+
}
48+
3949
void FillCreateViewProposal(NKikimrSchemeOp::TModifyScheme& modifyScheme,
4050
const NYql::TCreateObjectSettings& settings,
4151
const TString& database) {
@@ -54,10 +64,9 @@ void FillCreateViewProposal(NKikimrSchemeOp::TModifyScheme& modifyScheme,
5464
}
5565

5666
void FillDropViewProposal(NKikimrSchemeOp::TModifyScheme& modifyScheme,
57-
const NYql::TDropObjectSettings& settings,
58-
const TString& database) {
67+
const NYql::TDropObjectSettings& settings) {
5968

60-
const auto pathPair = SplitPathByDb(settings.GetObjectId(), database);
69+
const auto pathPair = SplitPathByObjectId(settings.GetObjectId());
6170
modifyScheme.SetWorkingDir(pathPair.first);
6271
modifyScheme.SetOperationType(NKikimrSchemeOp::ESchemeOpDropView);
6372

@@ -103,7 +112,7 @@ NThreading::TFuture<TYqlConclusionStatus> DropView(const NYql::TDropObjectSettin
103112
proposal->Record.SetUserToken(context.GetExternalData().GetUserToken()->GetSerializedToken());
104113
}
105114
auto& schemeTx = *proposal->Record.MutableTransaction()->MutableModifyScheme();
106-
FillDropViewProposal(schemeTx, settings, context.GetExternalData().GetDatabase());
115+
FillDropViewProposal(schemeTx, settings);
107116

108117
return SendSchemeRequest(proposal.Release(), context.GetExternalData().GetActorSystem(), false);
109118
}
@@ -115,9 +124,8 @@ void PrepareCreateView(NKqpProto::TKqpSchemeOperation& schemeOperation,
115124
}
116125

117126
void PrepareDropView(NKqpProto::TKqpSchemeOperation& schemeOperation,
118-
const NYql::TObjectSettingsImpl& settings,
119-
TInternalModificationContext& context) {
120-
FillDropViewProposal(*schemeOperation.MutableDropView(), settings, context.GetExternalData().GetDatabase());
127+
const NYql::TObjectSettingsImpl& settings) {
128+
FillDropViewProposal(*schemeOperation.MutableDropView(), settings);
121129
}
122130

123131
}
@@ -173,7 +181,7 @@ TViewManager::TYqlConclusionStatus TViewManager::DoPrepare(NKqpProto::TKqpScheme
173181
PrepareCreateView(schemeOperation, settings, context);
174182
break;
175183
case EActivityType::Drop:
176-
PrepareDropView(schemeOperation, settings, context);
184+
PrepareDropView(schemeOperation, settings);
177185
break;
178186
}
179187
} catch (...) {

ydb/core/kqp/ut/view/view_ut.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Y_UNIT_TEST_SUITE(TKQPViewTest) {
154154
)",
155155
path
156156
);
157-
157+
158158
DisableViewsFeatureFlag(kikimr);
159159
const auto creationResult = session.ExecuteSchemeQuery(creationQuery).ExtractValueSync();
160160
UNIT_ASSERT(!creationResult.IsSuccess());
@@ -317,6 +317,32 @@ Y_UNIT_TEST_SUITE(TKQPViewTest) {
317317
}
318318
}
319319

320+
Y_UNIT_TEST(DropViewInFolder) {
321+
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
322+
EnableViewsFeatureFlag(kikimr);
323+
auto& runtime = *kikimr.GetTestServer().GetRuntime();
324+
auto session = kikimr.GetTableClient().CreateSession().GetValueSync().GetSession();
325+
326+
constexpr const char* path = "/Root/some/path/to/TheView";
327+
constexpr const char* queryInView = "SELECT 1";
328+
329+
const TString creationQuery = std::format(R"(
330+
CREATE VIEW `{}` WITH (security_invoker = true) AS {};
331+
)",
332+
path,
333+
queryInView
334+
);
335+
ExecuteDataDefinitionQuery(session, creationQuery);
336+
337+
const TString dropQuery = std::format(R"(
338+
DROP VIEW `{}`;
339+
)",
340+
path
341+
);
342+
ExecuteDataDefinitionQuery(session, dropQuery);
343+
ExpectUnknownEntry(runtime, path);
344+
}
345+
320346
Y_UNIT_TEST(ContextPollution) {
321347
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
322348
EnableViewsFeatureFlag(kikimr);
@@ -328,7 +354,7 @@ Y_UNIT_TEST_SUITE(TKQPViewTest) {
328354
ExecuteDataDefinitionQuery(session, R"(
329355
CREATE VIEW OuterView WITH (security_invoker = TRUE) AS SELECT * FROM InnerView;
330356
)");
331-
357+
332358
ExecuteDataDefinitionQuery(session, R"(
333359
DROP VIEW OuterView;
334360
CREATE VIEW OuterView WITH (security_invoker = TRUE) AS SELECT * FROM InnerView;

0 commit comments

Comments
 (0)