| 193 | |
| 194 | |
| 195 | bool Set::insertFromBlock(const Block & block) |
| 196 | { |
| 197 | std::unique_lock lock(rwlock); |
| 198 | |
| 199 | if (data.empty()) |
| 200 | throw Exception("Method Set::setHeader must be called before Set::insertFromBlock", ErrorCodes::LOGICAL_ERROR); |
| 201 | |
| 202 | ColumnRawPtrs key_columns; |
| 203 | key_columns.reserve(keys_size); |
| 204 | |
| 205 | /// The constant columns to the right of IN are not supported directly. For this, they first materialize. |
| 206 | Columns materialized_columns; |
| 207 | |
| 208 | /// Remember the columns we will work with |
| 209 | for (size_t i = 0; i < keys_size; ++i) |
| 210 | { |
| 211 | materialized_columns.emplace_back(block.safeGetByPosition(i).column->convertToFullColumnIfConst()->convertToFullColumnIfLowCardinality()); |
| 212 | key_columns.emplace_back(materialized_columns.back().get()); |
| 213 | } |
| 214 | |
| 215 | size_t rows = block.rows(); |
| 216 | |
| 217 | /// We will insert to the Set only keys, where all components are not NULL. |
| 218 | ConstNullMapPtr null_map{}; |
| 219 | ColumnPtr null_map_holder; |
| 220 | if (!transform_null_in) |
| 221 | null_map_holder = extractNestedColumnsAndNullMap(key_columns, null_map); |
| 222 | |
| 223 | /// Filter to extract distinct values from the block. |
| 224 | ColumnUInt8::MutablePtr filter; |
| 225 | if (fill_set_elements) |
| 226 | filter = ColumnUInt8::create(block.rows()); |
| 227 | |
| 228 | switch (data.type) |
| 229 | { |
| 230 | case SetVariants::Type::EMPTY: |
| 231 | break; |
| 232 | case SetVariants::Type::bitmap64: |
| 233 | { |
| 234 | if (key_columns.size() == 1) |
| 235 | { |
| 236 | if (const auto * bitmap_column = dynamic_cast<const ColumnBitMap64 *>(key_columns[0]); |
| 237 | bitmap_column) |
| 238 | { |
| 239 | for (size_t i = 0; i < bitmap_column->size(); ++i) |
| 240 | { |
| 241 | bitmap_set |= bitmap_column->getBitMapAt(i); |
| 242 | } |
| 243 | } |
| 244 | else |
| 245 | throw Exception("Not found ColumnBitMap64 when using IN bitmap", ErrorCodes::LOGICAL_ERROR); |
| 246 | } |
| 247 | else |
| 248 | throw Exception("Column size of Set(BitMap64) should be only one when using IN operator", ErrorCodes::LOGICAL_ERROR); |
| 249 | break; |
| 250 | } |
| 251 | #define M(NAME) \ |
| 252 | case SetVariants::Type::NAME: \ |
no test coverage detected