Skip to content

Enable DROP VIEW from a folder, bugfix #8066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions ydb/core/kqp/gateway/behaviour/view/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <ydb/core/base/path.h>
#include <ydb/core/kqp/gateway/actors/scheme.h>
#include <ydb/core/kqp/gateway/utils/scheme_helpers.h>
#include <ydb/core/tx/tx_proxy/proxy.h>

namespace NKikimr::NKqp {
Expand Down Expand Up @@ -36,6 +37,15 @@ std::pair<TString, TString> SplitPathByDb(const TString& objectId,
return pathPair;
}

std::pair<TString, TString> SplitPathByObjectId(const TString& objectId) {
std::pair<TString, TString> pathPair;
TString error;
if (!NSchemeHelpers::TrySplitTablePath(objectId, pathPair, error)) {
ythrow TBadArgumentException() << error;
}
return pathPair;
}

void FillCreateViewProposal(NKikimrSchemeOp::TModifyScheme& modifyScheme,
const NYql::TCreateObjectSettings& settings,
const TString& database) {
Expand All @@ -54,10 +64,9 @@ void FillCreateViewProposal(NKikimrSchemeOp::TModifyScheme& modifyScheme,
}

void FillDropViewProposal(NKikimrSchemeOp::TModifyScheme& modifyScheme,
const NYql::TDropObjectSettings& settings,
const TString& database) {
const NYql::TDropObjectSettings& settings) {

const auto pathPair = SplitPathByDb(settings.GetObjectId(), database);
const auto pathPair = SplitPathByObjectId(settings.GetObjectId());
modifyScheme.SetWorkingDir(pathPair.first);
modifyScheme.SetOperationType(NKikimrSchemeOp::ESchemeOpDropView);

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

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

void PrepareDropView(NKqpProto::TKqpSchemeOperation& schemeOperation,
const NYql::TObjectSettingsImpl& settings,
TInternalModificationContext& context) {
FillDropViewProposal(*schemeOperation.MutableDropView(), settings, context.GetExternalData().GetDatabase());
const NYql::TObjectSettingsImpl& settings) {
FillDropViewProposal(*schemeOperation.MutableDropView(), settings);
}

}
Expand Down Expand Up @@ -173,7 +181,7 @@ TViewManager::TYqlConclusionStatus TViewManager::DoPrepare(NKqpProto::TKqpScheme
PrepareCreateView(schemeOperation, settings, context);
break;
case EActivityType::Drop:
PrepareDropView(schemeOperation, settings, context);
PrepareDropView(schemeOperation, settings);
break;
}
} catch (...) {
Expand Down
30 changes: 28 additions & 2 deletions ydb/core/kqp/ut/view/view_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
)",
path
);

DisableViewsFeatureFlag(kikimr);
const auto creationResult = session.ExecuteSchemeQuery(creationQuery).ExtractValueSync();
UNIT_ASSERT(!creationResult.IsSuccess());
Expand Down Expand Up @@ -325,6 +325,32 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
}
}

Y_UNIT_TEST(DropViewInFolder) {
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
EnableViewsFeatureFlag(kikimr);
auto& runtime = *kikimr.GetTestServer().GetRuntime();
auto session = kikimr.GetTableClient().CreateSession().GetValueSync().GetSession();

constexpr const char* path = "/Root/some/path/to/TheView";
constexpr const char* queryInView = "SELECT 1";

const TString creationQuery = std::format(R"(
CREATE VIEW `{}` WITH (security_invoker = true) AS {};
)",
path,
queryInView
);
ExecuteDataDefinitionQuery(session, creationQuery);

const TString dropQuery = std::format(R"(
DROP VIEW `{}`;
)",
path
);
ExecuteDataDefinitionQuery(session, dropQuery);
ExpectUnknownEntry(runtime, path);
}

Y_UNIT_TEST(ContextPollution) {
TKikimrRunner kikimr(TKikimrSettings().SetWithSampleTables(false));
EnableViewsFeatureFlag(kikimr);
Expand All @@ -336,7 +362,7 @@ Y_UNIT_TEST_SUITE(TCreateAndDropViewTest) {
ExecuteDataDefinitionQuery(session, R"(
CREATE VIEW OuterView WITH (security_invoker = TRUE) AS SELECT * FROM InnerView;
)");

ExecuteDataDefinitionQuery(session, R"(
DROP VIEW OuterView;
CREATE VIEW OuterView WITH (security_invoker = TRUE) AS SELECT * FROM InnerView;
Expand Down
Loading