mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
dbms: added column sizes to system.columns table [#METR-17475].
This commit is contained in:
parent
c5570f3f89
commit
38d6128150
@ -779,6 +779,13 @@ public:
|
||||
return it == std::end(column_sizes) ? 0 : it->second;
|
||||
}
|
||||
|
||||
using ColumnSizes = std::unordered_map<std::string, size_t>;
|
||||
ColumnSizes getColumnSizes() const
|
||||
{
|
||||
Poco::ScopedLock<Poco::FastMutex> lock{data_parts_mutex};
|
||||
return column_sizes;
|
||||
}
|
||||
|
||||
/// Для ATTACH/DETACH/DROP PARTITION.
|
||||
static String getMonthName(const Field & partition);
|
||||
static DayNum_t getMonthDayNum(const Field & partition);
|
||||
@ -810,7 +817,7 @@ private:
|
||||
|
||||
NamesAndTypesListPtr columns;
|
||||
/// Актуальные размеры столбцов в сжатом виде
|
||||
std::unordered_map<std::string, size_t> column_sizes;
|
||||
ColumnSizes column_sizes;
|
||||
|
||||
BrokenPartCallback broken_part_callback;
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
#include <DB/Storages/StorageSystemColumns.h>
|
||||
#include <DB/Storages/MergeTree/MergeTreeData.h>
|
||||
#include <DB/Storages/StorageMergeTree.h>
|
||||
#include <DB/Storages/StorageReplicatedMergeTree.h>
|
||||
#include <DB/Columns/ColumnString.h>
|
||||
#include <DB/DataTypes/DataTypeString.h>
|
||||
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
||||
#include <DB/DataStreams/OneBlockInputStream.h>
|
||||
#include <DB/Common/VirtualColumnUtils.h>
|
||||
|
||||
@ -15,7 +19,8 @@ StorageSystemColumns::StorageSystemColumns(const std::string & name_)
|
||||
{ "name", new DataTypeString },
|
||||
{ "type", new DataTypeString },
|
||||
{ "default_type", new DataTypeString },
|
||||
{ "default_expression", new DataTypeString }
|
||||
{ "default_expression", new DataTypeString },
|
||||
{ "bytes", new DataTypeUInt64 },
|
||||
}
|
||||
{
|
||||
}
|
||||
@ -103,6 +108,7 @@ BlockInputStreams StorageSystemColumns::read(
|
||||
ColumnPtr type_column = new ColumnString;
|
||||
ColumnPtr default_type_column = new ColumnString;
|
||||
ColumnPtr default_expression_column = new ColumnString;
|
||||
ColumnPtr bytes_column = new ColumnUInt64;
|
||||
|
||||
size_t rows = filtered_database_column->size();
|
||||
for (size_t i = 0; i < rows; ++i)
|
||||
@ -112,6 +118,7 @@ BlockInputStreams StorageSystemColumns::read(
|
||||
|
||||
NamesAndTypesList columns;
|
||||
ColumnDefaults column_defaults;
|
||||
std::unordered_map<String, size_t> column_sizes;
|
||||
|
||||
{
|
||||
StoragePtr storage = storages.at(std::make_pair(database_name, table_name));
|
||||
@ -120,6 +127,26 @@ BlockInputStreams StorageSystemColumns::read(
|
||||
columns = storage->getColumnsList();
|
||||
columns.insert(std::end(columns), std::begin(storage->alias_columns), std::end(storage->alias_columns));
|
||||
column_defaults = storage->column_defaults;
|
||||
|
||||
/** Данные о размерах столбцов для таблиц семейства MergeTree.
|
||||
* NOTE: В дальнейшем можно сделать интерфейс, позволяющий получить размеры столбцов у IStorage.
|
||||
*/
|
||||
if (auto storage_concrete = dynamic_cast<StorageMergeTree *>(storage.get()))
|
||||
{
|
||||
column_sizes = storage_concrete->getData().getColumnSizes();
|
||||
}
|
||||
else if (auto storage_concrete = dynamic_cast<StorageReplicatedMergeTree *>(storage.get()))
|
||||
{
|
||||
column_sizes = storage_concrete->getData().getColumnSizes();
|
||||
|
||||
auto unreplicated_data = storage_concrete->getUnreplicatedData();
|
||||
if (unreplicated_data)
|
||||
{
|
||||
auto unreplicated_column_sizes = unreplicated_data->getColumnSizes();
|
||||
for (const auto & name_size : unreplicated_column_sizes)
|
||||
column_sizes[name_size.first] += name_size.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto & column : columns)
|
||||
@ -129,16 +156,26 @@ BlockInputStreams StorageSystemColumns::read(
|
||||
name_column->insert(column.name);
|
||||
type_column->insert(column.type->getName());
|
||||
|
||||
const auto it = column_defaults.find(column.name);
|
||||
if (it == std::end(column_defaults))
|
||||
{
|
||||
default_type_column->insertDefault();
|
||||
default_expression_column->insertDefault();
|
||||
const auto it = column_defaults.find(column.name);
|
||||
if (it == std::end(column_defaults))
|
||||
{
|
||||
default_type_column->insertDefault();
|
||||
default_expression_column->insertDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
default_type_column->insert(toString(it->second.type));
|
||||
default_expression_column->insert(queryToString(it->second.expression));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
default_type_column->insert(toString(it->second.type));
|
||||
default_expression_column->insert(queryToString(it->second.expression));
|
||||
const auto it = column_sizes.find(column.name);
|
||||
if (it == std::end(column_sizes))
|
||||
bytes_column->insertDefault();
|
||||
else
|
||||
bytes_column->insert(it->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -151,6 +188,7 @@ BlockInputStreams StorageSystemColumns::read(
|
||||
block.insert(ColumnWithTypeAndName(type_column, new DataTypeString, "type"));
|
||||
block.insert(ColumnWithTypeAndName(default_type_column, new DataTypeString, "default_type"));
|
||||
block.insert(ColumnWithTypeAndName(default_expression_column, new DataTypeString, "default_expression"));
|
||||
block.insert(ColumnWithTypeAndName(bytes_column, new DataTypeUInt64, "bytes"));
|
||||
|
||||
return BlockInputStreams{ 1, new OneBlockInputStream(block) };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user