Skip to content

Commit f4b2c61

Browse files
authored
Add unit test: drop then add column with different type (#8446)
1 parent 684bdae commit f4b2c61

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.github/config/muted_ya.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ydb/core/kqp/ut/query KqpLimits.QueryReplySize
1717
ydb/core/kqp/ut/query KqpQuery.QueryTimeout
1818
ydb/core/kqp/ut/scan KqpRequestContext.TraceIdInErrorMessage
1919
ydb/core/kqp/ut/scheme [*/*]*
20+
ydb/core/kqp/ut/scheme KqpOlapScheme.DropThenAddColumn
2021
ydb/core/kqp/ut/scheme KqpOlapScheme.TenThousandColumns
2122
ydb/core/kqp/ut/scheme KqpScheme.AlterAsyncReplication
2223
ydb/core/kqp/ut/scheme KqpScheme.QueryWithAlter

ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <ydb/core/kqp/ut/common/kqp_ut_common.h>
33
#include <ydb/core/kqp/ut/common/columnshard.h>
44
#include <ydb/core/tx/columnshard/hooks/testing/controller.h>
5+
#include <ydb/core/tx/columnshard/test_helper/controllers.h>
56
#include <ydb/core/formats/arrow/arrow_helpers.h>
67
#include <ydb/core/tx/tx_proxy/proxy.h>
78
#include <ydb/public/sdk/cpp/client/draft/ydb_replication.h>
@@ -7848,6 +7849,65 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) {
78487849
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#;[\"test_res_1\"]]]");
78497850
}
78507851

7852+
Y_UNIT_TEST(DropThenAddColumn) {
7853+
auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NOlap::TWaitCompactionController>();
7854+
csController->DisableBackground(NYDBTest::ICSController::EBackground::Indexation);
7855+
csController->DisableBackground(NYDBTest::ICSController::EBackground::Compaction);
7856+
7857+
TKikimrSettings runnerSettings;
7858+
runnerSettings.WithSampleTables = false;
7859+
TTestHelper testHelper(runnerSettings);
7860+
7861+
TVector<TTestHelper::TColumnSchema> schema = {
7862+
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false),
7863+
TTestHelper::TColumnSchema().SetName("value").SetType(NScheme::NTypeIds::Utf8),
7864+
};
7865+
7866+
TTestHelper::TColumnTable testTable;
7867+
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({ "id" }).SetSharding({ "id" }).SetSchema(schema);
7868+
testHelper.CreateTable(testTable);
7869+
7870+
{
7871+
TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema));
7872+
tableInserter.AddRow().Add(1).Add("test_res_1");
7873+
tableInserter.AddRow().Add(2).Add("test_res_2");
7874+
testHelper.BulkUpsert(testTable, tableInserter);
7875+
}
7876+
7877+
csController->EnableBackground(NYDBTest::ICSController::EBackground::Indexation);
7878+
csController->EnableBackground(NYDBTest::ICSController::EBackground::Compaction);
7879+
csController->WaitIndexation(TDuration::Seconds(5));
7880+
csController->WaitCompactions(TDuration::Seconds(5));
7881+
csController->DisableBackground(NYDBTest::ICSController::EBackground::Indexation);
7882+
csController->DisableBackground(NYDBTest::ICSController::EBackground::Compaction);
7883+
7884+
{
7885+
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` DROP COLUMN value;";
7886+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
7887+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
7888+
}
7889+
{
7890+
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` ADD COLUMN value Uint64;";
7891+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
7892+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
7893+
}
7894+
schema.back().SetType(NScheme::NTypeIds::Uint64);
7895+
7896+
{
7897+
TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema));
7898+
tableInserter.AddRow().Add(3).Add(42);
7899+
tableInserter.AddRow().Add(4).Add(43);
7900+
testHelper.BulkUpsert(testTable, tableInserter);
7901+
}
7902+
7903+
csController->EnableBackground(NYDBTest::ICSController::EBackground::Indexation);
7904+
csController->EnableBackground(NYDBTest::ICSController::EBackground::Compaction);
7905+
csController->WaitIndexation(TDuration::Seconds(5));
7906+
csController->WaitCompactions(TDuration::Seconds(5));
7907+
7908+
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest`", "[[4;#;[\"test_res_1\"]]]");
7909+
}
7910+
78517911
Y_UNIT_TEST(DropTtlColumn) {
78527912
TKikimrSettings runnerSettings;
78537913
runnerSettings.WithSampleTables = false;

0 commit comments

Comments
 (0)