aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcherednik <dcherednik@ydb.tech>2023-09-28 18:22:33 +0300
committerdcherednik <dcherednik@ydb.tech>2023-09-28 19:08:02 +0300
commita113e7a5106d9eb2c3957710c82b79d44afe6662 (patch)
tree93c9f2ff1415b442a0d82476de3e89922a94dcac
parent887dfe66960e19ce9285f041a642b8d5c9a68525 (diff)
downloadydb-a113e7a5106d9eb2c3957710c82b79d44afe6662.tar.gz
Alter table support for query service. KIKIMR-19408
-rw-r--r--.mapping.json5
-rw-r--r--ydb/core/kqp/executer_actor/CMakeLists.darwin-x86_64.txt1
-rw-r--r--ydb/core/kqp/executer_actor/CMakeLists.linux-aarch64.txt1
-rw-r--r--ydb/core/kqp/executer_actor/CMakeLists.linux-x86_64.txt1
-rw-r--r--ydb/core/kqp/executer_actor/CMakeLists.windows-x86_64.txt1
-rw-r--r--ydb/core/kqp/executer_actor/kqp_scheme_executer.cpp35
-rw-r--r--ydb/core/kqp/executer_actor/ya.make1
-rw-r--r--ydb/core/kqp/gateway/CMakeLists.darwin-x86_64.txt1
-rw-r--r--ydb/core/kqp/gateway/CMakeLists.linux-aarch64.txt1
-rw-r--r--ydb/core/kqp/gateway/CMakeLists.linux-x86_64.txt1
-rw-r--r--ydb/core/kqp/gateway/CMakeLists.windows-x86_64.txt1
-rw-r--r--ydb/core/kqp/gateway/kqp_ic_gateway.cpp19
-rw-r--r--ydb/core/kqp/gateway/local_rpc/CMakeLists.darwin-x86_64.txt23
-rw-r--r--ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-aarch64.txt24
-rw-r--r--ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-x86_64.txt24
-rw-r--r--ydb/core/kqp/gateway/local_rpc/CMakeLists.txt17
-rw-r--r--ydb/core/kqp/gateway/local_rpc/CMakeLists.windows-x86_64.txt23
-rw-r--r--ydb/core/kqp/gateway/local_rpc/helper.cpp40
-rw-r--r--ydb/core/kqp/gateway/local_rpc/helper.h15
-rw-r--r--ydb/core/kqp/gateway/local_rpc/ya.make15
-rw-r--r--ydb/core/kqp/host/kqp_gateway_proxy.cpp21
-rw-r--r--ydb/core/kqp/provider/yql_kikimr_exec.cpp40
-rw-r--r--ydb/core/kqp/ut/pg/kqp_pg_ut.cpp19
-rw-r--r--ydb/core/kqp/ut/query/kqp_query_ut.cpp17
-rw-r--r--ydb/core/protos/kqp_physical.proto6
25 files changed, 296 insertions, 56 deletions
diff --git a/.mapping.json b/.mapping.json
index 69c53d1511..12598f8590 100644
--- a/.mapping.json
+++ b/.mapping.json
@@ -4580,6 +4580,11 @@
"ydb/core/kqp/gateway/behaviour/tablestore/operations/CMakeLists.linux-x86_64.txt":"",
"ydb/core/kqp/gateway/behaviour/tablestore/operations/CMakeLists.txt":"",
"ydb/core/kqp/gateway/behaviour/tablestore/operations/CMakeLists.windows-x86_64.txt":"",
+ "ydb/core/kqp/gateway/local_rpc/CMakeLists.darwin-x86_64.txt":"",
+ "ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-aarch64.txt":"",
+ "ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-x86_64.txt":"",
+ "ydb/core/kqp/gateway/local_rpc/CMakeLists.txt":"",
+ "ydb/core/kqp/gateway/local_rpc/CMakeLists.windows-x86_64.txt":"",
"ydb/core/kqp/host/CMakeLists.darwin-x86_64.txt":"",
"ydb/core/kqp/host/CMakeLists.linux-aarch64.txt":"",
"ydb/core/kqp/host/CMakeLists.linux-x86_64.txt":"",
diff --git a/ydb/core/kqp/executer_actor/CMakeLists.darwin-x86_64.txt b/ydb/core/kqp/executer_actor/CMakeLists.darwin-x86_64.txt
index 81f67d2325..e07e2bd503 100644
--- a/ydb/core/kqp/executer_actor/CMakeLists.darwin-x86_64.txt
+++ b/ydb/core/kqp/executer_actor/CMakeLists.darwin-x86_64.txt
@@ -25,6 +25,7 @@ target_link_libraries(core-kqp-executer_actor PUBLIC
core-kqp-query_compiler
core-kqp-rm_service
core-kqp-topics
+ kqp-gateway-local_rpc
ydb-core-protos
tx-long_tx_service-public
ydb-core-ydb_convert
diff --git a/ydb/core/kqp/executer_actor/CMakeLists.linux-aarch64.txt b/ydb/core/kqp/executer_actor/CMakeLists.linux-aarch64.txt
index 2e000c5a42..28cb3b0661 100644
--- a/ydb/core/kqp/executer_actor/CMakeLists.linux-aarch64.txt
+++ b/ydb/core/kqp/executer_actor/CMakeLists.linux-aarch64.txt
@@ -26,6 +26,7 @@ target_link_libraries(core-kqp-executer_actor PUBLIC
core-kqp-query_compiler
core-kqp-rm_service
core-kqp-topics
+ kqp-gateway-local_rpc
ydb-core-protos
tx-long_tx_service-public
ydb-core-ydb_convert
diff --git a/ydb/core/kqp/executer_actor/CMakeLists.linux-x86_64.txt b/ydb/core/kqp/executer_actor/CMakeLists.linux-x86_64.txt
index 2e000c5a42..28cb3b0661 100644
--- a/ydb/core/kqp/executer_actor/CMakeLists.linux-x86_64.txt
+++ b/ydb/core/kqp/executer_actor/CMakeLists.linux-x86_64.txt
@@ -26,6 +26,7 @@ target_link_libraries(core-kqp-executer_actor PUBLIC
core-kqp-query_compiler
core-kqp-rm_service
core-kqp-topics
+ kqp-gateway-local_rpc
ydb-core-protos
tx-long_tx_service-public
ydb-core-ydb_convert
diff --git a/ydb/core/kqp/executer_actor/CMakeLists.windows-x86_64.txt b/ydb/core/kqp/executer_actor/CMakeLists.windows-x86_64.txt
index 81f67d2325..e07e2bd503 100644
--- a/ydb/core/kqp/executer_actor/CMakeLists.windows-x86_64.txt
+++ b/ydb/core/kqp/executer_actor/CMakeLists.windows-x86_64.txt
@@ -25,6 +25,7 @@ target_link_libraries(core-kqp-executer_actor PUBLIC
core-kqp-query_compiler
core-kqp-rm_service
core-kqp-topics
+ kqp-gateway-local_rpc
ydb-core-protos
tx-long_tx_service-public
ydb-core-ydb_convert
diff --git a/ydb/core/kqp/executer_actor/kqp_scheme_executer.cpp b/ydb/core/kqp/executer_actor/kqp_scheme_executer.cpp
index 39a4106800..7381fe6f5f 100644
--- a/ydb/core/kqp/executer_actor/kqp_scheme_executer.cpp
+++ b/ydb/core/kqp/executer_actor/kqp_scheme_executer.cpp
@@ -1,6 +1,7 @@
#include "kqp_executer.h"
#include <ydb/core/kqp/gateway/actors/scheme.h>
+#include <ydb/core/kqp/gateway/local_rpc/helper.h>
#include <ydb/core/tx/tx_proxy/proxy.h>
#include <ydb/core/kqp/session_actor/kqp_worker_common.h>
@@ -77,6 +78,27 @@ public:
break;
}
+ case NKqpProto::TKqpSchemeOperation::kAlterTable: {
+ auto alter = schemeOp.GetAlterTable();
+ TMaybe<TString> token;
+ TMaybe<TString> type;
+
+ if (UserToken) {
+ token = UserToken->GetSerializedToken();
+ }
+
+ if (auto t = alter.GetType()) {
+ type = t;
+ }
+
+ auto cb = GetAlterTableRespHandler();
+ DoAlterTableSameMailbox(std::move(*alter.MutableReq()), std::move(cb),
+ Database, token, type);
+
+ Become(&TKqpSchemeExecuter::ExecuteState);
+ return;
+ }
+
default:
InternalError(TStringBuilder() << "Unexpected scheme operation: "
<< (ui32) schemeOp.GetOperationCase());
@@ -133,6 +155,19 @@ public:
}
private:
+
+ std::function<void(const Ydb::Table::AlterTableResponse& r)> GetAlterTableRespHandler() const {
+ auto actorSystem = TlsActivationContext->AsActorContext().ExecutorThread.ActorSystem;
+ auto selfId = SelfId();
+
+ return [actorSystem, selfId] (const Ydb::Table::AlterTableResponse& r) {
+ auto ev = MakeHolder<TEvPrivate::TEvResult>();
+
+ ev->Result = GenericResultFromSyncOperation(r.operation());
+ actorSystem->Send(selfId, ev.Release());
+ };
+ }
+
void ReplyErrorAndDie(Ydb::StatusIds::StatusCode status, const NYql::TIssues& issues) {
google::protobuf::RepeatedPtrField<Ydb::Issue::IssueMessage> protoIssues;
IssuesToMessage(issues, &protoIssues);
diff --git a/ydb/core/kqp/executer_actor/ya.make b/ydb/core/kqp/executer_actor/ya.make
index 1840a77542..297503043a 100644
--- a/ydb/core/kqp/executer_actor/ya.make
+++ b/ydb/core/kqp/executer_actor/ya.make
@@ -29,6 +29,7 @@ PEERDIR(
ydb/core/kqp/query_compiler
ydb/core/kqp/rm_service
ydb/core/kqp/topics
+ ydb/core/kqp/gateway/local_rpc
ydb/core/protos
ydb/core/tx/long_tx_service/public
ydb/core/ydb_convert
diff --git a/ydb/core/kqp/gateway/CMakeLists.darwin-x86_64.txt b/ydb/core/kqp/gateway/CMakeLists.darwin-x86_64.txt
index 7893c75ba0..4fa3bf3548 100644
--- a/ydb/core/kqp/gateway/CMakeLists.darwin-x86_64.txt
+++ b/ydb/core/kqp/gateway/CMakeLists.darwin-x86_64.txt
@@ -8,6 +8,7 @@
add_subdirectory(actors)
add_subdirectory(behaviour)
+add_subdirectory(local_rpc)
add_library(core-kqp-gateway)
target_compile_options(core-kqp-gateway PRIVATE
diff --git a/ydb/core/kqp/gateway/CMakeLists.linux-aarch64.txt b/ydb/core/kqp/gateway/CMakeLists.linux-aarch64.txt
index de6fc0d227..1796c0956f 100644
--- a/ydb/core/kqp/gateway/CMakeLists.linux-aarch64.txt
+++ b/ydb/core/kqp/gateway/CMakeLists.linux-aarch64.txt
@@ -8,6 +8,7 @@
add_subdirectory(actors)
add_subdirectory(behaviour)
+add_subdirectory(local_rpc)
add_library(core-kqp-gateway)
target_compile_options(core-kqp-gateway PRIVATE
diff --git a/ydb/core/kqp/gateway/CMakeLists.linux-x86_64.txt b/ydb/core/kqp/gateway/CMakeLists.linux-x86_64.txt
index de6fc0d227..1796c0956f 100644
--- a/ydb/core/kqp/gateway/CMakeLists.linux-x86_64.txt
+++ b/ydb/core/kqp/gateway/CMakeLists.linux-x86_64.txt
@@ -8,6 +8,7 @@
add_subdirectory(actors)
add_subdirectory(behaviour)
+add_subdirectory(local_rpc)
add_library(core-kqp-gateway)
target_compile_options(core-kqp-gateway PRIVATE
diff --git a/ydb/core/kqp/gateway/CMakeLists.windows-x86_64.txt b/ydb/core/kqp/gateway/CMakeLists.windows-x86_64.txt
index 7893c75ba0..4fa3bf3548 100644
--- a/ydb/core/kqp/gateway/CMakeLists.windows-x86_64.txt
+++ b/ydb/core/kqp/gateway/CMakeLists.windows-x86_64.txt
@@ -8,6 +8,7 @@
add_subdirectory(actors)
add_subdirectory(behaviour)
+add_subdirectory(local_rpc)
add_library(core-kqp-gateway)
target_compile_options(core-kqp-gateway PRIVATE
diff --git a/ydb/core/kqp/gateway/kqp_ic_gateway.cpp b/ydb/core/kqp/gateway/kqp_ic_gateway.cpp
index b685bde61f..3b5728a6db 100644
--- a/ydb/core/kqp/gateway/kqp_ic_gateway.cpp
+++ b/ydb/core/kqp/gateway/kqp_ic_gateway.cpp
@@ -2,6 +2,7 @@
#include "actors/kqp_ic_gateway_actors.h"
#include "actors/scheme.h"
#include "kqp_metadata_loader.h"
+#include "local_rpc/helper.h"
#include <ydb/core/base/appdata.h>
#include <ydb/core/base/path.h>
@@ -2073,24 +2074,8 @@ private:
template<typename TRpc>
TFuture<TGenericResult> SendLocalRpcRequestNoResult(typename TRpc::TRequest&& proto, const TString& databse, const TString& token, const TMaybe<TString>& requestType = {}) {
return NRpcService::DoLocalRpc<TRpc>(std::move(proto), databse, token, requestType, ActorSystem).Apply([](NThreading::TFuture<typename TRpc::TResponse> future) {
- auto r = future.ExtractValue();
- NYql::TIssues issues;
- NYql::IssuesFromMessage(r.operation().issues(), issues);
- if (r.operation().ready() != true) {
- issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, TStringBuilder()
- << "Unexpected operation for \"sync\" mode"));
-
- const auto& yqlStatus = TIssuesIds::DEFAULT_ERROR;
-
- auto result = ResultFromIssues<TGenericResult>(yqlStatus, issues);
- return NThreading::MakeFuture(result);
- }
-
- const auto& yqlStatus = NYql::YqlStatusFromYdbStatus(r.operation().status());
-
- auto result = ResultFromIssues<TGenericResult>(yqlStatus, issues);
- return NThreading::MakeFuture(result);
+ return NThreading::MakeFuture(GenericResultFromSyncOperation(future.GetValue().operation()));
});
}
diff --git a/ydb/core/kqp/gateway/local_rpc/CMakeLists.darwin-x86_64.txt b/ydb/core/kqp/gateway/local_rpc/CMakeLists.darwin-x86_64.txt
new file mode 100644
index 0000000000..f4643e254b
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/CMakeLists.darwin-x86_64.txt
@@ -0,0 +1,23 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(kqp-gateway-local_rpc)
+target_compile_options(kqp-gateway-local_rpc PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_link_libraries(kqp-gateway-local_rpc PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ core-grpc_services-local_rpc
+ core-kqp-provider
+ ydb-library-ydb_issue
+)
+target_sources(kqp-gateway-local_rpc PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/gateway/local_rpc/helper.cpp
+)
diff --git a/ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-aarch64.txt b/ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-aarch64.txt
new file mode 100644
index 0000000000..d3d1afc95e
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-aarch64.txt
@@ -0,0 +1,24 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(kqp-gateway-local_rpc)
+target_compile_options(kqp-gateway-local_rpc PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_link_libraries(kqp-gateway-local_rpc PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ core-grpc_services-local_rpc
+ core-kqp-provider
+ ydb-library-ydb_issue
+)
+target_sources(kqp-gateway-local_rpc PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/gateway/local_rpc/helper.cpp
+)
diff --git a/ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-x86_64.txt b/ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-x86_64.txt
new file mode 100644
index 0000000000..d3d1afc95e
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/CMakeLists.linux-x86_64.txt
@@ -0,0 +1,24 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(kqp-gateway-local_rpc)
+target_compile_options(kqp-gateway-local_rpc PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_link_libraries(kqp-gateway-local_rpc PUBLIC
+ contrib-libs-linux-headers
+ contrib-libs-cxxsupp
+ yutil
+ core-grpc_services-local_rpc
+ core-kqp-provider
+ ydb-library-ydb_issue
+)
+target_sources(kqp-gateway-local_rpc PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/gateway/local_rpc/helper.cpp
+)
diff --git a/ydb/core/kqp/gateway/local_rpc/CMakeLists.txt b/ydb/core/kqp/gateway/local_rpc/CMakeLists.txt
new file mode 100644
index 0000000000..f8b31df0c1
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/CMakeLists.txt
@@ -0,0 +1,17 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-aarch64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ include(CMakeLists.darwin-x86_64.txt)
+elseif (WIN32 AND CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" AND NOT HAVE_CUDA)
+ include(CMakeLists.windows-x86_64.txt)
+elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT HAVE_CUDA)
+ include(CMakeLists.linux-x86_64.txt)
+endif()
diff --git a/ydb/core/kqp/gateway/local_rpc/CMakeLists.windows-x86_64.txt b/ydb/core/kqp/gateway/local_rpc/CMakeLists.windows-x86_64.txt
new file mode 100644
index 0000000000..f4643e254b
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/CMakeLists.windows-x86_64.txt
@@ -0,0 +1,23 @@
+
+# This file was generated by the build system used internally in the Yandex monorepo.
+# Only simple modifications are allowed (adding source-files to targets, adding simple properties
+# like target_include_directories). These modifications will be ported to original
+# ya.make files by maintainers. Any complex modifications which can't be ported back to the
+# original buildsystem will not be accepted.
+
+
+
+add_library(kqp-gateway-local_rpc)
+target_compile_options(kqp-gateway-local_rpc PRIVATE
+ -DUSE_CURRENT_UDF_ABI_VERSION
+)
+target_link_libraries(kqp-gateway-local_rpc PUBLIC
+ contrib-libs-cxxsupp
+ yutil
+ core-grpc_services-local_rpc
+ core-kqp-provider
+ ydb-library-ydb_issue
+)
+target_sources(kqp-gateway-local_rpc PRIVATE
+ ${CMAKE_SOURCE_DIR}/ydb/core/kqp/gateway/local_rpc/helper.cpp
+)
diff --git a/ydb/core/kqp/gateway/local_rpc/helper.cpp b/ydb/core/kqp/gateway/local_rpc/helper.cpp
new file mode 100644
index 0000000000..dcda348401
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/helper.cpp
@@ -0,0 +1,40 @@
+#include "helper.h"
+
+#include <ydb/core/grpc_services/local_rpc/local_rpc.h>
+#include <ydb/library/yql/public/issue/yql_issue_message.h>
+#include <ydb/library/ydb_issue/issue_helpers.h>
+
+namespace NKikimr {
+namespace NKqp {
+
+using namespace NYql;
+using namespace Ydb;
+
+IKikimrGateway::TGenericResult GenericResultFromSyncOperation(const Operations::Operation& op) {
+ using NYql::NCommon::ResultFromIssues;
+
+ NYql::TIssues issues;
+ NYql::IssuesFromMessage(op.issues(), issues);
+
+ if (op.ready() != true) {
+ issues.AddIssue(MakeIssue(NKikimrIssues::TIssuesIds::DEFAULT_ERROR, TStringBuilder()
+ << "Unexpected operation for \"sync\" mode"));
+ return ResultFromIssues<IKikimrGateway::TGenericResult>(TIssuesIds::DEFAULT_ERROR, issues);
+ } else {
+ const auto& yqlStatus = NYql::YqlStatusFromYdbStatus(op.status());
+ return ResultFromIssues<IKikimrGateway::TGenericResult>(yqlStatus, issues);
+ }
+}
+
+void DoAlterTableSameMailbox(Ydb::Table::AlterTableRequest&& req, TAlterTableRespHandler&& cb,
+ const TString& database, const TMaybe<TString>& token, const TMaybe<TString>& type)
+{
+ using TEvAlterTableRequest = NGRpcService::TGrpcRequestOperationCall<Ydb::Table::AlterTableRequest,
+ Ydb::Table::AlterTableResponse>;
+
+ NRpcService::DoLocalRpcSameMailbox<TEvAlterTableRequest>(std::move(req), std::move(cb),
+ database, token, type, TlsActivationContext->AsActorContext());
+}
+
+}
+}
diff --git a/ydb/core/kqp/gateway/local_rpc/helper.h b/ydb/core/kqp/gateway/local_rpc/helper.h
new file mode 100644
index 0000000000..faeafd874b
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/helper.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <ydb/core/kqp/provider/yql_kikimr_gateway.h>
+
+namespace NKikimr {
+namespace NKqp {
+
+NYql::IKikimrGateway::TGenericResult GenericResultFromSyncOperation(const Ydb::Operations::Operation& op);
+
+using TAlterTableRespHandler = std::function<void(const Ydb::Table::AlterTableResponse& r)>;
+void DoAlterTableSameMailbox(Ydb::Table::AlterTableRequest&& req, TAlterTableRespHandler&& cb,
+ const TString& database, const TMaybe<TString>& token, const TMaybe<TString>& type);
+
+}
+}
diff --git a/ydb/core/kqp/gateway/local_rpc/ya.make b/ydb/core/kqp/gateway/local_rpc/ya.make
new file mode 100644
index 0000000000..68219aa3af
--- /dev/null
+++ b/ydb/core/kqp/gateway/local_rpc/ya.make
@@ -0,0 +1,15 @@
+LIBRARY()
+
+SRCS(
+ helper.cpp
+)
+
+PEERDIR(
+ ydb/core/grpc_services/local_rpc
+ ydb/core/kqp/provider
+ ydb/library/ydb_issue
+)
+
+YQL_LAST_ABI_VERSION()
+
+END()
diff --git a/ydb/core/kqp/host/kqp_gateway_proxy.cpp b/ydb/core/kqp/host/kqp_gateway_proxy.cpp
index 6cf615ab50..d3e36b1519 100644
--- a/ydb/core/kqp/host/kqp_gateway_proxy.cpp
+++ b/ydb/core/kqp/host/kqp_gateway_proxy.cpp
@@ -545,7 +545,26 @@ public:
TFuture<TGenericResult> AlterTable(const TString& cluster, Ydb::Table::AlterTableRequest&& req,
const TMaybe<TString>& requestType) override
{
- FORWARD_ENSURE_NO_PREPARE(AlterTable, cluster, std::move(req), requestType);
+ CHECK_PREPARED_DDL(AlterTable);
+
+ if (IsPrepare()) {
+ auto& phyQuery = *SessionCtx->Query().PreparingQuery->MutablePhysicalQuery();
+ auto& phyTx = *phyQuery.AddTransactions();
+ phyTx.SetType(NKqpProto::TKqpPhyTx::TYPE_SCHEME);
+ auto alter = phyTx.MutableSchemeOperation()->MutableAlterTable();
+ alter->MutableReq()->Swap(&req);
+ if (requestType) {
+ alter->SetType(*requestType);
+ }
+
+ auto promise = NewPromise<TGenericResult>();
+ TGenericResult result;
+ result.SetSuccess();
+ promise.SetValue(result);
+ return promise.GetFuture();
+ } else {
+ return Gateway->AlterTable(cluster, std::move(req), requestType);
+ }
}
TFuture<TGenericResult> RenameTable(const TString& src, const TString& dst, const TString& cluster) override {
diff --git a/ydb/core/kqp/provider/yql_kikimr_exec.cpp b/ydb/core/kqp/provider/yql_kikimr_exec.cpp
index 0abe22188a..2930eb8b1c 100644
--- a/ydb/core/kqp/provider/yql_kikimr_exec.cpp
+++ b/ydb/core/kqp/provider/yql_kikimr_exec.cpp
@@ -1046,10 +1046,6 @@ public:
}
if (auto maybeAlter = TMaybeNode<TKiAlterTable>(input)) {
- if (!EnsureNotPrepare("ALTER TABLE", input->Pos(), SessionCtx->Query(), ctx)) {
- return SyncError();
- }
-
auto requireStatus = RequireChild(*input, 0);
if (requireStatus.Level != TStatus::Ok) {
return SyncStatus(requireStatus);
@@ -1495,28 +1491,24 @@ public:
}
NThreading::TFuture<IKikimrGateway::TGenericResult> future;
- if (SessionCtx->Query().PrepareOnly) {
- future = CreateDummySuccess();
- } else {
- bool isTableStore = (table.Metadata->TableType == ETableType::TableStore);
- bool isColumn = (table.Metadata->StoreType == EStoreType::Column);
+ bool isTableStore = (table.Metadata->TableType == ETableType::TableStore);
+ bool isColumn = (table.Metadata->StoreType == EStoreType::Column);
- if (isTableStore) {
- if (!isColumn) {
- ctx.AddError(TIssue(ctx.GetPosition(input->Pos()),
- TStringBuilder() << "TABLESTORE with not COLUMN store"));
- return SyncError();
- }
- future = Gateway->AlterTableStore(cluster, ParseAlterTableStoreSettings(maybeAlter.Cast()));
- } else if (isColumn) {
- future = Gateway->AlterColumnTable(cluster, ParseAlterColumnTableSettings(maybeAlter.Cast()));
- } else {
- TMaybe<TString> requestType;
- if (!SessionCtx->Query().DocumentApiRestricted) {
- requestType = NKikimr::NDocApi::RequestType;
- }
- future = Gateway->AlterTable(cluster, std::move(alterTableRequest), requestType);
+ if (isTableStore) {
+ if (!isColumn) {
+ ctx.AddError(TIssue(ctx.GetPosition(input->Pos()),
+ TStringBuilder() << "TABLESTORE with not COLUMN store"));
+ return SyncError();
+ }
+ future = Gateway->AlterTableStore(cluster, ParseAlterTableStoreSettings(maybeAlter.Cast()));
+ } else if (isColumn) {
+ future = Gateway->AlterColumnTable(cluster, ParseAlterColumnTableSettings(maybeAlter.Cast()));
+ } else {
+ TMaybe<TString> requestType;
+ if (!SessionCtx->Query().DocumentApiRestricted) {
+ requestType = NKikimr::NDocApi::RequestType;
}
+ future = Gateway->AlterTable(cluster, std::move(alterTableRequest), requestType);
}
return WrapFuture(future,
diff --git a/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp b/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp
index 36a19abe2a..0c1087bad3 100644
--- a/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp
+++ b/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp
@@ -1430,9 +1430,18 @@ Y_UNIT_TEST_SUITE(KqpPg) {
}
Y_UNIT_TEST(CreateIndex) {
- TKikimrRunner kikimr(NKqp::TKikimrSettings().SetWithSampleTables(false));
- auto client = kikimr.GetTableClient();
- auto session = client.CreateSession().GetValueSync().GetSession();
+ NKikimrConfig::TAppConfig appConfig;
+ appConfig.MutableTableServiceConfig()->SetEnablePreparedDdl(true);;
+ auto setting = NKikimrKqp::TKqpSetting();
+ auto serverSettings = TKikimrSettings()
+ .SetAppConfig(appConfig)
+ .SetKqpSettings({setting});
+ TKikimrRunner kikimr(
+ serverSettings.SetWithSampleTables(false));
+
+ auto client = kikimr.GetQueryClient();
+ auto session = client.GetSession().GetValueSync().GetSession();
+ const auto txCtrl = NYdb::NQuery::TTxControl::NoTx();
{
const auto query = Q_(R"(
--!syntax_pg
@@ -1446,7 +1455,7 @@ Y_UNIT_TEST_SUITE(KqpPg) {
CREATE INDEX "test_fk_idx_cover" ON test (fk) INCLUDE(value);
)");
- auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ auto result = session.ExecuteQuery(query, txCtrl).ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
}
{
@@ -1455,7 +1464,7 @@ Y_UNIT_TEST_SUITE(KqpPg) {
CREATE INDEX "test_fk_idx" ON test (fk);
)");
- auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ auto result = session.ExecuteQuery(query, txCtrl).ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::BAD_REQUEST, result.GetIssues().ToString());
}
/*
diff --git a/ydb/core/kqp/ut/query/kqp_query_ut.cpp b/ydb/core/kqp/ut/query/kqp_query_ut.cpp
index 12e1073464..fb630d2b3a 100644
--- a/ydb/core/kqp/ut/query/kqp_query_ut.cpp
+++ b/ydb/core/kqp/ut/query/kqp_query_ut.cpp
@@ -1158,28 +1158,27 @@ Y_UNIT_TEST_SUITE(KqpQuery) {
);
)"), TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx()).ExtractValueSync();
result.GetIssues().PrintTo(Cerr);
- UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR);
- UNIT_ASSERT(HasIssue(result.GetIssues(), NYql::TIssuesIds::KIKIMR_BAD_OPERATION, [](const NYql::TIssue& issue) {
+
+ const auto issueChecker = [](const NYql::TIssue& issue) {
return issue.GetMessage().Contains("can't be performed in data query");
- }));
+ };
+
+ UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR);
+ UNIT_ASSERT(HasIssue(result.GetIssues(), NYql::TIssuesIds::KIKIMR_BAD_OPERATION, issueChecker));
result = session.ExecuteDataQuery(Q_(R"(
DROP TABLE `/Root/KeyValue`;
)"), TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx()).ExtractValueSync();
result.GetIssues().PrintTo(Cerr);
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR);
- UNIT_ASSERT(HasIssue(result.GetIssues(), NYql::TIssuesIds::KIKIMR_BAD_OPERATION, [](const NYql::TIssue& issue) {
- return issue.GetMessage().Contains("can't be performed in data query");
- }));
+ UNIT_ASSERT(HasIssue(result.GetIssues(), NYql::TIssuesIds::KIKIMR_BAD_OPERATION, issueChecker));
result = session.ExecuteDataQuery(Q_(R"(
ALTER TABLE `/Root/KeyValue` DROP COLUMN Value;
)"), TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx()).ExtractValueSync();
result.GetIssues().PrintTo(Cerr);
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR);
- UNIT_ASSERT(HasIssue(result.GetIssues(), NYql::TIssuesIds::DEFAULT_ERROR, [](const NYql::TIssue& issue) {
- return issue.GetMessage().Contains("not supported");
- }));
+ UNIT_ASSERT(HasIssue(result.GetIssues(), NYql::TIssuesIds::KIKIMR_BAD_OPERATION, issueChecker));
}
Y_UNIT_TEST(DyNumberCompare) {
diff --git a/ydb/core/protos/kqp_physical.proto b/ydb/core/protos/kqp_physical.proto
index 3521bd1401..70415ade76 100644
--- a/ydb/core/protos/kqp_physical.proto
+++ b/ydb/core/protos/kqp_physical.proto
@@ -9,6 +9,7 @@ import "ydb/core/protos/flat_scheme_op.proto";
import "ydb/library/mkql_proto/protos/minikql.proto";
import "ydb/library/yql/dq/proto/dq_tasks.proto";
import "ydb/public/api/protos/ydb_value.proto";
+import "ydb/public/api/protos/ydb_table.proto";
message TKqpPhyExternalBinding {
}
@@ -364,9 +365,14 @@ message TKqpPhyResult {
}
message TKqpSchemeOperation {
+ message TAlterTable {
+ Ydb.Table.AlterTableRequest Req = 1;
+ string Type = 2;
+ }
oneof Operation {
NKikimrSchemeOp.TModifyScheme CreateTable = 1;
NKikimrSchemeOp.TModifyScheme DropTable = 2;
+ TAlterTable AlterTable = 3;
}
}