diff options
author | dcherednik <dcherednik@ydb.tech> | 2023-09-29 12:31:29 +0300 |
---|---|---|
committer | dcherednik <dcherednik@ydb.tech> | 2023-09-29 12:53:33 +0300 |
commit | 347d5c422477a8dc5399f447e5f0441c1bb0c502 (patch) | |
tree | 1c8815a13bdfc20e31a2fc7385a7785ece41a130 | |
parent | e0e3e1717e3d33762ce61950504f9637a6e669ed (diff) | |
download | ydb-347d5c422477a8dc5399f447e5f0441c1bb0c502.tar.gz |
Check index naming in case of pg syntax. KIKIMR-18527
-rw-r--r-- | ydb/core/grpc_services/rpc_alter_table.cpp | 21 | ||||
-rw-r--r-- | ydb/core/kqp/gateway/local_rpc/helper.cpp | 21 | ||||
-rw-r--r-- | ydb/core/kqp/ut/pg/kqp_pg_ut.cpp | 10 | ||||
-rw-r--r-- | ydb/core/protos/index_builder.proto | 1 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp | 6 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_path.cpp | 29 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_path.h | 1 |
7 files changed, 82 insertions, 7 deletions
diff --git a/ydb/core/grpc_services/rpc_alter_table.cpp b/ydb/core/grpc_services/rpc_alter_table.cpp index 4b76150195..62b47c545c 100644 --- a/ydb/core/grpc_services/rpc_alter_table.cpp +++ b/ydb/core/grpc_services/rpc_alter_table.cpp @@ -142,8 +142,15 @@ class TAlterTableRPC : public TRpcSchemeRequestActor<TAlterTableRPC, TEvAlterTab } public: - TAlterTableRPC(IRequestOpCtx* msg) - : TBase(msg) {} + enum EFlags : ui8 { + Default = 0, + PgMode = 1 + }; + + TAlterTableRPC(IRequestOpCtx* msg, ui8 flags = Default) + : TBase(msg) + , Flags(flags) + {} void Bootstrap(const TActorContext &ctx) { TBase::Bootstrap(ctx); @@ -400,6 +407,9 @@ private: const auto& req = *GetProtoRequest(); NKikimrIndexBuilder::TIndexBuildSettings settings; + if (Flags & PgMode) { + settings.set_pg_mode(true); + } settings.set_source_path(req.path()); auto tableIndex = settings.mutable_index(); tableIndex->CopyFrom(req.add_indexes(0)); @@ -699,6 +709,8 @@ private: THolder<const NACLib::TUserToken> UserToken; TTableProfiles Profiles; EOp OpType; + + const ui8 Flags; }; void DoAlterTableRequest(std::unique_ptr<IRequestOpCtx> p, const IFacilityProvider& f) { @@ -710,5 +722,10 @@ IActor* TEvAlterTableRequest::CreateRpcActor(NKikimr::NGRpcService::IRequestOpCt return new TAlterTableRPC(msg); } +IActor* CreatePgAlterTableRpcActor(NKikimr::NGRpcService::IRequestOpCtx* msg) { + return new TAlterTableRPC(msg, TAlterTableRPC::PgMode); +} + + } // namespace NKikimr } // namespace NGRpcService diff --git a/ydb/core/kqp/gateway/local_rpc/helper.cpp b/ydb/core/kqp/gateway/local_rpc/helper.cpp index dcda348401..4681d0f08f 100644 --- a/ydb/core/kqp/gateway/local_rpc/helper.cpp +++ b/ydb/core/kqp/gateway/local_rpc/helper.cpp @@ -5,6 +5,22 @@ #include <ydb/library/ydb_issue/issue_helpers.h> namespace NKikimr { + +namespace NGRpcService { + +IActor* CreatePgAlterTableRpcActor(NKikimr::NGRpcService::IRequestOpCtx* msg); + +using TEvAlterTableRequest = NGRpcService::TGrpcRequestOperationCall<Ydb::Table::AlterTableRequest, + Ydb::Table::AlterTableResponse>; + +struct TEvPgAlterTableRequest : public TEvAlterTableRequest { + static IActor* CreateRpcActor(IRequestOpCtx* msg) { + return CreatePgAlterTableRpcActor(msg); + } +}; + +} // NGRpcService + namespace NKqp { using namespace NYql; @@ -29,10 +45,7 @@ IKikimrGateway::TGenericResult GenericResultFromSyncOperation(const Operations:: 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), + NRpcService::DoLocalRpcSameMailbox<NGRpcService::TEvPgAlterTableRequest>(std::move(req), std::move(cb), database, token, type, TlsActivationContext->AsActorContext()); } diff --git a/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp b/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp index 0c1087bad3..1bc390fe4d 100644 --- a/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp +++ b/ydb/core/kqp/ut/pg/kqp_pg_ut.cpp @@ -1467,6 +1467,16 @@ Y_UNIT_TEST_SUITE(KqpPg) { auto result = session.ExecuteQuery(query, txCtrl).ExtractValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::BAD_REQUEST, result.GetIssues().ToString()); } + { + const auto query = Q_(R"( + --!syntax_pg + CREATE INDEX "test" ON test (fk); + )"); + + auto result = session.ExecuteQuery(query, txCtrl).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::BAD_REQUEST, result.GetIssues().ToString()); + } + /* { const auto query = Q_(R"( diff --git a/ydb/core/protos/index_builder.proto b/ydb/core/protos/index_builder.proto index 7c56553d63..7f2d7d0dcb 100644 --- a/ydb/core/protos/index_builder.proto +++ b/ydb/core/protos/index_builder.proto @@ -21,6 +21,7 @@ message TIndexBuildSettings { optional string source_path = 1; optional Ydb.Table.TableIndex index = 2; optional TColumnBuildSettings column_build_operation = 7; + optional bool pg_mode = 8; optional uint32 max_batch_rows = 3 [ default = 500 ]; optional uint64 max_batch_bytes = 4 [ default = 8388608 ]; diff --git a/ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp b/ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp index 6e9f57cecf..ce0eaf9608 100644 --- a/ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_build_index__create.cpp @@ -86,7 +86,7 @@ public: if (settings.has_index()) { buildInfo->BuildKind = TIndexBuildInfo::EBuildKind::BuildIndex; - const auto indexPath = tablePath.Child(settings.index().name()); + const auto& indexPath = tablePath.Child(settings.index().name()); { const auto checks = indexPath.Check(); checks @@ -103,6 +103,10 @@ public: .NotResolved(); } + if (settings.pg_mode()) { + checks.IsNameUniqGrandParentLevel(); + } + checks .IsValidLeafName() .PathsLimit(2) // index and impl-table diff --git a/ydb/core/tx/schemeshard/schemeshard_path.cpp b/ydb/core/tx/schemeshard/schemeshard_path.cpp index b0f8120e9e..9951acf30f 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_path.cpp @@ -908,6 +908,35 @@ const TPath::TChecker& TPath::TChecker::IsValidACL(const TString& acl, EStatus s << ", new ACL size: " << bytesSize); } +const TPath::TChecker& TPath::TChecker::IsNameUniqGrandParentLevel(EStatus status) const { + if (Failed) { + return *this; + } + + if (Path.Elements.size() < 2) { + return *this; + } + + auto path = Path.Parent(); + if (!path.IsResolved()) { + return *this; + } + + path.Rise(); + if (!path.IsResolved()) { + return *this; + } + + const auto& myName = Path.NameParts.back(); + + if (path.Elements.back()->FindChild(myName)) { + return Fail(status, TStringBuilder() << "name " << myName + << " is not uniq. Found in: " << path.PathString()); + } + + return *this; +} + TString TPath::TChecker::BasicPathInfo(TPathElement::TPtr element) const { return TStringBuilder() << "id: " << element->PathId << ", " diff --git a/ydb/core/tx/schemeshard/schemeshard_path.h b/ydb/core/tx/schemeshard/schemeshard_path.h index a258e73011..6022e0fa6f 100644 --- a/ydb/core/tx/schemeshard/schemeshard_path.h +++ b/ydb/core/tx/schemeshard/schemeshard_path.h @@ -90,6 +90,7 @@ public: const TChecker& ImportsLimit(ui64 delta = 1, EStatus status = EStatus::StatusResourceExhausted) const; const TChecker& IsExternalTable(EStatus status = EStatus::StatusNameConflict) const; const TChecker& IsExternalDataSource(EStatus status = EStatus::StatusNameConflict) const; + const TChecker& IsNameUniqGrandParentLevel(EStatus status = EStatus::StatusNameConflict) const; }; public: |