MCPcopy Create free account
hub / github.com/ByConity/ByConity / writeProjectionPartImpl

Method writeProjectionPartImpl

src/Storages/MergeTree/MergeTreeDataWriter.cpp:639–715  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637}
638
639MergeTreeMetaBase::MutableDataPartPtr MergeTreeDataWriter::writeProjectionPartImpl(
640 MergeTreeMetaBase & data,
641 Poco::Logger * log,
642 Block block,
643 const StorageMetadataPtr & metadata_snapshot,
644 MergeTreeMetaBase::MutableDataPartPtr && new_data_part)
645{
646 NamesAndTypesList columns = metadata_snapshot->getColumns().getAllPhysical().filter(block.getNames());
647 MergeTreePartition partition{};
648 IMergeTreeDataPart::MinMaxIndex minmax_idx{};
649 new_data_part->setColumns(columns);
650 new_data_part->partition = std::move(partition);
651 new_data_part->minmax_idx = std::move(minmax_idx);
652
653 if (new_data_part->isStoredOnDisk())
654 {
655 /// The name could be non-unique in case of stale files from previous runs.
656 String full_path = new_data_part->getFullRelativePath();
657
658 if (new_data_part->volume->getDisk()->exists(full_path))
659 {
660 LOG_WARNING(log, "Removing old temporary directory {}", fullPath(new_data_part->volume->getDisk(), full_path));
661 new_data_part->volume->getDisk()->removeRecursive(full_path);
662 }
663
664 new_data_part->volume->getDisk()->createDirectories(full_path);
665 }
666
667 /// If we need to calculate some columns to sort.
668 if (metadata_snapshot->hasSortingKey() || metadata_snapshot->hasSecondaryIndices())
669 data.getSortingKeyAndSkipIndicesExpression(metadata_snapshot)->execute(block);
670
671 Names sort_columns = metadata_snapshot->getSortingKeyColumns();
672 SortDescription sort_description;
673 size_t sort_columns_size = sort_columns.size();
674 sort_description.reserve(sort_columns_size);
675
676 for (size_t i = 0; i < sort_columns_size; ++i)
677 sort_description.emplace_back(block.getPositionByName(sort_columns[i]), 1, 1);
678
679 ProfileEvents::increment(ProfileEvents::MergeTreeDataProjectionWriterBlocks);
680
681 /// Sort
682 IColumn::Permutation * perm_ptr = nullptr;
683 IColumn::Permutation perm;
684 if (!sort_description.empty())
685 {
686 if (!isAlreadySorted(block, sort_description))
687 {
688 stableGetPermutation(block, sort_description, perm);
689 perm_ptr = &perm;
690 }
691 else
692 ProfileEvents::increment(ProfileEvents::MergeTreeDataProjectionWriterBlocksAlreadySorted);
693 }
694
695 /// This effectively chooses minimal compression method:
696 /// either default lz4 or compression method with zero thresholds on absolute and relative part size.

Callers

nothing calls this directly

Calls 15

fullPathFunction · 0.85
isAlreadySortedFunction · 0.85
stableGetPermutationFunction · 0.85
getAllPhysicalMethod · 0.80
hasSortingKeyMethod · 0.80
hasSecondaryIndicesMethod · 0.80
getSortingKeyColumnsMethod · 0.80
writeWithPermutationMethod · 0.80
getBytesOnDiskMethod · 0.80

Tested by

no test coverage detected