2019-04-15 09:30:45 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataPartTTLInfo.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
2019-10-17 16:01:28 +00:00
|
|
|
#include <Common/quoteString.h>
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
#include <common/JSON.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
void MergeTreeDataPartTTLInfos::update(const MergeTreeDataPartTTLInfos & other_infos)
|
|
|
|
{
|
|
|
|
for (const auto & [name, ttl_info] : other_infos.columns_ttl)
|
|
|
|
{
|
|
|
|
columns_ttl[name].update(ttl_info);
|
2019-07-28 10:30:46 +00:00
|
|
|
updatePartMinMaxTTL(ttl_info.min, ttl_info.max);
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-17 16:01:28 +00:00
|
|
|
for (const auto & [expression, ttl_info] : other_infos.moves_ttl)
|
|
|
|
{
|
|
|
|
moves_ttl[expression].update(ttl_info);
|
|
|
|
}
|
2019-11-26 08:02:48 +00:00
|
|
|
|
|
|
|
table_ttl.update(other_infos.table_ttl);
|
|
|
|
updatePartMinMaxTTL(table_ttl.min, table_ttl.max);
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-17 16:01:28 +00:00
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
void MergeTreeDataPartTTLInfos::read(ReadBuffer & in)
|
|
|
|
{
|
|
|
|
String json_str;
|
|
|
|
readString(json_str, in);
|
|
|
|
assertEOF(in);
|
|
|
|
|
|
|
|
JSON json(json_str);
|
|
|
|
if (json.has("columns"))
|
|
|
|
{
|
2019-11-11 06:52:38 +00:00
|
|
|
const JSON & columns = json["columns"];
|
2020-03-09 01:50:33 +00:00
|
|
|
for (auto col : columns) // NOLINT
|
2019-04-15 09:30:45 +00:00
|
|
|
{
|
|
|
|
MergeTreeDataPartTTLInfo ttl_info;
|
|
|
|
ttl_info.min = col["min"].getUInt();
|
|
|
|
ttl_info.max = col["max"].getUInt();
|
|
|
|
String name = col["name"].getString();
|
|
|
|
columns_ttl.emplace(name, ttl_info);
|
|
|
|
|
2019-07-28 10:30:46 +00:00
|
|
|
updatePartMinMaxTTL(ttl_info.min, ttl_info.max);
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (json.has("table"))
|
|
|
|
{
|
2019-11-11 06:52:38 +00:00
|
|
|
const JSON & table = json["table"];
|
2019-04-15 09:30:45 +00:00
|
|
|
table_ttl.min = table["min"].getUInt();
|
|
|
|
table_ttl.max = table["max"].getUInt();
|
|
|
|
|
2019-07-28 10:30:46 +00:00
|
|
|
updatePartMinMaxTTL(table_ttl.min, table_ttl.max);
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
2019-10-17 16:01:28 +00:00
|
|
|
if (json.has("moves"))
|
|
|
|
{
|
2019-11-11 06:52:38 +00:00
|
|
|
const JSON & moves = json["moves"];
|
2020-03-09 01:50:33 +00:00
|
|
|
for (auto move : moves) // NOLINT
|
2019-10-17 16:01:28 +00:00
|
|
|
{
|
|
|
|
MergeTreeDataPartTTLInfo ttl_info;
|
|
|
|
ttl_info.min = move["min"].getUInt();
|
|
|
|
ttl_info.max = move["max"].getUInt();
|
|
|
|
String expression = move["expression"].getString();
|
|
|
|
moves_ttl.emplace(expression, ttl_info);
|
|
|
|
}
|
|
|
|
}
|
2020-08-31 13:29:31 +00:00
|
|
|
if (json.has("recompression"))
|
|
|
|
{
|
|
|
|
const JSON & moves = json["recompression"];
|
|
|
|
for (auto move : moves) // NOLINT
|
|
|
|
{
|
|
|
|
MergeTreeDataPartTTLInfo ttl_info;
|
|
|
|
ttl_info.min = move["min"].getUInt();
|
|
|
|
ttl_info.max = move["max"].getUInt();
|
|
|
|
String expression = move["expression"].getString();
|
|
|
|
recompression_ttl.emplace(expression, ttl_info);
|
|
|
|
}
|
|
|
|
}
|
2019-04-15 09:30:45 +00:00
|
|
|
}
|
|
|
|
|
2019-10-17 16:01:28 +00:00
|
|
|
|
2019-04-15 09:30:45 +00:00
|
|
|
void MergeTreeDataPartTTLInfos::write(WriteBuffer & out) const
|
|
|
|
{
|
|
|
|
writeString("ttl format version: 1\n", out);
|
|
|
|
writeString("{", out);
|
|
|
|
if (!columns_ttl.empty())
|
|
|
|
{
|
|
|
|
writeString("\"columns\":[", out);
|
|
|
|
for (auto it = columns_ttl.begin(); it != columns_ttl.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != columns_ttl.begin())
|
|
|
|
writeString(",", out);
|
|
|
|
|
2019-10-17 16:01:28 +00:00
|
|
|
writeString("{\"name\":", out);
|
|
|
|
writeString(doubleQuoteString(it->first), out);
|
|
|
|
writeString(",\"min\":", out);
|
2019-04-15 09:30:45 +00:00
|
|
|
writeIntText(it->second.min, out);
|
|
|
|
writeString(",\"max\":", out);
|
|
|
|
writeIntText(it->second.max, out);
|
|
|
|
writeString("}", out);
|
|
|
|
}
|
|
|
|
writeString("]", out);
|
|
|
|
}
|
|
|
|
if (table_ttl.min)
|
|
|
|
{
|
|
|
|
if (!columns_ttl.empty())
|
|
|
|
writeString(",", out);
|
2020-03-09 01:59:08 +00:00
|
|
|
writeString(R"("table":{"min":)", out);
|
2019-04-15 09:30:45 +00:00
|
|
|
writeIntText(table_ttl.min, out);
|
2020-03-09 01:59:08 +00:00
|
|
|
writeString(R"(,"max":)", out);
|
2019-04-15 09:30:45 +00:00
|
|
|
writeIntText(table_ttl.max, out);
|
|
|
|
writeString("}", out);
|
|
|
|
}
|
2019-10-17 16:01:28 +00:00
|
|
|
if (!moves_ttl.empty())
|
|
|
|
{
|
|
|
|
if (!columns_ttl.empty() || table_ttl.min)
|
|
|
|
writeString(",", out);
|
2020-03-09 01:59:08 +00:00
|
|
|
writeString(R"("moves":[)", out);
|
2019-10-17 16:01:28 +00:00
|
|
|
for (auto it = moves_ttl.begin(); it != moves_ttl.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != moves_ttl.begin())
|
|
|
|
writeString(",", out);
|
|
|
|
|
2020-03-09 01:59:08 +00:00
|
|
|
writeString(R"({"expression":)", out);
|
2019-10-17 16:01:28 +00:00
|
|
|
writeString(doubleQuoteString(it->first), out);
|
2020-03-09 01:59:08 +00:00
|
|
|
writeString(R"(,"min":)", out);
|
2019-10-17 16:01:28 +00:00
|
|
|
writeIntText(it->second.min, out);
|
2020-03-09 01:59:08 +00:00
|
|
|
writeString(R"(,"max":)", out);
|
2019-10-17 16:01:28 +00:00
|
|
|
writeIntText(it->second.max, out);
|
|
|
|
writeString("}", out);
|
|
|
|
}
|
|
|
|
writeString("]", out);
|
|
|
|
}
|
2020-08-31 13:29:31 +00:00
|
|
|
if (!recompression_ttl.empty())
|
|
|
|
{
|
|
|
|
if (!moves_ttl.empty() || !columns_ttl.empty() || table_ttl.min)
|
|
|
|
writeString(",", out);
|
|
|
|
|
|
|
|
writeString(R"("recompression":[)", out);
|
|
|
|
for (auto it = recompression_ttl.begin(); it != recompression_ttl.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != recompression_ttl.begin())
|
|
|
|
writeString(",", out);
|
|
|
|
|
|
|
|
writeString(R"({"expression":)", out);
|
|
|
|
writeString(doubleQuoteString(it->first), out);
|
|
|
|
writeString(R"(,"min":)", out);
|
|
|
|
writeIntText(it->second.min, out);
|
|
|
|
writeString(R"(,"max":)", out);
|
|
|
|
writeIntText(it->second.max, out);
|
|
|
|
writeString("}", out);
|
|
|
|
}
|
|
|
|
writeString("]", out);
|
|
|
|
|
|
|
|
}
|
2019-04-15 09:30:45 +00:00
|
|
|
writeString("}", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|