Skip to content

Commit bbeb8f6

Browse files
authored
Merge 786e4d2 into 0392fbf
2 parents 0392fbf + 786e4d2 commit bbeb8f6

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10306,6 +10306,28 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) {
1030610306
testTable.SetName(tableName).SetPrimaryKey({ "Key" }).SetSchema(schema).SetColumnFamilies(families);
1030710307
testHelper.CreateTable(testTable, EStatus::GENERIC_ERROR);
1030810308
}
10309+
10310+
Y_UNIT_TEST(DropColumnAndResetTtl) {
10311+
TKikimrSettings runnerSettings;
10312+
runnerSettings.WithSampleTables = false;
10313+
TTestHelper testHelper(runnerSettings);
10314+
10315+
TVector<TTestHelper::TColumnSchema> schema = {
10316+
TTestHelper::TColumnSchema().SetName("id").SetType(NScheme::NTypeIds::Int32).SetNullable(false),
10317+
TTestHelper::TColumnSchema().SetName("timestamp").SetType(NScheme::NTypeIds::Timestamp).SetNullable(false)
10318+
};
10319+
10320+
TTestHelper::TColumnTable testTable;
10321+
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema).SetTTL("timestamp", "Interval(\"PT1H\")");
10322+
testHelper.CreateTable(testTable);
10323+
10324+
{
10325+
auto alterQuery = TStringBuilder() << "ALTER TABLE `" << testTable.GetName() << "` DROP COLUMN timestamp, RESET (TTL);";
10326+
auto alterResult = testHelper.GetSession().ExecuteSchemeQuery(alterQuery).GetValueSync();
10327+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), EStatus::SUCCESS, alterResult.GetIssues().ToString());
10328+
}
10329+
}
10330+
1030910331
}
1031010332

1031110333
Y_UNIT_TEST_SUITE(KqpOlapTypes) {

ydb/core/tx/columnshard/columnshard_ttl.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ class TTtl {
4848

4949
void SetPathTtl(ui64 pathId, TDescription&& descr) {
5050
if (descr.Eviction) {
51-
auto& evict = descr.Eviction;
52-
auto it = Columns.find(evict->ColumnName);
53-
if (it != Columns.end()) {
54-
evict->ColumnName = *it; // replace string dups (memory efficiency)
55-
} else {
56-
Columns.insert(evict->ColumnName);
57-
}
5851
PathTtls[pathId] = descr;
5952
} else {
6053
PathTtls.erase(pathId);
@@ -74,11 +67,16 @@ class TTtl {
7467
return true;
7568
}
7669

77-
const THashSet<TString>& TtlColumns() const { return Columns; }
70+
THashSet<TString> TtlColumns() const {
71+
THashSet<TString> columns;
72+
for (const auto& [pathId, settings] : PathTtls) {
73+
columns.insert(settings.Eviction->ColumnName);
74+
}
75+
return columns;
76+
}
7877

7978
private:
8079
THashMap<ui64, TDescription> PathTtls; // pathId -> ttl
81-
THashSet<TString> Columns;
8280

8381
std::shared_ptr<NOlap::TTierInfo> Convert(const TDescription& descr) const
8482
{

ydb/core/tx/columnshard/tables_manager.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,17 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
317317
AFL_VERIFY(it != Tables.end());
318318
auto& table = it->second;
319319

320+
bool isTtlModified = false;
321+
if (versionInfo.HasTtlSettings()) {
322+
isTtlModified = true;
323+
const auto& ttlSettings = versionInfo.GetTtlSettings();
324+
if (ttlSettings.HasEnabled()) {
325+
Ttl.SetPathTtl(pathId, TTtl::TDescription(ttlSettings.GetEnabled()));
326+
} else {
327+
Ttl.DropPathTtl(pathId);
328+
}
329+
}
330+
320331
if (versionInfo.HasSchemaPresetId()) {
321332
AFL_VERIFY(!schema);
322333
Y_ABORT_UNLESS(SchemaPresetsIds.contains(versionInfo.GetSchemaPresetId()));
@@ -330,13 +341,7 @@ void TTablesManager::AddTableVersion(const ui64 pathId, const NOlap::TSnapshot&
330341
AddSchemaVersion(fakePreset.GetId(), version, *schema, db, manager);
331342
}
332343

333-
if (versionInfo.HasTtlSettings()) {
334-
const auto& ttlSettings = versionInfo.GetTtlSettings();
335-
if (ttlSettings.HasEnabled()) {
336-
Ttl.SetPathTtl(pathId, TTtl::TDescription(ttlSettings.GetEnabled()));
337-
} else {
338-
Ttl.DropPathTtl(pathId);
339-
}
344+
if (isTtlModified) {
340345
if (PrimaryIndex && manager->IsReady()) {
341346
PrimaryIndex->OnTieringModified(manager, Ttl, pathId);
342347
}

0 commit comments

Comments
 (0)