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

53 lines
1.3 KiB
C++
Raw Normal View History

#include <Common/ProfileEvents.h>
#include <Columns/ColumnString.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataStreams/OneBlockInputStream.h>
#include <Storages/System/StorageSystemEvents.h>
namespace DB
{
StorageSystemEvents::StorageSystemEvents(const std::string & name_)
: name(name_),
columns
{
2017-12-02 02:47:12 +00:00
{"event", std::make_shared<DataTypeString>()},
{"value", std::make_shared<DataTypeUInt64>()}
}
{
}
BlockInputStreams StorageSystemEvents::read(
const Names & column_names,
2017-12-02 02:47:12 +00:00
const SelectQueryInfo &,
const Context &,
QueryProcessingStage::Enum & processed_stage,
2017-12-02 02:47:12 +00:00
const size_t /*max_block_size*/,
const unsigned /*num_streams*/)
{
check(column_names);
processed_stage = QueryProcessingStage::FetchColumns;
MutableColumns res_columns = getSampleBlock().cloneEmptyColumns();
for (size_t i = 0, end = ProfileEvents::end(); i < end; ++i)
{
UInt64 value = ProfileEvents::counters[i];
if (0 != value)
{
res_columns[0]->insert(String(ProfileEvents::getDescription(ProfileEvents::Event(i))));
res_columns[1]->insert(value);
}
}
return BlockInputStreams(1, std::make_shared<OneBlockInputStream>(getSampleBlock().cloneWithColumns(std::move(res_columns))));
}
}