diff options
author | nsofya <nsofya@yandex-team.com> | 2023-06-08 11:11:23 +0300 |
---|---|---|
committer | nsofya <nsofya@yandex-team.com> | 2023-06-08 11:11:23 +0300 |
commit | c49c97d9c975644812ff9223bb6d4099a65f3cbd (patch) | |
tree | a08a55dac011c3f4592d1b600b0a8a00aad7795f | |
parent | 81d39471f2e9dc990e644f2f0547560e65f092b4 (diff) | |
download | ydb-c49c97d9c975644812ff9223bb6d4099a65f3cbd.tar.gz |
Alow drop table in schemeshard
Alow drop table in schemeshard
-rw-r--r-- | ydb/core/kqp/ut/common/kqp_ut_common.cpp | 22 | ||||
-rw-r--r-- | ydb/core/kqp/ut/common/kqp_ut_common.h | 6 | ||||
-rw-r--r-- | ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 186 | ||||
-rw-r--r-- | ydb/core/testlib/cs_helper.cpp | 4 | ||||
-rw-r--r-- | ydb/core/testlib/cs_helper.h | 2 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_olap_types.cpp | 29 | ||||
-rw-r--r-- | ydb/core/tx/schemeshard/schemeshard_olap_types.h | 1 |
7 files changed, 222 insertions, 28 deletions
diff --git a/ydb/core/kqp/ut/common/kqp_ut_common.cpp b/ydb/core/kqp/ut/common/kqp_ut_common.cpp index 7243163aed0..9e1ee584bea 100644 --- a/ydb/core/kqp/ut/common/kqp_ut_common.cpp +++ b/ydb/core/kqp/ut/common/kqp_ut_common.cpp @@ -592,7 +592,7 @@ bool IsTimeoutError(NYdb::EStatus status) { } template<typename TIterator> -TString StreamResultToYsonImpl(TIterator& it, TVector<TString>* profiles, bool throwOnTimeout = false) { +TString StreamResultToYsonImpl(TIterator& it, TVector<TString>* profiles, bool throwOnTimeout = false, const NYdb::EStatus& opStatus = NYdb::EStatus::SUCCESS) { TStringStream out; NYson::TYsonWriter writer(&out, NYson::EYsonFormat::Text, ::NYson::EYsonType::Node, true); writer.OnBeginList(); @@ -602,6 +602,10 @@ TString StreamResultToYsonImpl(TIterator& it, TVector<TString>* profiles, bool t for (;;) { auto streamPart = it.ReadNext().GetValueSync(); if (!streamPart.IsSuccess()) { + if (opStatus != NYdb::EStatus::SUCCESS) { + UNIT_ASSERT_VALUES_EQUAL_C(streamPart.GetStatus(), opStatus, streamPart.GetIssues().ToString()); + break; + } if (throwOnTimeout && IsTimeoutError(streamPart.GetStatus())) { throw TStreamReadError(streamPart.GetStatus()); } @@ -623,11 +627,11 @@ TString StreamResultToYsonImpl(TIterator& it, TVector<TString>* profiles, bool t return out.Str(); } -TString StreamResultToYson(NYdb::NTable::TScanQueryPartIterator& it, bool throwOnTimeout) { - return StreamResultToYsonImpl(it, nullptr, throwOnTimeout); +TString StreamResultToYson(NYdb::NTable::TScanQueryPartIterator& it, bool throwOnTimeout, const NYdb::EStatus& opStatus) { + return StreamResultToYsonImpl(it, nullptr, throwOnTimeout, opStatus); } -TString StreamResultToYson(NYdb::NTable::TTablePartIterator& it, bool throwOnTimeout) { +TString StreamResultToYson(NYdb::NTable::TTablePartIterator& it, bool throwOnTimeout, const NYdb::EStatus& opStatus) { TStringStream out; NYson::TYsonWriter writer(&out, NYson::EYsonFormat::Text, ::NYson::EYsonType::Node, true); writer.OnBeginList(); @@ -637,6 +641,10 @@ TString StreamResultToYson(NYdb::NTable::TTablePartIterator& it, bool throwOnTim for (;;) { auto streamPart = it.ReadNext().GetValueSync(); if (!streamPart.IsSuccess()) { + if (opStatus != NYdb::EStatus::SUCCESS) { + UNIT_ASSERT_VALUES_EQUAL_C(streamPart.GetStatus(), opStatus, streamPart.GetIssues().ToString()); + break; + } if (throwOnTimeout && IsTimeoutError(streamPart.GetStatus())) { throw TStreamReadError(streamPart.GetStatus()); } @@ -655,7 +663,7 @@ TString StreamResultToYson(NYdb::NTable::TTablePartIterator& it, bool throwOnTim return out.Str(); } -TString StreamResultToYson(NYdb::NScripting::TYqlResultPartIterator& it, bool throwOnTimeout) { +TString StreamResultToYson(NYdb::NScripting::TYqlResultPartIterator& it, bool throwOnTimeout, const NYdb::EStatus& opStatus) { TStringStream out; NYson::TYsonWriter writer(&out, NYson::EYsonFormat::Text, ::NYson::EYsonType::Node, true); writer.OnBeginList(); @@ -667,6 +675,10 @@ TString StreamResultToYson(NYdb::NScripting::TYqlResultPartIterator& it, bool th for (;;) { auto streamPart = it.ReadNext().GetValueSync(); if (!streamPart.IsSuccess()) { + if (opStatus != NYdb::EStatus::SUCCESS) { + UNIT_ASSERT_VALUES_EQUAL_C(streamPart.GetStatus(), opStatus, streamPart.GetIssues().ToString()); + break; + } if (throwOnTimeout && IsTimeoutError(streamPart.GetStatus())) { throw TStreamReadError(streamPart.GetStatus()); } diff --git a/ydb/core/kqp/ut/common/kqp_ut_common.h b/ydb/core/kqp/ut/common/kqp_ut_common.h index f24f7bc1412..30dc781d1c0 100644 --- a/ydb/core/kqp/ut/common/kqp_ut_common.h +++ b/ydb/core/kqp/ut/common/kqp_ut_common.h @@ -246,9 +246,9 @@ public: NYdb::EStatus Status; }; -TString StreamResultToYson(NYdb::NTable::TScanQueryPartIterator& it, bool throwOnTImeout = false); -TString StreamResultToYson(NYdb::NScripting::TYqlResultPartIterator& it, bool throwOnTImeout = false); -TString StreamResultToYson(NYdb::NTable::TTablePartIterator& it, bool throwOnTImeout = false); +TString StreamResultToYson(NYdb::NTable::TScanQueryPartIterator& it, bool throwOnTImeout = false, const NYdb::EStatus& opStatus = NYdb::EStatus::SUCCESS); +TString StreamResultToYson(NYdb::NScripting::TYqlResultPartIterator& it, bool throwOnTImeout = false, const NYdb::EStatus& opStatus = NYdb::EStatus::SUCCESS); +TString StreamResultToYson(NYdb::NTable::TTablePartIterator& it, bool throwOnTImeout = false, const NYdb::EStatus& opStatus = NYdb::EStatus::SUCCESS); bool ValidatePlanNodeIds(const NJson::TJsonValue& plan); ui32 CountPlanNodesByKv(const NJson::TJsonValue& plan, const TString& key, const TString& value); diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index 78fc70f4b0f..3f69165b215 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -4821,18 +4821,20 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { UNIT_ASSERT_VALUES_EQUAL_C(resCommitTx.Status().GetStatus(), EStatus::SUCCESS, resCommitTx.Status().GetIssues().ToString()); } - void InsertBulk(const TColumnTable& table, TTestHelper::TUpdatesBuilder& updates, const EStatus opStatus = EStatus::SUCCESS) { + void BulkUpsert(const TColumnTable& table, TTestHelper::TUpdatesBuilder& updates, const Ydb::StatusIds_StatusCode& opStatus = Ydb::StatusIds::SUCCESS) { Y_UNUSED(opStatus); NKikimr::Tests::NCS::THelper helper(Kikimr.GetTestServer()); auto batch = updates.BuildArrow(); - helper.SendDataViaActorSystem(table.GetName(), batch); + helper.SendDataViaActorSystem(table.GetName(), batch, opStatus); } - void ReadData(const TString& query, const TString& expected) { + void ReadData(const TString& query, const TString& expected, const EStatus opStatus = EStatus::SUCCESS) { auto it = TableClient.StreamExecuteScanQuery(query).GetValueSync(); - UNIT_ASSERT_C(it.IsSuccess(), it.GetIssues().ToString()); - TString result = StreamResultToYson(it); - UNIT_ASSERT_NO_DIFF(ReformatYson(result), ReformatYson(expected)); + UNIT_ASSERT_VALUES_EQUAL_C(it.GetStatus(), EStatus::SUCCESS, it.GetIssues().ToString()); + TString result = StreamResultToYson(it, false, opStatus); + if (opStatus == EStatus::SUCCESS) { + UNIT_ASSERT_NO_DIFF(ReformatYson(result), ReformatYson(expected)); + } } void RebootTablets(const TString& tableName) { @@ -4958,7 +4960,7 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { { TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema)); tableInserter.AddRow().Add(1).Add("test_res_1").AddNull(); - testHelper.InsertBulk(testTable, tableInserter, EStatus::SUCCESS); + testHelper.BulkUpsert(testTable, tableInserter); } testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#;#;[\"test_res_1\"]]]"); } @@ -5065,7 +5067,6 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) }; TTestHelper::TColumnTable testTable; - testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); testHelper.CreateTable(testTable); @@ -5076,7 +5077,7 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { } } - Y_UNIT_TEST(DropColumnErrors) { + Y_UNIT_TEST(DropColumn) { TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false; TTestHelper testHelper(runnerSettings); @@ -5086,15 +5087,176 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { TTestHelper::TColumnSchema().SetName("resource_id").SetType(NScheme::NTypeIds::Utf8), TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) }; + TTestHelper::TColumnTable testTable; + testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); + testHelper.CreateTable(testTable); + { + TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema)); + tableInserter.AddRow().Add(1).Add("test_res_1").AddNull(); + tableInserter.AddRow().Add(2).Add("test_res_2").Add(123); + testHelper.InsertData(testTable, tableInserter); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#;[\"test_res_1\"]]]"); + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN resource_id;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#]]"); + testHelper.ReadData("SELECT resource_id FROM `/Root/ColumnTableTest` ", "[[];[]]", EStatus::GENERIC_ERROR); + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN level;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` ", "[[1];[2]]"); + } + + Y_UNIT_TEST(DropColumnOnSchemeChange) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + TTestHelper testHelper(runnerSettings); + + TVector<TTestHelper::TColumnSchema> schema = { + TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false), + TTestHelper::TColumnSchema().SetName("resource_id").SetType(NScheme::NTypeIds::Utf8), + TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) + }; + + TTestHelper::TColumnTable testTable; testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); testHelper.CreateTable(testTable); { + TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema)); + tableInserter.AddRow().Add(1).Add("test_res_1").AddNull(); + testHelper.InsertData(testTable, tableInserter, [&testTable, &testHelper]() { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN resource_id;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + }); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#]]"); + } + + Y_UNIT_TEST(DropColumnOldScheme) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + TTestHelper testHelper(runnerSettings); + + TVector<TTestHelper::TColumnSchema> schema = { + TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false), + TTestHelper::TColumnSchema().SetName("resource_id").SetType(NScheme::NTypeIds::Utf8), + TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) + }; + + TTestHelper::TColumnTable testTable; + + testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); + testHelper.CreateTable(testTable); + { auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN resource_id;"; auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); - UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::BAD_REQUEST, alterResult.GetIssues().ToString()); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } + { + TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema)); + tableInserter.AddRow().Add(1).Add("test_res_1").AddNull(); + testHelper.InsertData(testTable, tableInserter, {}, EStatus::SUCCESS); + } + // testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#]]"); + } + + Y_UNIT_TEST(DropColumnOldSchemeBulkUpsert) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + TTestHelper testHelper(runnerSettings); + + TVector<TTestHelper::TColumnSchema> schema = { + TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false), + TTestHelper::TColumnSchema().SetName("resource_id").SetType(NScheme::NTypeIds::Utf8), + TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) + }; + + TTestHelper::TColumnTable testTable; + + testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); + testHelper.CreateTable(testTable); + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN resource_id;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } + { + TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema)); + tableInserter.AddRow().Add(1).Add("test_res_1").AddNull(); + testHelper.BulkUpsert(testTable, tableInserter, Ydb::StatusIds::SCHEME_ERROR); + } + } + + Y_UNIT_TEST(DropColumnAfterAdd) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + TTestHelper testHelper(runnerSettings); + + TVector<TTestHelper::TColumnSchema> schema = { + TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false), + TTestHelper::TColumnSchema().SetName("resource_id").SetType(NScheme::NTypeIds::Utf8), + TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) + }; + + TTestHelper::TColumnTable testTable; + testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); + testHelper.CreateTable(testTable); + + { + TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema)); + tableInserter.AddRow().Add(1).Add("test_res_1").AddNull(); + tableInserter.AddRow().Add(2).Add("test_res_2").Add(123); + testHelper.InsertData(testTable, tableInserter); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#;[\"test_res_1\"]]]"); + { + schema.push_back(TTestHelper::TColumnSchema().SetName("new_column").SetType(NScheme::NTypeIds::Uint64)); + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` ADD COLUMN new_column Uint64;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#;#;[\"test_res_1\"]]]"); + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN new_column;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString()); + } + testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;#;[\"test_res_1\"]]]"); + } + + Y_UNIT_TEST(DropColumnErrors) { + TKikimrSettings runnerSettings; + runnerSettings.WithSampleTables = false; + TTestHelper testHelper(runnerSettings); + + TVector<TTestHelper::TColumnSchema> schema = { + TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false), + TTestHelper::TColumnSchema().SetName("resource_id").SetType(NScheme::NTypeIds::Utf8), + TTestHelper::TColumnSchema().SetName("level").SetType(NScheme::NTypeIds::Int32) + }; + TTestHelper::TColumnTable testTable; + + testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema); + testHelper.CreateTable(testTable); + + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN unknown_column;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::GENERIC_ERROR, alterResult.GetIssues().ToString()); + } + + { + auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "`DROP COLUMN id;"; + auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::GENERIC_ERROR, alterResult.GetIssues().ToString()); } } @@ -5117,9 +5279,9 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { testHelper.CreateTable(testTable); { - auto alterQuery = TStringBuilder() << "ALTER TABLESTORE `" << testTableStore.GetName() << "`DROP COLUMN resource_id;"; + auto alterQuery = TStringBuilder() << "ALTER TABLESTORE `" << testTableStore.GetName() << "`DROP COLUMN id;"; auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync(); - UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::GENERIC_ERROR, alterResult.GetIssues().ToString()); // EStatus::BAD_REQUEST + UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::GENERIC_ERROR, alterResult.GetIssues().ToString()); } } } diff --git a/ydb/core/testlib/cs_helper.cpp b/ydb/core/testlib/cs_helper.cpp index b090fd6a4f3..a3cf4d59964 100644 --- a/ydb/core/testlib/cs_helper.cpp +++ b/ydb/core/testlib/cs_helper.cpp @@ -59,7 +59,7 @@ void THelperSchemaless::CreateTestOlapTable(TActorId sender, TString storeOrDirN WaitForSchemeOperation(sender, txId); } -void THelperSchemaless::SendDataViaActorSystem(TString testTable, std::shared_ptr<arrow::RecordBatch> batch) const { +void THelperSchemaless::SendDataViaActorSystem(TString testTable, std::shared_ptr<arrow::RecordBatch> batch, const Ydb::StatusIds_StatusCode& expectedStatus) const { auto* runtime = Server.GetRuntime(); UNIT_ASSERT(batch); @@ -87,7 +87,7 @@ void THelperSchemaless::SendDataViaActorSystem(TString testTable, std::shared_pt } Cerr << "\n"; } - UNIT_ASSERT_VALUES_EQUAL(op.status(), Ydb::StatusIds::SUCCESS); + UNIT_ASSERT_VALUES_EQUAL(op.status(), expectedStatus); }); TDispatchOptions options; diff --git a/ydb/core/testlib/cs_helper.h b/ydb/core/testlib/cs_helper.h index 2548e9905a1..d2f6d061622 100644 --- a/ydb/core/testlib/cs_helper.h +++ b/ydb/core/testlib/cs_helper.h @@ -15,7 +15,7 @@ public: void CreateTestOlapStore(TActorId sender, TString scheme); void CreateTestOlapTable(TActorId sender, TString storeOrDirName, TString scheme); void SendDataViaActorSystem(TString testTable, ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui32 tsStepUs = 1) const; - void SendDataViaActorSystem(TString testTable, std::shared_ptr<arrow::RecordBatch> batch) const; + void SendDataViaActorSystem(TString testTable, std::shared_ptr<arrow::RecordBatch> batch, const Ydb::StatusIds_StatusCode& expectedStatus = Ydb::StatusIds::SUCCESS) const; virtual std::shared_ptr<arrow::RecordBatch> TestArrowBatch(ui64 pathIdBegin, ui64 tsBegin, size_t rowCount, const ui32 tsStepUs = 1) const = 0; }; diff --git a/ydb/core/tx/schemeshard/schemeshard_olap_types.cpp b/ydb/core/tx/schemeshard/schemeshard_olap_types.cpp index 40d47523faf..04bea02f57a 100644 --- a/ydb/core/tx/schemeshard/schemeshard_olap_types.cpp +++ b/ydb/core/tx/schemeshard/schemeshard_olap_types.cpp @@ -184,12 +184,14 @@ namespace NKikimr::NSchemeShard { } bool TOlapSchemaUpdate::Parse(const NKikimrSchemeOp::TAlterColumnTableSchema& alterRequest, IErrorCollector& errors) { - TSet<TString> addColumnNames; - if (alterRequest.DropColumnsSize()) { - errors.AddError(NKikimrScheme::StatusInvalidParameter, "Drop columns method not supported for tablestore and table"); - return false; + for (const auto& column: alterRequest.GetDropColumns()) { + if (!DropColumns.emplace(column.GetName()).second) { + errors.AddError(NKikimrScheme::StatusInvalidParameter, "Duplicated column for drop"); + return false; + } } - + + TSet<TString> addColumnNames; for (auto& columnSchema : alterRequest.GetAddColumns()) { TOlapColumnAdd column({}); if (!column.ParseFromRequest(columnSchema, errors)) { @@ -278,6 +280,7 @@ namespace NKikimr::NSchemeShard { } } } + if (KeyColumnIds.empty()) { auto it = orderedKeyColumnIds.begin(); for (ui32 i = 0; i < orderedKeyColumnIds.size(); ++i, ++it) { @@ -289,6 +292,22 @@ namespace NKikimr::NSchemeShard { return false; } } + + for (const auto& columnName : schemaUpdate.GetDropColumns()) { + auto columnInfo = GetColumnByName(columnName); + if (!columnInfo) { + errors.AddError(NKikimrScheme::StatusSchemeError, TStringBuilder() << "Unknown column for drop: " << columnName); + return false; + } + + if (columnInfo->IsKeyColumn()) { + errors.AddError(NKikimrScheme::StatusSchemeError, TStringBuilder() << "Cannot remove pk column: " << columnName); + return false; + } + ColumnsByName.erase(columnName); + Columns.erase(columnInfo->GetId()); + } + ++Version; return true; } diff --git a/ydb/core/tx/schemeshard/schemeshard_olap_types.h b/ydb/core/tx/schemeshard/schemeshard_olap_types.h index 63941ccbd88..f322f2fabe1 100644 --- a/ydb/core/tx/schemeshard/schemeshard_olap_types.h +++ b/ydb/core/tx/schemeshard/schemeshard_olap_types.h @@ -103,6 +103,7 @@ namespace NKikimr::NSchemeShard { class TOlapSchemaUpdate { YDB_READONLY_OPT(NKikimrSchemeOp::EColumnTableEngine, Engine); YDB_READONLY_DEF(TVector<TOlapColumnAdd>, AddColumns); + YDB_READONLY_DEF(TSet<TString>, DropColumns); YDB_READONLY_DEF(TVector<TOlapColumnDiff>, AlterColumns); public: bool Parse(const NKikimrSchemeOp::TColumnTableSchema& tableSchema, IErrorCollector& errors, bool allowNullKeys = false); |