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();
|
res.emplace_back();
|
||||||
auto & part = res.back();
|
auto & part = res.back();
|
||||||
|
|
||||||
/// First, try to parse as <part_name>.
|
DetachedPartInfo::tryParseDetachedPartName(dir_name, &part, format_version);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -188,4 +188,26 @@ String MergeTreePartInfo::getPartNameV0(DayNum left_date, DayNum right_date) con
|
|||||||
return wb.str();
|
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
|
struct DetachedPartInfo : public MergeTreePartInfo
|
||||||
{
|
{
|
||||||
String prefix;
|
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:
|
protected:
|
||||||
explicit StorageSystemDetachedParts()
|
explicit StorageSystemDetachedParts()
|
||||||
{
|
{
|
||||||
|
// TODO add column "directory_name" or "is_valid_name"
|
||||||
setColumns(ColumnsDescription{{
|
setColumns(ColumnsDescription{{
|
||||||
{"database", std::make_shared<DataTypeString>()},
|
{"database", std::make_shared<DataTypeString>()},
|
||||||
{"table", std::make_shared<DataTypeString>()},
|
{"table", std::make_shared<DataTypeString>()},
|
||||||
|
Loading…
Reference in New Issue
Block a user