| 195 | } |
| 196 | |
| 197 | void makeUniqueColumnNamesInBlock(Block & block) |
| 198 | { |
| 199 | NameSet block_column_names; |
| 200 | size_t unique_column_name_counter = 1; |
| 201 | |
| 202 | for (auto & column_with_type : block) |
| 203 | { |
| 204 | if (block_column_names.insert(column_with_type.name).second) |
| 205 | continue; |
| 206 | |
| 207 | /// The base name collides with a name we have already kept or produced. |
| 208 | /// Loop until we find a suffix that is unused anywhere in the block, |
| 209 | /// including by names we are about to keep and by names we have already |
| 210 | /// renamed. Register the renamed name to prevent further collisions. |
| 211 | /// |
| 212 | /// Example: for input `a, a, a_1`, the second `a` is renamed to `a_1` |
| 213 | /// and the third column (`a_1`) is renamed to `a_2`, instead of leaving |
| 214 | /// the block with two `a_1` columns. |
| 215 | String new_name; |
| 216 | do |
| 217 | { |
| 218 | new_name = column_with_type.name + '_' + std::to_string(unique_column_name_counter); |
| 219 | ++unique_column_name_counter; |
| 220 | } while (!block_column_names.insert(new_name).second); |
| 221 | |
| 222 | column_with_type.name = std::move(new_name); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | bool isExpressionNodeType(QueryTreeNodeType node_type) |
| 227 | { |
no test coverage detected