| 354 | } |
| 355 | |
| 356 | MergeTreeMetaBase::MutableDataPartPtr MergeTreeDataWriter::writeTempPart( |
| 357 | BlockWithPartition & block_with_partition, const StorageMetadataPtr & metadata_snapshot, ContextPtr context, UInt64 block_id, Int64 mutation, Int64 hint_mutation) |
| 358 | { |
| 359 | Block & block = block_with_partition.block; |
| 360 | Int64 bucket_number = block_with_partition.bucket_info.bucket_number; |
| 361 | |
| 362 | auto columns = metadata_snapshot->getColumns().getAllPhysical().filter(block.getNames()); |
| 363 | auto storage_snapshot = data.getStorageSnapshot(metadata_snapshot, context); |
| 364 | |
| 365 | if (metadata_snapshot->hasDynamicSubcolumns()) |
| 366 | { |
| 367 | convertDynamicColumnsToTuples(block, storage_snapshot); |
| 368 | } |
| 369 | |
| 370 | for (auto & column : columns) |
| 371 | if (column.type->hasDynamicSubcolumns()) |
| 372 | column.type = block.getByName(column.name).type; |
| 373 | |
| 374 | static const String TMP_PREFIX = "tmp_insert_"; |
| 375 | |
| 376 | /// This will generate unique name in scope of current server process. |
| 377 | Int64 temp_index = block_id ? block_id : data.insert_increment.get(); |
| 378 | |
| 379 | IMergeTreeDataPart::MinMaxIndex minmax_idx; |
| 380 | minmax_idx.update(block, data.getMinMaxColumnsNames(metadata_snapshot->getPartitionKey())); |
| 381 | |
| 382 | MergeTreePartition partition(std::move(block_with_partition.partition)); |
| 383 | |
| 384 | MergeTreePartInfo new_part_info( |
| 385 | partition.getID(metadata_snapshot->getPartitionKey().sample_block, data.extractNullableForPartitionID()), |
| 386 | /*min_block_*/temp_index, |
| 387 | /*max_block_*/temp_index, |
| 388 | /*level_*/0, |
| 389 | mutation, |
| 390 | hint_mutation); |
| 391 | String part_name; |
| 392 | if (data.format_version < MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING) |
| 393 | { |
| 394 | DayNum min_date(minmax_idx.hyperrectangle[data.minmax_idx_date_column_pos].left.get<UInt64>()); |
| 395 | DayNum max_date(minmax_idx.hyperrectangle[data.minmax_idx_date_column_pos].right.get<UInt64>()); |
| 396 | |
| 397 | const auto & date_lut = DateLUT::serverTimezoneInstance(); |
| 398 | |
| 399 | auto min_month = date_lut.toNumYYYYMM(min_date); |
| 400 | auto max_month = date_lut.toNumYYYYMM(max_date); |
| 401 | |
| 402 | if (min_month != max_month) |
| 403 | throw Exception("Logical error: part spans more than one month.", ErrorCodes::LOGICAL_ERROR); |
| 404 | |
| 405 | part_name = new_part_info.getPartNameV0(min_date, max_date); |
| 406 | } |
| 407 | else |
| 408 | part_name = new_part_info.getPartName(); |
| 409 | |
| 410 | /// If we need to calculate some columns to sort. |
| 411 | if (metadata_snapshot->hasSortingKey() || metadata_snapshot->hasSecondaryIndices()) |
| 412 | data.getSortingKeyAndSkipIndicesExpression(metadata_snapshot)->execute(block); |
| 413 |
no test coverage detected