Skip to content

Commit

Permalink
Test for missed index name
Browse files Browse the repository at this point in the history
  • Loading branch information
azevaykin committed Jul 24, 2024
1 parent 976f5e1 commit 350355e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
11 changes: 6 additions & 5 deletions ydb/core/kqp/provider/yql_kikimr_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,17 +1686,18 @@ class TKiSinkCallableExecutionTransformer : public TAsyncCallbackTransformer<TKi
const auto indexIter = std::find_if(table.Metadata->Indexes.begin(), table.Metadata->Indexes.end(), [&indexName] (const auto& index) {
return index.Name == indexName;
});
if (!indexIter) {
if (indexIter == table.Metadata->Indexes.end()) {
ctx.AddError(
TIssue(ctx.GetPosition(indexSetting.Name().Pos()),
TStringBuilder() << "Unknown index name: " << indexName));
YqlIssue(ctx.GetPosition(indexSetting.Name().Pos()),
TIssuesIds::KIKIMR_SCHEME_ERROR,
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"));
TStringBuilder() << "Only index with one impl table is supported"));
return SyncError();
}
alterTableRequest.set_path(std::move(indexTablePaths[0]));
Expand Down
15 changes: 14 additions & 1 deletion ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2510,7 +2510,20 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Only index with one impl table is supported" );
}
}


Y_UNIT_TEST(AlterTableAlterMissedIndex) {
TKikimrRunner kikimr;
auto db = kikimr.GetTableClient();
auto session = db.CreateSession().GetValueSync().GetSession();
CreateSampleTablesWithIndex(session);
{
auto result = session.ExecuteSchemeQuery(R"(
ALTER TABLE `/Root/SecondaryKeys` ALTER INDEX WrongIndexName SET AUTO_PARTITIONING_MIN_PARTITIONS_COUNT 1;
)").ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SCHEME_ERROR, result.GetIssues().ToString());
UNIT_ASSERT_STRING_CONTAINS(result.GetIssues().ToString(), "Unknown index name: WrongIndexName");
}
}

Y_UNIT_TEST(AlterIndexImplTable) {
TKikimrRunner kikimr;
Expand Down

0 comments on commit 350355e

Please sign in to comment.