From 976f5e18097d301dc99244fae44015e572c6be29 Mon Sep 17 00:00:00 2001 From: azevaykin Date: Wed, 24 Jul 2024 10:24:52 +0000 Subject: [PATCH] Alter index is not supported for vector index --- ydb/core/kqp/provider/yql_kikimr_exec.cpp | 21 ++++++++-- ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 50 ++++++++++++++++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/ydb/core/kqp/provider/yql_kikimr_exec.cpp b/ydb/core/kqp/provider/yql_kikimr_exec.cpp index 58c2e24dbe77..446056dbb691 100644 --- a/ydb/core/kqp/provider/yql_kikimr_exec.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_exec.cpp @@ -1682,9 +1682,24 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer().StringValue(); - auto indexTablePath = NKikimr::NKqp::NSchemeHelpers::CreateIndexTablePath(table.Metadata->Name, indexName); - alterTableRequest.set_path(std::move(indexTablePath)); + const auto indexName = indexSetting.Value().Cast().StringValue(); + const auto indexIter = std::find_if(table.Metadata->Indexes.begin(), table.Metadata->Indexes.end(), [&indexName] (const auto& index) { + return index.Name == indexName; + }); + if (!indexIter) { + ctx.AddError( + TIssue(ctx.GetPosition(indexSetting.Name().Pos()), + TStringBuilder() << "Unknown index name: " << indexName)); + return SyncError(); + } + auto indexTablePaths = NKikimr::NKqp::NSchemeHelpers::CreateIndexTablePath(table.Metadata->Name, indexIter->Type, indexName); + if (indexTablePaths.size() != 1) { + ctx.AddError( + TIssue(ctx.GetPosition(indexSetting.Name().Pos()), + TStringBuilder() << "Only index with one impl table is supported")); + return SyncError(); + } + alterTableRequest.set_path(std::move(indexTablePaths[0])); } else if (settingName == "tableSettings") { auto tableSettings = indexSetting.Value().Cast(); for (const auto& tableSetting : tableSettings) { diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index 4aefc8142460..1c2ce555f23c 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -2472,6 +2472,46 @@ Y_UNIT_TEST_SUITE(KqpScheme) { } } + Y_UNIT_TEST(AlterTableAlterVectorIndex) { + NKikimrConfig::TFeatureFlags featureFlags; + featureFlags.SetEnableVectorIndex(true); + auto settings = TKikimrSettings().SetFeatureFlags(featureFlags); + TKikimrRunner kikimr(settings); + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().GetValueSync().GetSession(); + { + TString create_index_query = R"( + --!syntax_v1 + CREATE TABLE `/Root/TestTable` ( + Key Uint64, + Embedding String, + PRIMARY KEY (Key), + INDEX vector_idx + GLOBAL USING vector_kmeans_tree + ON (Embedding) + WITH (similarity=cosine, vector_type=bit, vector_dimension=1) + ); + )"; + auto result = session.ExecuteSchemeQuery(create_index_query).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + } + { + auto describe = session.DescribeTable("/Root/TestTable/vector_idx/indexImplPostingTable").GetValueSync(); + UNIT_ASSERT_C(describe.IsSuccess(), describe.GetIssues().ToString()); + auto indexDesc = describe.GetTableDescription(); + constexpr int defaultPartitionSizeMb = 2048; + UNIT_ASSERT_VALUES_EQUAL(indexDesc.GetPartitioningSettings().GetPartitionSizeMb(), defaultPartitionSizeMb); + } + { + auto result = session.ExecuteSchemeQuery(R"( + ALTER TABLE `/Root/TestTable` ALTER INDEX vector_idx SET AUTO_PARTITIONING_MIN_PARTITIONS_COUNT 1; + )").ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString()); + UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Only index with one impl table is supported" ); + } + } + + Y_UNIT_TEST(AlterIndexImplTable) { TKikimrRunner kikimr; auto db = kikimr.GetTableClient(); @@ -2695,6 +2735,7 @@ Y_UNIT_TEST_SUITE(KqpScheme) { WITH (similarity=inner_product, vector_type=float, vector_dimension=1024) ); )"; + auto result = session.ExecuteSchemeQuery(create_index_query).ExtractValueSync(); UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); @@ -2714,7 +2755,14 @@ Y_UNIT_TEST_SUITE(KqpScheme) { UNIT_ASSERT_VALUES_EQUAL(indexDesc.GetVectorIndexSettings()->VectorType, NYdb::NTable::TVectorIndexSettings::EVectorType::Float); UNIT_ASSERT_VALUES_EQUAL(indexDesc.GetVectorIndexSettings()->VectorDimension, 1024); } - } + { + auto describeLevelTable = session.DescribeTable("/Root/TestTable/vector_idx/indexImplLevelTable").GetValueSync(); + UNIT_ASSERT_C(describeLevelTable.IsSuccess(), describeLevelTable.GetIssues().ToString()); + auto describePostingTable = session.DescribeTable("/Root/TestTable/vector_idx/indexImplPostingTable").GetValueSync(); + UNIT_ASSERT_C(describePostingTable.IsSuccess(), describePostingTable.GetIssues().ToString()); + } + } + Y_UNIT_TEST(CreateTableWithVectorIndexCovered) { NKikimrConfig::TFeatureFlags featureFlags;