2019-05-24 19:03:07 +00:00
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <Storages/System/StorageSystemDisks.h>
|
2020-01-24 17:49:14 +00:00
|
|
|
#include <Processors/Sources/SourceFromSingleChunk.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2019-05-24 19:03:07 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StorageSystemDisks::StorageSystemDisks(const std::string & name_)
|
2019-12-03 16:25:32 +00:00
|
|
|
: IStorage({"system", name_})
|
2019-05-24 19:03:07 +00:00
|
|
|
{
|
2020-06-19 15:39:41 +00:00
|
|
|
StorageInMemoryMetadata storage_metadata;
|
|
|
|
storage_metadata.setColumns(ColumnsDescription(
|
2019-05-24 19:03:07 +00:00
|
|
|
{
|
|
|
|
{"name", std::make_shared<DataTypeString>()},
|
|
|
|
{"path", std::make_shared<DataTypeString>()},
|
|
|
|
{"free_space", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"total_space", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"keep_free_space", std::make_shared<DataTypeUInt64>()},
|
|
|
|
}));
|
2020-06-19 15:39:41 +00:00
|
|
|
setInMemoryMetadata(storage_metadata);
|
2019-05-24 19:03:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-19 16:07:28 +00:00
|
|
|
Pipes StorageSystemDisks::read(
|
2019-08-14 15:20:52 +00:00
|
|
|
const Names & column_names,
|
2020-06-16 15:51:29 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot,
|
2019-08-14 15:20:52 +00:00
|
|
|
const SelectQueryInfo & /*query_info*/,
|
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum /*processed_stage*/,
|
|
|
|
const size_t /*max_block_size*/,
|
|
|
|
const unsigned /*num_streams*/)
|
2019-05-24 19:03:07 +00:00
|
|
|
{
|
2020-06-19 17:17:13 +00:00
|
|
|
metadata_snapshot->check(column_names, getVirtuals(), getStorageID());
|
2019-05-24 19:03:07 +00:00
|
|
|
|
2019-09-09 13:50:19 +00:00
|
|
|
MutableColumnPtr col_name = ColumnString::create();
|
|
|
|
MutableColumnPtr col_path = ColumnString::create();
|
|
|
|
MutableColumnPtr col_free = ColumnUInt64::create();
|
|
|
|
MutableColumnPtr col_total = ColumnUInt64::create();
|
|
|
|
MutableColumnPtr col_keep = ColumnUInt64::create();
|
2019-05-24 19:03:07 +00:00
|
|
|
|
2020-05-21 14:11:56 +00:00
|
|
|
for (const auto & [disk_name, disk_ptr] : context.getDisksMap())
|
2019-05-24 19:03:07 +00:00
|
|
|
{
|
2019-09-09 13:50:19 +00:00
|
|
|
col_name->insert(disk_name);
|
|
|
|
col_path->insert(disk_ptr->getPath());
|
|
|
|
col_free->insert(disk_ptr->getAvailableSpace());
|
|
|
|
col_total->insert(disk_ptr->getTotalSpace());
|
|
|
|
col_keep->insert(disk_ptr->getKeepingFreeSpace());
|
2019-05-24 19:03:07 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 18:33:47 +00:00
|
|
|
Columns res_columns;
|
|
|
|
res_columns.emplace_back(std::move(col_name));
|
|
|
|
res_columns.emplace_back(std::move(col_path));
|
|
|
|
res_columns.emplace_back(std::move(col_free));
|
|
|
|
res_columns.emplace_back(std::move(col_total));
|
|
|
|
res_columns.emplace_back(std::move(col_keep));
|
2019-05-24 19:03:07 +00:00
|
|
|
|
2020-01-24 18:33:47 +00:00
|
|
|
UInt64 num_rows = res_columns.at(0)->size();
|
|
|
|
Chunk chunk(std::move(res_columns), num_rows);
|
2020-01-24 17:49:14 +00:00
|
|
|
|
|
|
|
Pipes pipes;
|
2020-06-16 15:51:29 +00:00
|
|
|
pipes.emplace_back(std::make_shared<SourceFromSingleChunk>(metadata_snapshot->getSampleBlock(), std::move(chunk)));
|
2020-01-24 17:49:14 +00:00
|
|
|
|
|
|
|
return pipes;
|
2019-05-24 19:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|