2019-06-18 12:54:27 +00:00
|
|
|
#include <Storages/MergeTree/MergedColumnOnlyOutputStream.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2019-06-18 12:54:27 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-25 18:10:48 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NOT_IMPLEMENTED;
|
|
|
|
}
|
2019-06-18 12:54:27 +00:00
|
|
|
|
|
|
|
MergedColumnOnlyOutputStream::MergedColumnOnlyOutputStream(
|
2020-04-17 11:59:10 +00:00
|
|
|
const MergeTreeDataPartPtr & data_part,
|
2020-06-16 15:51:29 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
2020-04-17 11:59:10 +00:00
|
|
|
const Block & header_,
|
|
|
|
CompressionCodecPtr default_codec,
|
2019-11-07 11:11:38 +00:00
|
|
|
const std::vector<MergeTreeIndexPtr> & indices_to_recalc,
|
2019-12-09 21:21:17 +00:00
|
|
|
WrittenOffsetColumns * offset_columns_,
|
2019-11-08 14:36:10 +00:00
|
|
|
const MergeTreeIndexGranularity & index_granularity,
|
2020-04-17 11:59:10 +00:00
|
|
|
const MergeTreeIndexGranularityInfo * index_granularity_info)
|
2020-06-16 15:51:29 +00:00
|
|
|
: IMergedBlockOutputStream(data_part, metadata_snapshot_)
|
|
|
|
, header(header_)
|
2019-06-18 12:54:27 +00:00
|
|
|
{
|
2020-02-04 13:34:57 +00:00
|
|
|
const auto & global_settings = data_part->storage.global_context.getSettings();
|
2019-12-18 15:54:45 +00:00
|
|
|
MergeTreeWriterSettings writer_settings(
|
2020-02-04 13:34:57 +00:00
|
|
|
global_settings,
|
|
|
|
index_granularity_info ? index_granularity_info->is_adaptive : data_part->storage.canUseAdaptiveGranularity(),
|
|
|
|
global_settings.min_bytes_to_use_direct_io);
|
|
|
|
|
2020-04-17 11:59:10 +00:00
|
|
|
writer = data_part->getWriter(
|
|
|
|
header.getNamesAndTypesList(),
|
|
|
|
indices_to_recalc,
|
|
|
|
default_codec,
|
|
|
|
std::move(writer_settings),
|
|
|
|
index_granularity);
|
2019-11-08 14:36:10 +00:00
|
|
|
|
2019-12-19 14:05:26 +00:00
|
|
|
writer->setWrittenOffsetColumns(offset_columns_);
|
2019-11-08 14:36:10 +00:00
|
|
|
writer->initSkipIndices();
|
2019-09-02 16:31:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MergedColumnOnlyOutputStream::write(const Block & block)
|
|
|
|
{
|
2020-01-16 16:15:01 +00:00
|
|
|
std::unordered_set<String> skip_indexes_column_names_set;
|
2019-12-19 14:05:26 +00:00
|
|
|
for (const auto & index : writer->getSkipIndices())
|
2020-05-28 12:37:05 +00:00
|
|
|
std::copy(index->index.column_names.cbegin(), index->index.column_names.cend(),
|
2019-06-24 13:44:44 +00:00
|
|
|
std::inserter(skip_indexes_column_names_set, skip_indexes_column_names_set.end()));
|
|
|
|
Names skip_indexes_column_names(skip_indexes_column_names_set.begin(), skip_indexes_column_names_set.end());
|
|
|
|
|
2019-12-09 21:21:17 +00:00
|
|
|
Block skip_indexes_block = getBlockAndPermute(block, skip_indexes_column_names, nullptr);
|
2019-06-24 13:44:44 +00:00
|
|
|
|
|
|
|
size_t rows = block.rows();
|
2019-06-24 15:07:01 +00:00
|
|
|
if (!rows)
|
|
|
|
return;
|
2019-06-24 13:44:44 +00:00
|
|
|
|
2019-12-09 21:21:17 +00:00
|
|
|
writer->write(block);
|
|
|
|
writer->calculateAndSerializeSkipIndices(skip_indexes_block, rows);
|
|
|
|
writer->next();
|
2019-06-18 12:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MergedColumnOnlyOutputStream::writeSuffix()
|
|
|
|
{
|
|
|
|
throw Exception("Method writeSuffix is not supported by MergedColumnOnlyOutputStream", ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2020-03-13 15:09:55 +00:00
|
|
|
MergeTreeData::DataPart::Checksums
|
|
|
|
MergedColumnOnlyOutputStream::writeSuffixAndGetChecksums(MergeTreeData::MutableDataPartPtr & new_part, MergeTreeData::DataPart::Checksums & all_checksums)
|
2019-06-18 12:54:27 +00:00
|
|
|
{
|
|
|
|
/// Finish columns serialization.
|
|
|
|
MergeTreeData::DataPart::Checksums checksums;
|
2020-04-17 11:59:10 +00:00
|
|
|
writer->finishDataSerialization(checksums);
|
2019-12-09 21:21:17 +00:00
|
|
|
writer->finishSkipIndicesSerialization(checksums);
|
2019-06-24 13:44:44 +00:00
|
|
|
|
2020-03-13 15:09:55 +00:00
|
|
|
auto columns = new_part->getColumns();
|
|
|
|
|
|
|
|
auto removed_files = removeEmptyColumnsFromPart(new_part, columns, checksums);
|
|
|
|
for (const String & removed_file : removed_files)
|
|
|
|
if (all_checksums.files.count(removed_file))
|
|
|
|
all_checksums.files.erase(removed_file);
|
|
|
|
|
|
|
|
new_part->setColumns(columns);
|
2019-06-18 12:54:27 +00:00
|
|
|
return checksums;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|