diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2022-06-17 18:40:43 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2022-06-17 18:40:43 +0300 |
commit | 5d69c04a58ea9f27399bb4c57e631cd90bb594a8 (patch) | |
tree | d66e65821a59445d964854e80a96de813dfe89e8 | |
parent | 2f7ce3d8c17884beaaea2dd833ef927c872aa275 (diff) | |
download | ydb-5d69c04a58ea9f27399bb4c57e631cd90bb594a8.tar.gz |
Do not execute DDL in case of prepare only query. KIKIMR-15083
ref:4867c3f1f499372e643ea87383643f3350429033
-rw-r--r-- | ydb/core/kqp/provider/yql_kikimr_exec.cpp | 33 | ||||
-rw-r--r-- | ydb/core/kqp/ut/kqp_scripting_ut.cpp | 84 |
2 files changed, 107 insertions, 10 deletions
diff --git a/ydb/core/kqp/provider/yql_kikimr_exec.cpp b/ydb/core/kqp/provider/yql_kikimr_exec.cpp index 602b47b67f5..499aa3d9746 100644 --- a/ydb/core/kqp/provider/yql_kikimr_exec.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_exec.cpp @@ -17,6 +17,12 @@ using namespace NCommon; using namespace NThreading; namespace { + NThreading::TFuture<IKikimrGateway::TGenericResult> CreateDummySuccess() { + IKikimrGateway::TGenericResult result; + result.SetSuccess(); + return NThreading::MakeFuture(result); + } + bool EnsureNotPrepare(const TString featureName, TPositionHandle pos, const TKikimrQueryContext& queryCtx, TExprContext& ctx) { @@ -467,7 +473,8 @@ public: return SyncError(); } - auto future = Gateway->CreateTable(table.Metadata, true); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->CreateTable(table.Metadata, true); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -494,7 +501,8 @@ public: return SyncError(); } - auto future = Gateway->DropTable(table.Metadata->Cluster, table.Metadata->Name); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->DropTable(table.Metadata->Cluster, table.Metadata->Name); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -882,7 +890,8 @@ public: } } - auto future = Gateway->AlterTable(std::move(alterTableRequest), cluster); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->AlterTable(std::move(alterTableRequest), cluster); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -906,7 +915,8 @@ public: auto cluster = TString(maybeCreateUser.Cast().DataSink().Cluster()); TCreateUserSettings createUserSettings = ParseCreateUserSettings(maybeCreateUser.Cast()); - auto future = Gateway->CreateUser(cluster, createUserSettings); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->CreateUser(cluster, createUserSettings); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -929,7 +939,8 @@ public: auto cluster = TString(maybeAlterUser.Cast().DataSink().Cluster()); TAlterUserSettings alterUserSettings = ParseAlterUserSettings(maybeAlterUser.Cast()); - auto future = Gateway->AlterUser(cluster, alterUserSettings); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->AlterUser(cluster, alterUserSettings); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -952,7 +963,8 @@ public: auto cluster = TString(maybeDropUser.Cast().DataSink().Cluster()); TDropUserSettings dropUserSettings = ParseDropUserSettings(maybeDropUser.Cast()); - auto future = Gateway->DropUser(cluster, dropUserSettings); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->DropUser(cluster, dropUserSettings); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -975,7 +987,8 @@ public: auto cluster = TString(maybeCreateGroup.Cast().DataSink().Cluster()); TCreateGroupSettings createGroupSettings = ParseCreateGroupSettings(maybeCreateGroup.Cast()); - auto future = Gateway->CreateGroup(cluster, createGroupSettings); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->CreateGroup(cluster, createGroupSettings); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -998,7 +1011,8 @@ public: auto cluster = TString(maybeAlterGroup.Cast().DataSink().Cluster()); TAlterGroupSettings alterGroupSettings = ParseAlterGroupSettings(maybeAlterGroup.Cast()); - auto future = Gateway->AlterGroup(cluster, alterGroupSettings); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->AlterGroup(cluster, alterGroupSettings); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { @@ -1021,7 +1035,8 @@ public: auto cluster = TString(maybeDropGroup.Cast().DataSink().Cluster()); TDropGroupSettings dropGroupSettings = ParseDropGroupSettings(maybeDropGroup.Cast()); - auto future = Gateway->DropGroup(cluster, dropGroupSettings); + bool prepareOnly = SessionCtx->Query().PrepareOnly; + auto future = prepareOnly ? CreateDummySuccess() : Gateway->DropGroup(cluster, dropGroupSettings); return WrapFuture(future, [](const IKikimrGateway::TGenericResult& res, const TExprNode::TPtr& input, TExprContext& ctx) { diff --git a/ydb/core/kqp/ut/kqp_scripting_ut.cpp b/ydb/core/kqp/ut/kqp_scripting_ut.cpp index bdd39ea76f3..a5120fe24cc 100644 --- a/ydb/core/kqp/ut/kqp_scripting_ut.cpp +++ b/ydb/core/kqp/ut/kqp_scripting_ut.cpp @@ -259,6 +259,79 @@ Y_UNIT_TEST_SUITE(KqpScripting) { UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); } + Y_UNIT_TEST(ScriptExplainCreatedTable) { + TKikimrRunner kikimr; + TScriptingClient client(kikimr.GetDriver()); + + TExplainYqlRequestSettings settings; + settings.Mode(ExplainYqlRequestMode::Plan); + + { + auto result = client.ExecuteYqlScript(R"( + PRAGMA Kikimr.UseNewEngine = "true"; + CREATE TABLE `/Root/ScriptingTest` ( + Key Uint64, + Value String, + PRIMARY KEY (Key) + ); + COMMIT; + )").GetValueSync(); + + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + } + + auto result = client.ExplainYqlScript(R"( + PRAGMA Kikimr.UseNewEngine = "false"; + REPLACE INTO `/Root/ScriptingTest` (Key, Value) VALUES + (1, "One"), + (2, "Two"); + COMMIT; + + PRAGMA Kikimr.UseNewEngine = "true"; + REPLACE INTO `/Root/ScriptingTest` (Key, Value) VALUES + (3, "Three"), + (4, "Four"); + COMMIT; + + PRAGMA kikimr.ScanQuery = "true"; + PRAGMA Kikimr.UseNewEngine = "true"; + SELECT count(*) FROM `/Root/ScriptingTest`; + COMMIT; + + PRAGMA kikimr.ScanQuery = "false"; + PRAGMA Kikimr.UseNewEngine = "true"; + SELECT count(*) FROM `/Root/ScriptingTest`; + COMMIT; + + PRAGMA kikimr.ScanQuery = "true"; + PRAGMA Kikimr.UseNewEngine = "false"; + SELECT count(*) FROM `/Root/ScriptingTest`; + COMMIT; + + PRAGMA kikimr.ScanQuery = "false"; + PRAGMA Kikimr.UseNewEngine = "false"; + SELECT count(*) FROM `/Root/ScriptingTest`; + COMMIT; + + PRAGMA kikimr.ScanQuery = "true"; + SELECT 1*2*3*4*5; + COMMIT; + + PRAGMA kikimr.ScanQuery = "false"; + SELECT 1*2*3*4*5; + COMMIT; + )", settings).GetValueSync(); + + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + + auto planJson = result.GetPlan(); + + NJson::TJsonValue plan; + NJson::ReadJsonTree(planJson, &plan, true); + UNIT_ASSERT_EQUAL(plan.GetMapSafe().at("queries").GetArraySafe().size(), 8); + } + + Y_UNIT_TEST(ScriptExplain) { TKikimrRunner kikimr; TScriptingClient client(kikimr.GetDriver()); @@ -315,13 +388,22 @@ Y_UNIT_TEST_SUITE(KqpScripting) { SELECT 1*2*3*4*5; COMMIT; )", settings).GetValueSync(); - UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + // KIKIMR-15083 + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SCHEME_ERROR, result.GetIssues().ToString()); + /* auto planJson = result.GetPlan(); NJson::TJsonValue plan; NJson::ReadJsonTree(planJson, &plan, true); UNIT_ASSERT_EQUAL(plan.GetMapSafe().at("queries").GetArraySafe().size(), 8); + */ + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().GetValueSync().GetSession(); + { + auto res = session.DescribeTable("/Root/ScriptingTest").ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL(res.GetStatus(), NYdb::EStatus::SCHEME_ERROR); + } } Y_UNIT_TEST(ScriptValidate) { |