2017-12-04 15:44:31 +00:00
|
|
|
#include <Common/escapeForFileName.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataStreams/OneBlockInputStream.h>
|
|
|
|
#include <Storages/System/StorageSystemPartsColumns.h>
|
|
|
|
#include <Storages/StorageReplicatedMergeTree.h>
|
|
|
|
#include <Storages/VirtualColumnUtils.h>
|
|
|
|
#include <Databases/IDatabase.h>
|
2017-12-04 15:53:18 +00:00
|
|
|
#include <Parsers/queryToString.h>
|
2017-12-04 15:44:31 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
StorageSystemPartsColumns::StorageSystemPartsColumns(const std::string & name)
|
|
|
|
: StorageSystemPartsBase(name,
|
|
|
|
{
|
|
|
|
{"partition", std::make_shared<DataTypeString>()},
|
|
|
|
{"name", std::make_shared<DataTypeString>()},
|
|
|
|
{"active", std::make_shared<DataTypeUInt8>()},
|
|
|
|
{"marks", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"marks_bytes_in_block", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"rows", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"bytes", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"modification_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"remove_time", std::make_shared<DataTypeDateTime>()},
|
|
|
|
{"refcount", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"min_date", std::make_shared<DataTypeDate>()},
|
|
|
|
{"max_date", std::make_shared<DataTypeDate>()},
|
|
|
|
{"min_block_number", std::make_shared<DataTypeInt64>()},
|
|
|
|
{"max_block_number", std::make_shared<DataTypeInt64>()},
|
|
|
|
{"level", std::make_shared<DataTypeUInt32>()},
|
|
|
|
{"primary_key_bytes_in_memory", std::make_shared<DataTypeUInt64>()},
|
|
|
|
{"primary_key_bytes_in_memory_allocated", std::make_shared<DataTypeUInt64>()},
|
|
|
|
|
|
|
|
{"database", std::make_shared<DataTypeString>()},
|
|
|
|
{"table", std::make_shared<DataTypeString>()},
|
|
|
|
{"engine", std::make_shared<DataTypeString>()},
|
|
|
|
{"column", std::make_shared<DataTypeString>()},
|
|
|
|
{ "type", std::make_shared<DataTypeString>() },
|
|
|
|
{ "default_kind", std::make_shared<DataTypeString>() },
|
|
|
|
{ "default_expression", std::make_shared<DataTypeString>() },
|
|
|
|
{ "data_compressed_bytes", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "data_uncompressed_bytes", std::make_shared<DataTypeUInt64>() },
|
|
|
|
{ "marks_bytes_in_column", std::make_shared<DataTypeUInt64>() },
|
|
|
|
}
|
|
|
|
)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-12-28 18:20:53 +00:00
|
|
|
void StorageSystemPartsColumns::processNextStorage(MutableColumns & columns, const StoragesInfo & info, bool has_state_column)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
/// Prepare information about columns in storage.
|
|
|
|
struct ColumnInfo
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
String default_kind;
|
|
|
|
String default_expression;
|
|
|
|
};
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-28 18:20:53 +00:00
|
|
|
NamesAndTypesList columns_list = info.storage->getColumnsList();
|
|
|
|
columns_list.insert(std::end(columns_list), std::begin(info.storage->alias_columns), std::end(info.storage->alias_columns));
|
2017-12-12 15:54:03 +00:00
|
|
|
column_defaults = info.storage->column_defaults;
|
|
|
|
std::unordered_map<String, ColumnInfo> columns_info;
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-28 18:20:53 +00:00
|
|
|
for (const auto & column : columns_list)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
ColumnInfo column_info;
|
2017-12-04 15:53:18 +00:00
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
const auto it = column_defaults.find(column.name);
|
|
|
|
if (it != std::end(column_defaults))
|
2017-12-04 15:53:18 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
column_info.default_kind = toString(it->second.type);
|
|
|
|
column_info.default_expression = queryToString(it->second.expression);
|
2017-12-04 15:53:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
columns_info[column.name] = column_info;
|
2017-12-04 15:44:31 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
/// Go through the list of parts.
|
|
|
|
for (size_t part_number = 0; part_number < info.all_parts.size(); ++part_number)
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
const auto & part = info.all_parts[part_number];
|
|
|
|
auto part_state = info.all_parts_state[part_number];
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
auto total_mrk_size_in_bytes = part->getTotalMrkSizeInBytes();
|
|
|
|
/// For convenience, in returned refcount, don't add references that was due to local variables in this method: all_parts, active_parts.
|
|
|
|
auto use_count = part.use_count() - 1;
|
|
|
|
auto min_date = part->getMinDate();
|
|
|
|
auto max_date = part->getMaxDate();
|
|
|
|
auto index_size_in_bytes = part->getIndexSizeInBytes();
|
|
|
|
auto index_size_in_allocated_bytes = part->getIndexSizeInAllocatedBytes();
|
2017-12-04 15:44:31 +00:00
|
|
|
|
|
|
|
using State = MergeTreeDataPart::State;
|
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
for (const auto & column : part->columns)
|
2017-12-04 15:53:18 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
size_t j = 0;
|
2017-12-04 15:53:18 +00:00
|
|
|
{
|
2017-12-12 15:54:03 +00:00
|
|
|
WriteBufferFromOwnString out;
|
|
|
|
part->partition.serializeTextQuoted(*info.data, out);
|
2017-12-28 18:20:53 +00:00
|
|
|
columns[j++]->insert(out.str());
|
2017-12-04 15:53:18 +00:00
|
|
|
}
|
2017-12-28 18:20:53 +00:00
|
|
|
columns[j++]->insert(part->name);
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part_state == State::Committed));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->marks_count));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(total_mrk_size_in_bytes));
|
|
|
|
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->rows_count));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->size_in_bytes));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->modification_time));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->remove_time));
|
|
|
|
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(use_count));
|
|
|
|
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(min_date));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(max_date));
|
|
|
|
columns[j++]->insert(part->info.min_block);
|
|
|
|
columns[j++]->insert(part->info.max_block);
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->info.level));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(index_size_in_bytes));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(index_size_in_allocated_bytes));
|
|
|
|
|
|
|
|
columns[j++]->insert(info.database);
|
|
|
|
columns[j++]->insert(info.table);
|
|
|
|
columns[j++]->insert(info.engine);
|
|
|
|
columns[j++]->insert(column.name);
|
|
|
|
columns[j++]->insert(column.type->getName());
|
2017-12-12 15:54:03 +00:00
|
|
|
|
|
|
|
auto column_info_it = columns_info.find(column.name);
|
|
|
|
if (column_info_it != columns_info.end())
|
2017-12-04 15:44:31 +00:00
|
|
|
{
|
2017-12-28 18:20:53 +00:00
|
|
|
columns[j++]->insert(column_info_it->second.default_kind);
|
|
|
|
columns[j++]->insert(column_info_it->second.default_expression);
|
2017-12-12 15:54:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-28 18:20:53 +00:00
|
|
|
columns[j++]->insertDefault();
|
|
|
|
columns[j++]->insertDefault();
|
2017-12-12 15:54:03 +00:00
|
|
|
}
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2018-01-12 12:50:59 +00:00
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->getColumnCompressedSize(column.name)));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->getColumnUncompressedSize(column.name)));
|
|
|
|
columns[j++]->insert(static_cast<UInt64>(part->getColumnMrkSize(column.name)));
|
2017-12-04 15:44:31 +00:00
|
|
|
|
2017-12-12 15:54:03 +00:00
|
|
|
if (has_state_column)
|
2017-12-28 18:20:53 +00:00
|
|
|
columns[j++]->insert(part->stateString());
|
2017-12-04 15:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|