| 672 | } |
| 673 | |
| 674 | MergeTreeTemporaryPartPtr MergeTreeDataWriter::writeTempPartImpl( |
| 675 | BlockWithPartition & block_with_partition, |
| 676 | StorageMetadataPtr metadata_snapshot, |
| 677 | String partition_id, |
| 678 | SourcePartsSetForPatch source_parts_set, |
| 679 | ContextPtr context, |
| 680 | UInt64 block_number) |
| 681 | { |
| 682 | auto temp_part = std::make_unique<MergeTreeTemporaryPart>(); |
| 683 | Block & block = *block_with_partition.block; |
| 684 | MergeTreePartition & partition = block_with_partition.partition; |
| 685 | |
| 686 | const auto & data_settings = data.getSettings(); |
| 687 | const auto & global_settings = context->getSettingsRef(); |
| 688 | |
| 689 | auto columns = metadata_snapshot->getColumns().getAllPhysical().filter(block.getNames()); |
| 690 | |
| 691 | /// Do not write _block_number and _block_offset for 0-level parts: block number is not known on this step. |
| 692 | const auto minmax_columns = MergeTreeData::getMinMaxColumns(metadata_snapshot->getPartitionKey(), data_settings, MergeTreePartMinMaxIndexColumns::PARTITION_KEY_ONLY); |
| 693 | auto minmax_idx = std::make_shared<IMergeTreeDataPart::MinMaxIndex>(); |
| 694 | minmax_idx->update(block, minmax_columns); |
| 695 | |
| 696 | const bool optimize_on_insert = !isPatchPartitionId(partition_id) |
| 697 | && global_settings[Setting::optimize_on_insert] |
| 698 | && data.merging_params.mode != MergeTreeData::MergingParams::Ordinary; |
| 699 | UInt32 new_part_level = optimize_on_insert ? 1 : 0; |
| 700 | MergeTreePartInfo new_part_info(std::move(partition_id), block_number, block_number, new_part_level); |
| 701 | |
| 702 | if (!source_parts_set.empty()) |
| 703 | new_part_info.mutation = source_parts_set.getMaxDataVersion(); |
| 704 | |
| 705 | String part_name; |
| 706 | if (data.format_version < MERGE_TREE_DATA_MIN_FORMAT_VERSION_WITH_CUSTOM_PARTITIONING) |
| 707 | { |
| 708 | DayNum min_date(static_cast<DayNum::UnderlyingType>(minmax_idx->hyperrectangle[data.minmax_idx_date_column_pos].left.safeGet<UInt64>())); |
| 709 | DayNum max_date(static_cast<DayNum::UnderlyingType>(minmax_idx->hyperrectangle[data.minmax_idx_date_column_pos].right.safeGet<UInt64>())); |
| 710 | |
| 711 | const auto & date_lut = DateLUT::serverTimezoneInstance(); |
| 712 | |
| 713 | auto min_month = date_lut.toNumYYYYMM(min_date); |
| 714 | auto max_month = date_lut.toNumYYYYMM(max_date); |
| 715 | |
| 716 | if (min_month != max_month) |
| 717 | throw Exception(ErrorCodes::LOGICAL_ERROR, "Part spans more than one month."); |
| 718 | |
| 719 | part_name = new_part_info.getPartNameV0(min_date, max_date); |
| 720 | } |
| 721 | else |
| 722 | part_name = new_part_info.getPartNameV1(); |
| 723 | |
| 724 | std::string temp_prefix = "tmp_insert_"; |
| 725 | const auto & temp_postfix = data.getPostfixForTempInsertName(); |
| 726 | if (!temp_postfix.empty()) |
| 727 | temp_prefix += temp_postfix + "_"; |
| 728 | |
| 729 | std::string part_dir = temp_prefix + part_name; |
| 730 | temp_part->temporary_directory_lock = data.getTemporaryPartDirectoryHolder(part_dir); |
| 731 |
nothing calls this directly
no test coverage detected