| 101 | } |
| 102 | |
| 103 | static Array extractMapColumnKeys(const MergeTreeMetaBase & data, const MergeTreeMetaBase::DataPartsVector & parts) |
| 104 | { |
| 105 | Array res; |
| 106 | |
| 107 | std::unordered_map<String, DataTypePtr> map_types; |
| 108 | std::unordered_map<String, MutableColumnPtr> map_keys; |
| 109 | /// get all map columns from storage |
| 110 | StorageMetadataPtr metadata = data.getInMemoryMetadataPtr(); |
| 111 | const auto & columns = metadata->getColumns(); |
| 112 | for (auto it = columns.begin(); it != columns.end(); it++) |
| 113 | { |
| 114 | if (it->type->isMap() && it->type->isByteMap()) |
| 115 | map_types[it->name] = it->type; |
| 116 | } |
| 117 | |
| 118 | Poco::Logger * logger = nullptr; |
| 119 | for (auto & part : parts) |
| 120 | { |
| 121 | for (auto & [file, _] : part->getChecksums()->files) |
| 122 | { |
| 123 | if (!isMapImplicitKey(file) || isMapBaseFile(file)) |
| 124 | continue; |
| 125 | |
| 126 | String map_name = parseMapNameFromImplicitFileName(file); |
| 127 | if (!isMapImplicitDataFileNameNotBaseOfSpecialMapName(file, map_name)) |
| 128 | continue; |
| 129 | String key_name = parseKeyNameFromImplicitFileName(file, map_name); |
| 130 | |
| 131 | if (!map_types.count(map_name)) |
| 132 | { |
| 133 | if (unlikely(logger == nullptr)) |
| 134 | logger = &Poco::Logger::get(data.getLogName() + " (ExtractMapKeys)"); |
| 135 | LOG_WARNING(logger, "Can not find byte map column {} of implicit file {}", map_name, file); |
| 136 | continue; |
| 137 | } |
| 138 | auto type = map_types[map_name]; |
| 139 | auto map_key_type = static_cast<const DataTypeMap *>(type.get())->getKeyType(); |
| 140 | if (!map_keys.count(map_name)) |
| 141 | map_keys[map_name] = IColumn::mutate(map_key_type->createColumn()); |
| 142 | |
| 143 | map_keys[map_name]->insert(map_key_type->stringToVisitorField(key_name)); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | for (auto & [map_name, column] : map_keys) |
| 148 | { |
| 149 | auto type_it = map_types.find(map_name); |
| 150 | if (type_it == map_types.end()) |
| 151 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Can not find column {}", map_name); |
| 152 | |
| 153 | auto map_key_type = static_cast<const DataTypeMap *>(type_it->second.get())->getKeyType(); |
| 154 | auto serialization = map_key_type->getDefaultSerialization(); |
| 155 | |
| 156 | for (size_t i = 0; i < column->size(); ++i) |
| 157 | { |
| 158 | WriteBufferFromOwnString buffer; |
| 159 | serialization->serializeText(*column, i, buffer, {}); |
| 160 | res.push_back(Tuple{map_name, buffer.str()}); |
no test coverage detected