ClickHouse/dbms/src/Storages/System/StorageSystemPartsColumns.cpp

170 lines
8.0 KiB
C++
Raw Normal View History

#include "StorageSystemPartsColumns.h"
#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/VirtualColumnUtils.h>
#include <Databases/IDatabase.h>
#include <Parsers/queryToString.h>
namespace DB
{
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>()},
{"rows", std::make_shared<DataTypeUInt64>()},
{"bytes_on_disk", std::make_shared<DataTypeUInt64>()},
{"data_compressed_bytes", std::make_shared<DataTypeUInt64>()},
{"data_uncompressed_bytes", std::make_shared<DataTypeUInt64>()},
{"marks_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>()},
{"partition_id", std::make_shared<DataTypeString>()},
{"min_block_number", std::make_shared<DataTypeInt64>()},
{"max_block_number", std::make_shared<DataTypeInt64>()},
{"level", std::make_shared<DataTypeUInt32>()},
{"data_version", std::make_shared<DataTypeUInt64>()},
{"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>()},
{"disk_name", std::make_shared<DataTypeString>()}, ///@TODO_IGR ASK is is OK?
{"path", std::make_shared<DataTypeString>()},
{"column", std::make_shared<DataTypeString>()},
2019-07-04 18:27:14 +00:00
{"type", std::make_shared<DataTypeString>()},
{"default_kind", std::make_shared<DataTypeString>()},
{"default_expression", std::make_shared<DataTypeString>()},
{"column_bytes_on_disk", std::make_shared<DataTypeUInt64>()},
{"column_data_compressed_bytes", std::make_shared<DataTypeUInt64>()},
{"column_data_uncompressed_bytes", std::make_shared<DataTypeUInt64>()},
2019-07-05 15:32:55 +00:00
{"column_marks_bytes", std::make_shared<DataTypeUInt64>()}
}
)
{
}
2017-12-28 18:20:53 +00:00
void StorageSystemPartsColumns::processNextStorage(MutableColumns & columns, const StoragesInfo & info, bool has_state_column)
{
/// Prepare information about columns in storage.
struct ColumnInfo
{
String default_kind;
String default_expression;
};
std::unordered_map<String, ColumnInfo> columns_info;
for (const auto & column : info.storage->getColumns())
{
ColumnInfo column_info;
if (column.default_desc.expression)
{
column_info.default_kind = toString(column.default_desc.kind);
column_info.default_expression = queryToString(column.default_desc.expression);
}
columns_info[column.name] = column_info;
}
/// Go through the list of parts.
MergeTreeData::DataPartStateVector all_parts_state;
MergeTreeData::DataPartsVector all_parts;
all_parts = info.getParts(all_parts_state, has_state_column);
for (size_t part_number = 0; part_number < all_parts.size(); ++part_number)
{
const auto & part = all_parts[part_number];
auto part_state = all_parts_state[part_number];
auto columns_size = part->getTotalColumnsSize();
/// 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();
using State = MergeTreeDataPart::State;
for (const auto & column : part->columns)
2019-07-04 18:27:14 +00:00
{
size_t j = 0;
{
WriteBufferFromOwnString out;
part->partition.serializeText(*info.data, out, format_settings);
2017-12-28 18:20:53 +00:00
columns[j++]->insert(out.str());
}
2017-12-28 18:20:53 +00:00
columns[j++]->insert(part->name);
columns[j++]->insert(part_state == State::Committed);
2019-03-25 13:55:24 +00:00
columns[j++]->insert(part->getMarksCount());
2017-12-28 18:20:53 +00:00
columns[j++]->insert(part->rows_count);
columns[j++]->insert(part->bytes_on_disk.load(std::memory_order_relaxed));
columns[j++]->insert(columns_size.data_compressed);
columns[j++]->insert(columns_size.data_uncompressed);
columns[j++]->insert(columns_size.marks);
columns[j++]->insert(UInt64(part->modification_time));
columns[j++]->insert(UInt64(part->remove_time.load(std::memory_order_relaxed)));
2017-12-28 18:20:53 +00:00
columns[j++]->insert(UInt64(use_count));
2017-12-28 18:20:53 +00:00
columns[j++]->insert(min_date);
columns[j++]->insert(max_date);
columns[j++]->insert(part->info.partition_id);
2017-12-28 18:20:53 +00:00
columns[j++]->insert(part->info.min_block);
columns[j++]->insert(part->info.max_block);
columns[j++]->insert(part->info.level);
columns[j++]->insert(UInt64(part->info.getDataVersion()));
columns[j++]->insert(index_size_in_bytes);
columns[j++]->insert(index_size_in_allocated_bytes);
2017-12-28 18:20:53 +00:00
columns[j++]->insert(info.database);
columns[j++]->insert(info.table);
columns[j++]->insert(info.engine);
columns[j++]->insert(part->disk->getName());
columns[j++]->insert(part->getFullPath());
2017-12-28 18:20:53 +00:00
columns[j++]->insert(column.name);
columns[j++]->insert(column.type->getName());
auto column_info_it = columns_info.find(column.name);
if (column_info_it != columns_info.end())
{
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);
}
else
{
2017-12-28 18:20:53 +00:00
columns[j++]->insertDefault();
columns[j++]->insertDefault();
}
ColumnSize column_size = part->getColumnSize(column.name, *column.type);
columns[j++]->insert(column_size.data_compressed + column_size.marks);
columns[j++]->insert(column_size.data_compressed);
columns[j++]->insert(column_size.data_uncompressed);
columns[j++]->insert(column_size.marks);
if (has_state_column)
2017-12-28 18:20:53 +00:00
columns[j++]->insert(part->stateString());
}
}
}
}