2017-04-01 09:19:00 +00:00
|
|
|
#include <Columns/ColumnsNumber.h>
|
|
|
|
#include <Columns/ColumnArray.h>
|
|
|
|
#include <Columns/ColumnString.h>
|
|
|
|
#include <DataTypes/DataTypeArray.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeString.h>
|
2017-06-25 00:01:10 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataPart.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/PartLog.h>
|
2017-03-07 17:13:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-06-25 00:01:10 +00:00
|
|
|
|
2017-03-07 17:13:54 +00:00
|
|
|
Block PartLogElement::createBlock()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
return
|
|
|
|
{
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "event_type"},
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt16::create(), std::make_shared<DataTypeDate>(), "event_date"},
|
|
|
|
{ColumnUInt32::create(), std::make_shared<DataTypeDateTime>(), "event_time"},
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "size_in_bytes"},
|
|
|
|
{ColumnUInt64::create(), std::make_shared<DataTypeUInt64>(), "duration_ms"},
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-14 01:43:19 +00:00
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "database"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "table"},
|
|
|
|
{ColumnString::create(), std::make_shared<DataTypeString>(), "part_name"},
|
|
|
|
{ColumnArray::create(ColumnString::create()),
|
2017-04-01 07:20:54 +00:00
|
|
|
std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>()), "merged_from"},
|
2017-03-07 17:13:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void PartLogElement::appendToBlock(Block & block) const
|
|
|
|
{
|
2017-12-15 18:23:05 +00:00
|
|
|
MutableColumns columns = block.mutateColumns();
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t i = 0;
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(event_type));
|
|
|
|
columns[i++]->insert(UInt64(DateLUT::instance().toDayNum(event_time)));
|
|
|
|
columns[i++]->insert(UInt64(event_time));
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(UInt64(size_in_bytes));
|
|
|
|
columns[i++]->insert(UInt64(duration_ms));
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-12-15 18:23:05 +00:00
|
|
|
columns[i++]->insert(database_name);
|
|
|
|
columns[i++]->insert(table_name);
|
|
|
|
columns[i++]->insert(part_name);
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Array merged_from_array;
|
|
|
|
merged_from_array.reserve(merged_from.size());
|
|
|
|
for (const auto & name : merged_from)
|
|
|
|
merged_from_array.push_back(name);
|
2017-12-15 18:23:05 +00:00
|
|
|
|
|
|
|
columns[i++]->insert(merged_from_array);
|
|
|
|
|
|
|
|
block.setColumns(std::move(columns));
|
2017-03-07 17:13:54 +00:00
|
|
|
}
|
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
void PartLog::addNewPart(const MergeTreeDataPart & part, double elapsed)
|
|
|
|
{
|
|
|
|
PartLogElement elem;
|
|
|
|
elem.event_time = time(nullptr);
|
|
|
|
|
|
|
|
elem.event_type = PartLogElement::NEW_PART;
|
|
|
|
elem.size_in_bytes = part.size_in_bytes;
|
|
|
|
elem.duration_ms = elapsed / 1000000;
|
|
|
|
|
|
|
|
elem.database_name = part.storage.getDatabaseName();
|
|
|
|
elem.table_name = part.storage.getTableName();
|
|
|
|
elem.part_name = part.name;
|
2017-03-07 17:13:54 +00:00
|
|
|
|
2017-06-25 00:01:10 +00:00
|
|
|
add(elem);
|
|
|
|
}
|
2017-03-07 17:13:54 +00:00
|
|
|
|
|
|
|
}
|