better detached part name parsing

This commit is contained in:
Alexander Tokmakov 2019-07-23 22:43:33 +03:00
parent 3c2172b750
commit ad787938f5
4 changed files with 30 additions and 16 deletions

View File

@ -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;
} }

View File

@ -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;
}
} }

View File

@ -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);
}; };
} }

View File

@ -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>()},