mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-17 21:24:28 +00:00
better detached part name parsing
This commit is contained in:
parent
3c2172b750
commit
ad787938f5
@ -2579,22 +2579,7 @@ MergeTreeData::getDetachedParts() const
|
||||
res.emplace_back();
|
||||
auto & part = res.back();
|
||||
|
||||
/// First, try to parse as <part_name>.
|
||||
if (MergeTreePartInfo::tryParsePartName(dir_name, &part, format_version))
|
||||
continue;
|
||||
|
||||
/// Next, as <prefix>_<partname>. Use entire name as prefix if it fails.
|
||||
part.prefix = dir_name;
|
||||
const auto first_separator = dir_name.find_first_of('_');
|
||||
if (first_separator == String::npos)
|
||||
continue;
|
||||
|
||||
const auto part_name = dir_name.substr(first_separator + 1,
|
||||
dir_name.size() - first_separator - 1);
|
||||
if (!MergeTreePartInfo::tryParsePartName(part_name, &part, format_version))
|
||||
continue;
|
||||
|
||||
part.prefix = dir_name.substr(0, first_separator);
|
||||
DetachedPartInfo::tryParseDetachedPartName(dir_name, &part, format_version);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -188,4 +188,26 @@ String MergeTreePartInfo::getPartNameV0(DayNum left_date, DayNum right_date) con
|
||||
return wb.str();
|
||||
}
|
||||
|
||||
bool DetachedPartInfo::tryParseDetachedPartName(const String & dir_name, DetachedPartInfo * part_info,
|
||||
MergeTreeDataFormatVersion format_version)
|
||||
{
|
||||
/// First, try to parse as <part_name>.
|
||||
if (MergeTreePartInfo::tryParsePartName(dir_name, part_info, format_version))
|
||||
return part_info->valid_name = true;
|
||||
|
||||
/// Next, as <prefix>_<partname>. Use entire name as prefix if it fails.
|
||||
part_info->prefix = dir_name;
|
||||
const auto first_separator = dir_name.find_first_of('_');
|
||||
if (first_separator == String::npos)
|
||||
return part_info->valid_name = false;
|
||||
|
||||
// TODO what if <prefix> contains '_'?
|
||||
const auto part_name = dir_name.substr(first_separator + 1,
|
||||
dir_name.size() - first_separator - 1);
|
||||
if (!MergeTreePartInfo::tryParsePartName(part_name, part_info, format_version))
|
||||
return part_info->valid_name = false;
|
||||
|
||||
part_info->prefix = dir_name.substr(0, first_separator);
|
||||
return part_info->valid_name = true;
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +93,12 @@ struct MergeTreePartInfo
|
||||
struct DetachedPartInfo : public MergeTreePartInfo
|
||||
{
|
||||
String prefix;
|
||||
|
||||
/// If false, prefix contains full directory name and MergeTreePartInfo may be in invalid state
|
||||
/// (directory name was not successfully parsed).
|
||||
bool valid_name;
|
||||
|
||||
static bool tryParseDetachedPartName(const String & dir_name, DetachedPartInfo * part_info, MergeTreeDataFormatVersion format_version);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public:
|
||||
protected:
|
||||
explicit StorageSystemDetachedParts()
|
||||
{
|
||||
// TODO add column "directory_name" or "is_valid_name"
|
||||
setColumns(ColumnsDescription{{
|
||||
{"database", std::make_shared<DataTypeString>()},
|
||||
{"table", std::make_shared<DataTypeString>()},
|
||||
|
Loading…
Reference in New Issue
Block a user