ClickHouse/src/Interpreters/TraceLog.cpp

59 lines
2.0 KiB
C++
Raw Normal View History

2019-02-03 21:30:45 +00:00
#include <Interpreters/TraceLog.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeDateTime64.h>
#include <Common/ClickHouseRevision.h>
2019-02-03 21:30:45 +00:00
2020-07-09 04:15:45 +00:00
namespace DB
{
using TraceDataType = TraceLogElement::TraceDataType;
const TraceDataType::Values TraceLogElement::trace_values =
{
{"Real", static_cast<UInt8>(TraceType::Real)},
{"CPU", static_cast<UInt8>(TraceType::CPU)},
{"Memory", static_cast<UInt8>(TraceType::Memory)},
2020-04-30 13:25:17 +00:00
{"MemorySample", static_cast<UInt8>(TraceType::MemorySample)},
{"MemoryPeak", static_cast<UInt8>(TraceType::MemoryPeak)},
};
2019-02-03 21:30:45 +00:00
NamesAndTypesList TraceLogElement::getNamesAndTypes()
2019-02-03 21:30:45 +00:00
{
return
{
{"event_date", std::make_shared<DataTypeDate>()},
{"event_time", std::make_shared<DataTypeDateTime>()},
{"event_time_microseconds", std::make_shared<DataTypeDateTime64>(6)},
{"timestamp_ns", std::make_shared<DataTypeUInt64>()},
{"revision", std::make_shared<DataTypeUInt32>()},
{"trace_type", std::make_shared<TraceDataType>(trace_values)},
{"thread_id", std::make_shared<DataTypeUInt64>()},
{"query_id", std::make_shared<DataTypeString>()},
{"trace", std::make_shared<DataTypeArray>(std::make_shared<DataTypeUInt64>())},
{"size", std::make_shared<DataTypeInt64>()},
2019-02-03 21:30:45 +00:00
};
}
void TraceLogElement::appendToBlock(MutableColumns & columns) const
2019-02-03 21:30:45 +00:00
{
size_t i = 0;
Extended range of DateTime64 to years 1925 - 2238 The Year 1925 is a starting point because most of the timezones switched to saner (mostly 15-minutes based) offsets somewhere during 1924 or before. And that significantly simplifies implementation. 2238 is to simplify arithmetics for sanitizing LUT index access; there are less than 0x1ffff days from 1925. * Extended DateLUTImpl internal LUT to 0x1ffff items, some of which represent negative (pre-1970) time values. As a collateral benefit, Date now correctly supports dates up to 2149 (instead of 2106). * Added a new strong typedef ExtendedDayNum, which represents dates pre-1970 and post 2149. * Functions that used to return DayNum now return ExtendedDayNum. * Refactored DateLUTImpl to untie DayNum from the dual role of being a value and an index (due to negative time). Index is now a different type LUTIndex with explicit conversion functions from DatNum, time_t, and ExtendedDayNum. * Updated DateLUTImpl to properly support values close to epoch start (1970-01-01 00:00), including negative ones. * Reduced resolution of DateLUTImpl::Values::time_at_offset_change to multiple of 15-minutes to allow storing 64-bits of time_t in DateLUTImpl::Value while keeping same size. * Minor performance updates to DateLUTImpl when building month LUT by skipping non-start-of-month days. * Fixed extractTimeZoneFromFunctionArguments to work correctly with DateTime64. * New unit-tests and stateless integration tests for both DateTime and DateTime64.
2020-04-17 13:26:44 +00:00
columns[i++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType());
2019-02-03 21:30:45 +00:00
columns[i++]->insert(event_time);
columns[i++]->insert(event_time_microseconds);
columns[i++]->insert(timestamp_ns);
2020-09-17 12:15:05 +00:00
columns[i++]->insert(ClickHouseRevision::getVersionRevision());
columns[i++]->insert(static_cast<UInt8>(trace_type));
2020-02-02 02:27:15 +00:00
columns[i++]->insert(thread_id);
2019-02-03 21:30:45 +00:00
columns[i++]->insertData(query_id.data(), query_id.size());
2019-07-05 13:48:47 +00:00
columns[i++]->insert(trace);
2020-01-16 12:37:29 +00:00
columns[i++]->insert(size);
2019-02-03 21:30:45 +00:00
}
2020-07-09 04:15:45 +00:00
}