| 235 | } |
| 236 | |
| 237 | String formatSetPretty( |
| 238 | const ActionsDAG::Node * set_node, |
| 239 | std::unordered_map<FutureSet::Hash, String, PreparedSets::Hashing> & subquery_set_names) |
| 240 | { |
| 241 | static constexpr size_t MAX_SET_ELEMENTS_TO_SHOW = 10; |
| 242 | |
| 243 | if (!set_node->column) |
| 244 | return trimColumnIdentifier(set_node->result_name); |
| 245 | |
| 246 | const ColumnSet * column_set = typeid_cast<const ColumnSet *>(&set_node->column->getDataColumn()); |
| 247 | |
| 248 | if (!column_set || !column_set->getData()) |
| 249 | return trimColumnIdentifier(set_node->result_name); |
| 250 | |
| 251 | FutureSetPtr future_set = column_set->getData(); |
| 252 | |
| 253 | if (const auto * from_storage = typeid_cast<const FutureSetFromStorage *>(future_set.get())) |
| 254 | { |
| 255 | if (auto storage_id = from_storage->getStorageID()) |
| 256 | return storage_id->getFullNameNotQuoted(); |
| 257 | return trimColumnIdentifier(set_node->result_name); |
| 258 | } |
| 259 | |
| 260 | if (typeid_cast<const FutureSetFromSubquery *>(future_set.get())) |
| 261 | { |
| 262 | auto [it, inserted] = subquery_set_names.try_emplace( |
| 263 | future_set->getHash(), |
| 264 | fmt::format("subquery{}", subquery_set_names.size() + 1)); |
| 265 | return it->second; |
| 266 | } |
| 267 | |
| 268 | if (auto * from_tuple = typeid_cast<FutureSetFromTuple *>(future_set.get())) |
| 269 | { |
| 270 | Columns key_columns = from_tuple->getKeyColumns(); |
| 271 | if (key_columns.empty()) |
| 272 | return trimColumnIdentifier(set_node->result_name); |
| 273 | |
| 274 | size_t num_rows = key_columns[0]->size(); |
| 275 | size_t num_keys = key_columns.size(); |
| 276 | size_t to_show = std::min(num_rows, MAX_SET_ELEMENTS_TO_SHOW); |
| 277 | |
| 278 | String result = "("; |
| 279 | for (size_t row = 0; row < to_show; ++row) |
| 280 | { |
| 281 | if (row > 0) |
| 282 | result += ", "; |
| 283 | if (num_keys > 1) |
| 284 | result += "("; |
| 285 | for (size_t col = 0; col < num_keys; ++col) |
| 286 | { |
| 287 | if (col > 0) |
| 288 | result += ", "; |
| 289 | Field value; |
| 290 | key_columns[col]->get(row, value); |
| 291 | result += applyVisitor(FieldVisitorToString(), value); |
| 292 | } |
| 293 | if (num_keys > 1) |
| 294 | result += ")"; |
no test coverage detected