| 58 | |
| 59 | |
| 60 | std::vector<FormattedOutputData> getTableFormattedOutput( |
| 61 | ContextPtr context, |
| 62 | CatalogAdaptorPtr catalog, |
| 63 | const CollectorSettings & collector_settings, |
| 64 | const StatsTableIdentifier & table_info, |
| 65 | const std::vector<String> & column_names) |
| 66 | { |
| 67 | std::vector<FormattedOutputData> results; |
| 68 | StatisticsCollector collector_impl(context, catalog, table_info, collector_settings); |
| 69 | if (column_names.empty()) |
| 70 | { |
| 71 | collector_impl.readAllFromCatalog(); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | auto cols_desc = catalog->filterCollectableColumns(table_info, column_names, true); |
| 76 | collector_impl.readFromCatalogImpl(cols_desc); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | auto plannode_stats_opt = collector_impl.toPlanNodeStatistics(); |
| 81 | if (!plannode_stats_opt.has_value()) |
| 82 | { |
| 83 | return {}; |
| 84 | } |
| 85 | |
| 86 | auto plannode_stats = plannode_stats_opt.value(); |
| 87 | |
| 88 | auto row_count = plannode_stats->getRowCount(); |
| 89 | { |
| 90 | FormattedOutputData fod; |
| 91 | fod.append("identifier", table_info.getTableName() + ".*"); |
| 92 | fod.append("count", row_count); |
| 93 | results.emplace_back(std::move(fod)); |
| 94 | } |
| 95 | |
| 96 | auto symbols = plannode_stats->getSymbolStatistics(); |
| 97 | auto cols_desc = catalog->getAllCollectableColumns(table_info); |
| 98 | for (auto & col : cols_desc) |
| 99 | { |
| 100 | auto symbol_iter = symbols.find(col.name); |
| 101 | if (symbol_iter == symbols.end()) |
| 102 | { |
| 103 | // TODO: should we output empty columns? to ensure no stats is correctly handled |
| 104 | continue; |
| 105 | } |
| 106 | auto & symbol_stats = symbol_iter->second; |
| 107 | |
| 108 | FormattedOutputData fod; |
| 109 | |
| 110 | auto type_name = col.type->getName(); |
| 111 | fod.append("identifier", table_info.getTableName() + "." + col.name); |
| 112 | fod.append("type", type_name); |
| 113 | auto ndv = symbol_stats->getNdv(); |
| 114 | fod.append("ndv", ndv); |
| 115 | |
| 116 | auto null_count = symbol_stats->getNullsCount(); |
| 117 | fod.append("count", row_count - null_count); |
no test coverage detected