| 342 | |
| 343 | |
| 344 | ColumnPtr Set::execute(const Block & block, bool negative) const |
| 345 | { |
| 346 | size_t num_key_columns = block.columns(); |
| 347 | |
| 348 | if (0 == num_key_columns) |
| 349 | throw Exception("Logical error: no columns passed to Set::execute method.", ErrorCodes::LOGICAL_ERROR); |
| 350 | |
| 351 | auto res = ColumnUInt8::create(); |
| 352 | ColumnUInt8::Container & vec_res = res->getData(); |
| 353 | vec_res.resize(block.safeGetByPosition(0).column->size()); |
| 354 | |
| 355 | if (vec_res.empty()) |
| 356 | return res; |
| 357 | |
| 358 | std::shared_lock lock(rwlock); |
| 359 | |
| 360 | /// If the set is empty. |
| 361 | if (data_types.empty()) |
| 362 | { |
| 363 | if (negative) |
| 364 | memset(vec_res.data(), 1, vec_res.size()); |
| 365 | else |
| 366 | memset(vec_res.data(), 0, vec_res.size()); |
| 367 | return res; |
| 368 | } |
| 369 | |
| 370 | checkColumnsNumber(num_key_columns); |
| 371 | |
| 372 | if (data_types.size() == 1 && isBitmap64(data_types[0]) |
| 373 | && block.columns() == 1 && isInteger(block.safeGetByPosition(0).type)) |
| 374 | { |
| 375 | executeBitmap64(block, vec_res, negative); |
| 376 | return res; |
| 377 | } |
| 378 | |
| 379 | /// Remember the columns we will work with. Also check that the data types are correct. |
| 380 | ColumnRawPtrs key_columns; |
| 381 | key_columns.reserve(num_key_columns); |
| 382 | |
| 383 | /// The constant columns to the left of IN are not supported directly. For this, they first materialize. |
| 384 | Columns materialized_columns; |
| 385 | materialized_columns.reserve(num_key_columns); |
| 386 | |
| 387 | for (size_t i = 0; i < num_key_columns; ++i) |
| 388 | { |
| 389 | ColumnPtr result; |
| 390 | |
| 391 | const auto & column_before_cast = block.safeGetByPosition(i); |
| 392 | ColumnWithTypeAndName column_to_cast |
| 393 | = {column_before_cast.column->convertToFullColumnIfConst(), column_before_cast.type, column_before_cast.name}; |
| 394 | |
| 395 | if (!transform_null_in && data_types[i]->canBeInsideNullable()) |
| 396 | { |
| 397 | result = castColumnAccurateOrNull(column_to_cast, data_types[i]); |
| 398 | } |
| 399 | else |
| 400 | { |
| 401 | result = castColumnAccurate(column_to_cast, data_types[i]); |
no test coverage detected