ClickHouse/src/Interpreters/QueryViewsLog.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
4.2 KiB
C++
Raw Normal View History

2021-06-18 13:44:08 +00:00
#include "QueryViewsLog.h"
2021-06-15 17:10:41 +00:00
#include <Columns/IColumn.h>
#include <Core/Block.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <DataTypes/DataTypeEnum.h>
2021-06-29 13:43:04 +00:00
#include <DataTypes/DataTypeMap.h>
2021-06-15 17:10:41 +00:00
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeUUID.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/ProfileEventsExt.h>
#include <Common/DateLUT.h>
2021-10-02 07:13:14 +00:00
#include <base/types.h>
2021-06-15 17:10:41 +00:00
namespace DB
{
2021-06-29 13:43:04 +00:00
NamesAndTypesList QueryViewsLogElement::getNamesAndTypes()
2021-06-15 17:10:41 +00:00
{
auto view_status_datatype = std::make_shared<DataTypeEnum8>(DataTypeEnum8::Values{
{"QueryStart", static_cast<Int8>(QUERY_START)},
{"QueryFinish", static_cast<Int8>(QUERY_FINISH)},
{"ExceptionBeforeStart", static_cast<Int8>(EXCEPTION_BEFORE_START)},
{"ExceptionWhileProcessing", static_cast<Int8>(EXCEPTION_WHILE_PROCESSING)}});
2021-06-15 17:10:41 +00:00
2021-06-18 13:44:08 +00:00
auto view_type_datatype = std::make_shared<DataTypeEnum8>(DataTypeEnum8::Values{
{"Default", static_cast<Int8>(ViewType::DEFAULT)},
{"Materialized", static_cast<Int8>(ViewType::MATERIALIZED)},
2022-09-09 11:46:53 +00:00
{"Live", static_cast<Int8>(ViewType::LIVE)},
{"Window", static_cast<Int8>(ViewType::WINDOW)}});
2021-06-18 13:44:08 +00:00
2021-06-15 17:10:41 +00:00
return {
2021-06-29 13:43:04 +00:00
{"event_date", std::make_shared<DataTypeDate>()},
{"event_time", std::make_shared<DataTypeDateTime>()},
{"event_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
{"view_duration_ms", std::make_shared<DataTypeUInt64>()},
2021-06-15 17:10:41 +00:00
2021-06-29 13:43:04 +00:00
{"initial_query_id", std::make_shared<DataTypeString>()},
{"view_name", std::make_shared<DataTypeString>()},
{"view_uuid", std::make_shared<DataTypeUUID>()},
{"view_type", std::move(view_type_datatype)},
{"view_query", std::make_shared<DataTypeString>()},
{"view_target", std::make_shared<DataTypeString>()},
2021-06-15 17:10:41 +00:00
2021-06-29 13:43:04 +00:00
{"read_rows", std::make_shared<DataTypeUInt64>()},
{"read_bytes", std::make_shared<DataTypeUInt64>()},
{"written_rows", std::make_shared<DataTypeUInt64>()},
{"written_bytes", std::make_shared<DataTypeUInt64>()},
{"peak_memory_usage", std::make_shared<DataTypeInt64>()},
{"ProfileEvents", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeUInt64>())},
2021-06-15 17:10:41 +00:00
2021-06-29 13:43:04 +00:00
{"status", std::move(view_status_datatype)},
{"exception_code", std::make_shared<DataTypeInt32>()},
{"exception", std::make_shared<DataTypeString>()},
{"stack_trace", std::make_shared<DataTypeString>()}};
}
NamesAndAliases QueryViewsLogElement::getNamesAndAliases()
{
return {
{"ProfileEvents.Names", {std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())}, "mapKeys(ProfileEvents)"},
{"ProfileEvents.Values", {std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>())}, "mapValues(ProfileEvents)"}};
2021-06-15 17:10:41 +00:00
}
2021-06-18 13:44:08 +00:00
void QueryViewsLogElement::appendToBlock(MutableColumns & columns) const
2021-06-15 17:10:41 +00:00
{
size_t i = 0;
columns[i++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType()); // event_date
columns[i++]->insert(event_time);
columns[i++]->insert(event_time_microseconds);
2021-06-18 13:44:08 +00:00
columns[i++]->insert(view_duration_ms);
2021-06-15 17:10:41 +00:00
columns[i++]->insertData(initial_query_id.data(), initial_query_id.size());
2021-06-18 13:44:08 +00:00
columns[i++]->insertData(view_name.data(), view_name.size());
columns[i++]->insert(view_uuid);
columns[i++]->insert(view_type);
columns[i++]->insertData(view_query.data(), view_query.size());
columns[i++]->insertData(view_target.data(), view_target.size());
2021-06-15 17:10:41 +00:00
columns[i++]->insert(read_rows);
columns[i++]->insert(read_bytes);
columns[i++]->insert(written_rows);
columns[i++]->insert(written_bytes);
columns[i++]->insert(peak_memory_usage);
if (profile_counters)
{
2021-06-29 13:43:04 +00:00
auto * column = columns[i++].get();
ProfileEvents::dumpToMapColumn(*profile_counters, column, true);
2021-06-15 17:10:41 +00:00
}
else
{
columns[i++]->insertDefault();
}
columns[i++]->insert(status);
2021-06-15 17:10:41 +00:00
columns[i++]->insert(exception_code);
columns[i++]->insertData(exception.data(), exception.size());
columns[i++]->insertData(stack_trace.data(), stack_trace.size());
}
}