1#include "ProfileEventsExt.h"
2#include <Common/typeid_cast.h>
3#include <Columns/ColumnsNumber.h>
4#include <Columns/ColumnString.h>
5#include <Columns/ColumnArray.h>
6#include <DataTypes/DataTypesNumber.h>
7#include <DataTypes/DataTypeString.h>
8#include <DataTypes/DataTypeArray.h>
9
10namespace ProfileEvents
11{
12
13/// Put implementation here to avoid extra linking dependencies for clickhouse_common_io
14void dumpToArrayColumns(const Counters & counters, DB::IColumn * column_names_, DB::IColumn * column_values_, bool nonzero_only)
15{
16 /// Convert ptr and make simple check
17 auto column_names = (column_names_) ? &typeid_cast<DB::ColumnArray &>(*column_names_) : nullptr;
18 auto column_values = (column_values_) ? &typeid_cast<DB::ColumnArray &>(*column_values_) : nullptr;
19
20 size_t size = 0;
21
22 for (Event event = 0; event < Counters::num_counters; ++event)
23 {
24 UInt64 value = counters[event].load(std::memory_order_relaxed);
25
26 if (nonzero_only && 0 == value)
27 continue;
28
29 ++size;
30
31 if (column_names)
32 {
33 const char * desc = ProfileEvents::getName(event);
34 column_names->getData().insertData(desc, strlen(desc));
35 }
36
37 if (column_values)
38 column_values->getData().insert(value);
39 }
40
41 if (column_names)
42 {
43 auto & offsets = column_names->getOffsets();
44 offsets.push_back(offsets.back() + size);
45 }
46
47 if (column_values)
48 {
49 /// Nested columns case
50 bool the_same_offsets = column_names && column_names->getOffsetsPtr().get() == column_values->getOffsetsPtr().get();
51 if (!the_same_offsets)
52 {
53 auto & offsets = column_values->getOffsets();
54 offsets.push_back(offsets.back() + size);
55 }
56 }
57}
58
59}
60