MCPcopy Create free account
hub / github.com/ByConity/ByConity / execute

Method execute

src/DataStreams/TTLAggregationAlgorithm.cpp:82–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82void TTLAggregationAlgorithm::execute(Block & block)
83{
84
85 bool some_rows_were_aggregated = false;
86 MutableColumns result_columns = header.cloneEmptyColumns();
87
88 if (!block) /// Empty block -- no more data, but we may still have some accumulated rows
89 {
90 if (!aggregation_result.empty()) /// Still have some aggregated data, let's update TTL
91 {
92 finalizeAggregates(result_columns);
93 some_rows_were_aggregated = true;
94 }
95 else /// No block, all aggregated, just finish
96 {
97 return;
98 }
99 }
100 else
101 {
102 const auto & column_names = header.getNames();
103 MutableColumns aggregate_columns = header.cloneEmptyColumns();
104
105 auto ttl_column = executeExpressionAndGetColumn(description.expression, block, description.result_column);
106 auto where_column = executeExpressionAndGetColumn(description.where_expression, block, description.where_result_column);
107
108 size_t rows_aggregated = 0;
109 size_t current_key_start = 0;
110 size_t rows_with_current_key = 0;
111
112 for (size_t i = 0; i < block.rows(); ++i)
113 {
114 UInt32 cur_ttl = getTimestampByIndex(ttl_column.get(), i);
115 bool where_filter_passed = !where_column || where_column->getBool(i);
116 bool ttl_expired = isTTLExpired(cur_ttl) && where_filter_passed;
117
118 bool same_as_current = true;
119 for (size_t j = 0; j < description.group_by_keys.size(); ++j)
120 {
121 const String & key_column = description.group_by_keys[j];
122 const IColumn * values_column = block.getByName(key_column).column.get();
123 if (!same_as_current || (*values_column)[i] != current_key_value[j])
124 {
125 values_column->get(i, current_key_value[j]);
126 same_as_current = false;
127 }
128 }
129
130 if (!same_as_current)
131 {
132 if (rows_with_current_key)
133 {
134 some_rows_were_aggregated = true;
135 calculateAggregates(aggregate_columns, current_key_start, rows_with_current_key);
136 }
137 finalizeAggregates(result_columns);
138
139 current_key_start = rows_aggregated;

Callers 1

finalizeAggregatesMethod · 0.45

Calls 12

getByNameMethod · 0.80
cloneWithColumnsMethod · 0.80
cloneEmptyColumnsMethod · 0.45
emptyMethod · 0.45
getNamesMethod · 0.45
rowsMethod · 0.45
getMethod · 0.45
getBoolMethod · 0.45
sizeMethod · 0.45
getPositionByNameMethod · 0.45
insertFromMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected