ClickHouse/src/Interpreters/FilesystemCacheLog.cpp

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

81 lines
2.7 KiB
C++
Raw Normal View History

2022-04-30 05:00:40 +00:00
#include <DataTypes/DataTypeDate.h>
#include <DataTypes/DataTypeDateTime.h>
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypesNumber.h>
2022-05-09 19:20:10 +00:00
#include <DataTypes/DataTypeMap.h>
#include <Interpreters/ProfileEventsExt.h>
2022-04-30 05:00:40 +00:00
#include <Interpreters/FilesystemCacheLog.h>
namespace DB
{
2022-07-18 12:09:57 +00:00
static String typeToString(FilesystemCacheLogElement::CacheType type)
2022-04-30 05:00:40 +00:00
{
switch (type)
{
2022-07-18 12:09:57 +00:00
case FilesystemCacheLogElement::CacheType::READ_FROM_CACHE:
2022-04-30 05:00:40 +00:00
return "READ_FROM_CACHE";
2022-07-18 12:09:57 +00:00
case FilesystemCacheLogElement::CacheType::READ_FROM_FS_AND_DOWNLOADED_TO_CACHE:
2022-04-30 05:00:40 +00:00
return "READ_FROM_FS_AND_DOWNLOADED_TO_CACHE";
2022-07-18 12:09:57 +00:00
case FilesystemCacheLogElement::CacheType::READ_FROM_FS_BYPASSING_CACHE:
return "READ_FROM_FS_BYPASSING_CACHE";
case FilesystemCacheLogElement::CacheType::WRITE_THROUGH_CACHE:
2022-09-12 16:53:54 +00:00
return "WRITE_THROUGH_CACHE";
2022-04-30 05:00:40 +00:00
}
__builtin_unreachable();
}
NamesAndTypesList FilesystemCacheLogElement::getNamesAndTypes()
{
DataTypes types{
std::make_shared<DataTypeNumber<UInt64>>(),
std::make_shared<DataTypeNumber<UInt64>>(),
};
return {
{"event_date", std::make_shared<DataTypeDate>()},
{"event_time", std::make_shared<DataTypeDateTime>()},
{"query_id", std::make_shared<DataTypeString>()},
2022-05-03 13:51:26 +00:00
{"source_file_path", std::make_shared<DataTypeString>()},
2022-05-10 14:00:53 +00:00
{"file_segment_range", std::make_shared<DataTypeTuple>(types)},
{"total_requested_range", std::make_shared<DataTypeTuple>(types)},
2022-05-03 13:51:26 +00:00
{"size", std::make_shared<DataTypeUInt64>()},
2022-04-30 05:00:40 +00:00
{"read_type", std::make_shared<DataTypeString>()},
2022-08-29 15:50:27 +00:00
{"read_from_cache_attempted", std::make_shared<DataTypeUInt8>()},
2022-05-09 19:20:10 +00:00
{"ProfileEvents", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeUInt64>())},
{"read_buffer_id", std::make_shared<DataTypeString>()},
2022-04-30 05:00:40 +00:00
};
}
void FilesystemCacheLogElement::appendToBlock(MutableColumns & columns) const
{
size_t i = 0;
columns[i++]->insert(DateLUT::instance().toDayNum(event_time).toUnderType());
columns[i++]->insert(event_time);
columns[i++]->insert(query_id);
2022-05-03 13:51:26 +00:00
columns[i++]->insert(source_file_path);
2022-04-30 13:34:28 +00:00
columns[i++]->insert(Tuple{file_segment_range.first, file_segment_range.second});
2022-05-09 19:20:10 +00:00
columns[i++]->insert(Tuple{requested_range.first, requested_range.second});
2022-05-03 13:51:26 +00:00
columns[i++]->insert(file_segment_size);
2022-07-18 12:09:57 +00:00
columns[i++]->insert(typeToString(cache_type));
2022-08-29 15:50:27 +00:00
columns[i++]->insert(read_from_cache_attempted);
2022-05-09 19:20:10 +00:00
if (profile_counters)
{
auto * column = columns[i++].get();
ProfileEvents::dumpToMapColumn(*profile_counters, column, true);
}
else
{
columns[i++]->insertDefault();
}
columns[i++]->insert(read_buffer_id);
2022-04-30 05:00:40 +00:00
}
2022-05-16 18:59:27 +00:00
}