Skip to content

Commit d02484d

Browse files
authored
Enable DROP VIEW from a folder, bugfix (#8066) (#8079)
1 parent 8043c50 commit d02484d

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
@@ -162,7 +162,7 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
162162
)",
163163
path
164164
);
165-
165+
166166
DisableViewsFeatureFlag(kikimr);
167167
const auto creationResult = session.ExecuteSchemeQuery(creationQuery).ExtractValueSync();
168168
UNIT_ASSERT(!creationResult.IsSuccess());
@@ -325,6 +325,32 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
325325
}
326326
}
327327

328+
Y_UNIT_TEST(DropViewInFolder) {
329+
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
330+
EnableViewsFeatureFlag(kikimr);
331+
auto& runtime = *kikimr.GetTestServer().GetRuntime();
332+
auto session = kikimr.GetTableClient().CreateSession().GetValueSync().GetSession();
333+
334+
constexpr const char* path = "/Root/some/path/to/TheView";
335+
constexpr const char* queryInView = "SELECT 1";
336+
337+
const TString creationQuery = std::format(R"(
338+
CREATE VIEW `{}` WITH (security_invoker = true) AS {};
339+
)",
340+
path,
341+
queryInView
342+
);
343+
ExecuteDataDefinitionQuery(session, creationQuery);
344+
345+
const TString dropQuery = std::format(R"(
346+
DROP VIEW `{}`;
347+
)",
348+
path
349+
);
350+
ExecuteDataDefinitionQuery(session, dropQuery);
351+
ExpectUnknownEntry(runtime, path);
352+
}
353+
328354
Y_UNIT_TEST(ContextPollution) {
329355
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
330356
EnableViewsFeatureFlag(kikimr);
@@ -336,7 +362,7 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
336362
ExecuteDataDefinitionQuery(session, R"(
337363
CREATE VIEW OuterView WITH (security_invoker = TRUE) AS SELECT * FROM InnerView;
338364
)");
339-
365+
340366
ExecuteDataDefinitionQuery(session, R"(
341367
DROP VIEW OuterView;
342368
CREATE VIEW OuterView WITH (security_invoker = TRUE) AS SELECT * FROM InnerView;

0 commit comments

Comments
 (0)