diff options
author | ilnaz <ilnaz@ydb.tech> | 2023-07-20 11:03:04 +0300 |
---|---|---|
committer | ilnaz <ilnaz@ydb.tech> | 2023-07-20 11:03:04 +0300 |
commit | 04c5f1685ae7fc88b5ee4e52b48f75985078b653 (patch) | |
tree | c35259d69ffc590cde2fa111c2d93391f2378df6 | |
parent | 9b31bd3e66b480b9b9e1582b27c43fb23b9f4b28 (diff) | |
download | ydb-04c5f1685ae7fc88b5ee4e52b48f75985078b653.tar.gz |
Apply TTL's run-interval option KIKIMR-18800
-rw-r--r-- | ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp | 52 | ||||
-rw-r--r-- | ydb/core/ydb_convert/table_description.cpp | 6 | ||||
-rw-r--r-- | ydb/core/ydb_convert/table_settings.h | 2 |
3 files changed, 59 insertions, 1 deletions
diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp index ef7f28a689..5578d6a69f 100644 --- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp +++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp @@ -5181,6 +5181,58 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) { } } + Y_UNIT_TEST(TtlRunInterval) { + TKikimrRunner kikimr; + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().ExtractValueSync().GetSession(); + + const auto ttl = TTtlSettings("Ts", TDuration::Zero()) + .SetRunInterval(TDuration::Minutes(30)); + + // create with ttl + { + auto result = session.CreateTable("/Root/table", TTableBuilder() + .AddNullableColumn("Key", EPrimitiveType::Uint64) + .AddNullableColumn("Ts", EPrimitiveType::Timestamp) + .SetPrimaryKeyColumn("Key") + .SetTtlSettings(ttl) + .Build() + ).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + } + + { + auto result = session.DescribeTable("/Root/table").ExtractValueSync(); + UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); + UNIT_ASSERT_VALUES_EQUAL(result.GetTableDescription().GetTtlSettings()->GetRunInterval(), ttl.GetRunInterval()); + } + + { + auto result = session.AlterTable("/Root/table", TAlterTableSettings() + .BeginAlterTtlSettings() + .Drop() + .EndAlterTtlSettings() + ).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + } + + // alter table set ttl + { + auto result = session.AlterTable("/Root/table", TAlterTableSettings() + .BeginAlterTtlSettings() + .Set(ttl) + .EndAlterTtlSettings() + ).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + } + + { + auto result = session.DescribeTable("/Root/table").ExtractValueSync(); + UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString()); + UNIT_ASSERT_VALUES_EQUAL(result.GetTableDescription().GetTtlSettings()->GetRunInterval(), ttl.GetRunInterval()); + } + } + Y_UNIT_TEST(AddColumn) { TKikimrSettings runnerSettings; runnerSettings.WithSampleTables = false; diff --git a/ydb/core/ydb_convert/table_description.cpp b/ydb/core/ydb_convert/table_description.cpp index a631832d55..65fb0f675f 100644 --- a/ydb/core/ydb_convert/table_description.cpp +++ b/ydb/core/ydb_convert/table_description.cpp @@ -97,6 +97,12 @@ static void AddTtl(TYdbProto& out, const TTtl& inTTL) { default: break; } + + if constexpr (std::is_same_v<TTtl, NKikimrSchemeOp::TTTLSettings::TEnabled>) { + if (inTTL.HasSysSettings() && inTTL.GetSysSettings().HasRunInterval()) { + out.mutable_ttl_settings()->set_run_interval_seconds(TDuration::FromValue(inTTL.GetSysSettings().GetRunInterval()).Seconds()); + } + } } template <typename TYdbProto> diff --git a/ydb/core/ydb_convert/table_settings.h b/ydb/core/ydb_convert/table_settings.h index cc9b4fc488..affdd70e6f 100644 --- a/ydb/core/ydb_convert/table_settings.h +++ b/ydb/core/ydb_convert/table_settings.h @@ -60,7 +60,7 @@ bool FillTtlSettings(TTtlSettingsEnabled& out, const Ydb::Table::TtlSettings& in return unsupported("Unsupported ttl settings"); } - if constexpr (std::is_same_v<TTtlSettingsEnabled, NKikimrSchemeOp::TTTLSettings>) { + if constexpr (std::is_same_v<TTtlSettingsEnabled, NKikimrSchemeOp::TTTLSettings::TEnabled>) { if (in.run_interval_seconds()) { out.MutableSysSettings()->SetRunInterval(TDuration::Seconds(in.run_interval_seconds()).GetValue()); } |