2019-05-20 16:24:36 +00:00
|
|
|
#include <Storages/System/StorageSystemDetachedParts.h>
|
|
|
|
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2019-07-26 20:04:45 +00:00
|
|
|
#include <DataTypes/DataTypeNullable.h>
|
2019-05-20 16:24:36 +00:00
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <ext/shared_ptr_helper.h>
|
|
|
|
#include <Storages/IStorage.h>
|
|
|
|
#include <Storages/System/StorageSystemPartsBase.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements system table 'detached_parts' which allows to get information
|
|
|
|
* about detached data parts for tables of MergeTree family.
|
|
|
|
* We don't use StorageSystemPartsBase, because it introduces virtual _state
|
|
|
|
* column and column aliases which we don't need.
|
|
|
|
*/
|
|
|
|
class StorageSystemDetachedParts :
|
|
|
|
public ext::shared_ptr_helper<StorageSystemDetachedParts>,
|
|
|
|
public IStorage
|
|
|
|
{
|
2019-08-26 19:07:29 +00:00
|
|
|
friend struct ext::shared_ptr_helper<StorageSystemDetachedParts>;
|
2019-05-20 16:24:36 +00:00
|
|
|
public:
|
|
|
|
std::string getName() const override { return "SystemDetachedParts"; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit StorageSystemDetachedParts()
|
2019-12-03 16:25:32 +00:00
|
|
|
: IStorage({"system", "detached_parts"})
|
2019-05-20 16:24:36 +00:00
|
|
|
{
|
|
|
|
setColumns(ColumnsDescription{{
|
|
|
|
{"database", std::make_shared<DataTypeString>()},
|
|
|
|
{"table", std::make_shared<DataTypeString>()},
|
2019-07-26 20:04:45 +00:00
|
|
|
{"partition_id", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>())},
|
2019-05-20 16:24:36 +00:00
|
|
|
{"name", std::make_shared<DataTypeString>()},
|
2019-11-19 06:44:10 +00:00
|
|
|
{"disk", std::make_shared<DataTypeString>()},
|
2019-07-26 20:04:45 +00:00
|
|
|
{"reason", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeString>())},
|
|
|
|
{"min_block_number", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>())},
|
|
|
|
{"max_block_number", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeInt64>())},
|
|
|
|
{"level", std::make_shared<DataTypeNullable>(std::make_shared<DataTypeUInt32>())}
|
2019-05-20 16:24:36 +00:00
|
|
|
}});
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & /* column_names */,
|
|
|
|
const SelectQueryInfo & query_info,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
|
|
|
const size_t /*max_block_size*/,
|
|
|
|
const unsigned /*num_streams*/) override
|
|
|
|
{
|
|
|
|
StoragesInfoStream stream(query_info, context);
|
|
|
|
|
|
|
|
/// Create the result.
|
|
|
|
Block block = getSampleBlock();
|
2019-08-03 11:02:40 +00:00
|
|
|
MutableColumns new_columns = block.cloneEmptyColumns();
|
2019-05-20 16:24:36 +00:00
|
|
|
|
|
|
|
while (StoragesInfo info = stream.next())
|
|
|
|
{
|
|
|
|
const auto parts = info.data->getDetachedParts();
|
|
|
|
for (auto & p : parts)
|
|
|
|
{
|
2019-08-05 16:04:47 +00:00
|
|
|
size_t i = 0;
|
2019-08-03 11:02:40 +00:00
|
|
|
new_columns[i++]->insert(info.database);
|
|
|
|
new_columns[i++]->insert(info.table);
|
2019-08-22 20:38:58 +00:00
|
|
|
new_columns[i++]->insert(p.valid_name ? p.partition_id : Field());
|
|
|
|
new_columns[i++]->insert(p.dir_name);
|
2019-11-19 06:44:10 +00:00
|
|
|
new_columns[i++]->insert(p.disk);
|
2019-08-22 20:38:58 +00:00
|
|
|
new_columns[i++]->insert(p.valid_name ? p.prefix : Field());
|
|
|
|
new_columns[i++]->insert(p.valid_name ? p.min_block : Field());
|
|
|
|
new_columns[i++]->insert(p.valid_name ? p.max_block : Field());
|
|
|
|
new_columns[i++]->insert(p.valid_name ? p.level : Field());
|
2019-05-20 16:24:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(
|
2019-08-03 11:02:40 +00:00
|
|
|
block.cloneWithColumns(std::move(new_columns))));
|
2019-05-20 16:24:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
StoragePtr
|
|
|
|
createDetachedPartsTable()
|
|
|
|
{
|
|
|
|
return StorageSystemDetachedParts::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|