2019-10-21 00:28:29 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeDataPartWriterWide.h>
|
2020-05-20 20:16:32 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2020-09-21 07:17:58 +00:00
|
|
|
#include <Compression/CompressionFactory.h>
|
2019-10-21 00:28:29 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-25 18:10:48 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
2019-10-21 00:28:29 +00:00
|
|
|
|
2019-10-21 15:33:59 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
constexpr auto DATA_FILE_EXTENSION = ".bin";
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeDataPartWriterWide::MergeTreeDataPartWriterWide(
|
2020-05-10 13:33:27 +00:00
|
|
|
const MergeTreeData::DataPartPtr & data_part_,
|
2019-10-21 15:33:59 +00:00
|
|
|
const NamesAndTypesList & columns_list_,
|
2020-06-17 12:39:20 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
2019-12-18 16:41:11 +00:00
|
|
|
const std::vector<MergeTreeIndexPtr> & indices_to_recalc_,
|
2019-10-21 15:33:59 +00:00
|
|
|
const String & marks_file_extension_,
|
|
|
|
const CompressionCodecPtr & default_codec_,
|
2019-12-18 15:54:45 +00:00
|
|
|
const MergeTreeWriterSettings & settings_,
|
2019-11-07 11:11:38 +00:00
|
|
|
const MergeTreeIndexGranularity & index_granularity_)
|
2020-06-26 11:27:19 +00:00
|
|
|
: MergeTreeDataPartWriterOnDisk(data_part_, columns_list_, metadata_snapshot_,
|
2020-05-10 13:33:27 +00:00
|
|
|
indices_to_recalc_, marks_file_extension_,
|
|
|
|
default_codec_, settings_, index_granularity_)
|
2019-10-21 15:33:59 +00:00
|
|
|
{
|
2020-06-17 12:39:20 +00:00
|
|
|
const auto & columns = metadata_snapshot->getColumns();
|
2019-10-21 15:33:59 +00:00
|
|
|
for (const auto & it : columns_list)
|
2020-09-21 11:24:10 +00:00
|
|
|
addStreams(it.name, *it.type, columns.getCodecDescOrDefault(it.name, default_codec), settings.estimated_size);
|
2019-10-21 15:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeDataPartWriterWide::addStreams(
|
|
|
|
const String & name,
|
|
|
|
const IDataType & type,
|
2020-09-21 07:17:58 +00:00
|
|
|
const ASTPtr & effective_codec_desc,
|
2019-12-09 21:21:17 +00:00
|
|
|
size_t estimated_size)
|
2019-10-21 15:33:59 +00:00
|
|
|
{
|
2020-09-21 07:17:58 +00:00
|
|
|
IDataType::StreamCallback callback = [&] (const IDataType::SubstreamPath & substream_path, const IDataType & substream_type)
|
2019-10-21 15:33:59 +00:00
|
|
|
{
|
|
|
|
String stream_name = IDataType::getFileNameForStream(name, substream_path);
|
|
|
|
/// Shared offsets for Nested type.
|
|
|
|
if (column_streams.count(stream_name))
|
|
|
|
return;
|
|
|
|
|
2020-09-21 14:22:13 +00:00
|
|
|
CompressionCodecPtr compression_codec;
|
2020-09-29 22:23:42 +00:00
|
|
|
/// If we can use special codec then just get it
|
2020-09-21 14:22:13 +00:00
|
|
|
if (IDataType::isSpecialCompressionAllowed(substream_path))
|
|
|
|
compression_codec = CompressionCodecFactory::instance().get(effective_codec_desc, &substream_type, default_codec);
|
2020-09-29 22:23:42 +00:00
|
|
|
else /// otherwise return only generic codecs and don't use info about the data_type
|
2020-09-21 14:47:10 +00:00
|
|
|
compression_codec = CompressionCodecFactory::instance().get(effective_codec_desc, nullptr, default_codec, true);
|
2020-09-21 07:17:58 +00:00
|
|
|
|
2020-02-19 14:07:36 +00:00
|
|
|
column_streams[stream_name] = std::make_unique<Stream>(
|
2019-10-21 15:33:59 +00:00
|
|
|
stream_name,
|
2020-05-10 13:33:27 +00:00
|
|
|
data_part->volume->getDisk(),
|
2019-10-21 15:33:59 +00:00
|
|
|
part_path + stream_name, DATA_FILE_EXTENSION,
|
|
|
|
part_path + stream_name, marks_file_extension,
|
2020-09-21 11:24:10 +00:00
|
|
|
compression_codec,
|
2019-10-21 15:33:59 +00:00
|
|
|
settings.max_compress_block_size,
|
|
|
|
estimated_size,
|
|
|
|
settings.aio_threshold);
|
|
|
|
};
|
|
|
|
|
|
|
|
IDataType::SubstreamPath stream_path;
|
|
|
|
type.enumerateStreams(callback, stream_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IDataType::OutputStreamGetter MergeTreeDataPartWriterWide::createStreamGetter(
|
2020-12-09 18:10:09 +00:00
|
|
|
const String & name, WrittenOffsetColumns & offset_columns) const
|
2019-10-21 15:33:59 +00:00
|
|
|
{
|
2019-12-09 21:21:17 +00:00
|
|
|
return [&, this] (const IDataType::SubstreamPath & substream_path) -> WriteBuffer *
|
2019-10-21 15:33:59 +00:00
|
|
|
{
|
|
|
|
bool is_offsets = !substream_path.empty() && substream_path.back().type == IDataType::Substream::ArraySizes;
|
|
|
|
|
|
|
|
String stream_name = IDataType::getFileNameForStream(name, substream_path);
|
|
|
|
|
|
|
|
/// Don't write offsets more than one time for Nested type.
|
|
|
|
if (is_offsets && offset_columns.count(stream_name))
|
|
|
|
return nullptr;
|
|
|
|
|
2020-12-09 18:10:09 +00:00
|
|
|
return &column_streams.at(stream_name)->compressed;
|
2019-10-21 15:33:59 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-10 08:57:52 +00:00
|
|
|
void MergeTreeDataPartWriterWide::write(const Block & block, const IColumn::Permutation * permutation)
|
2019-10-21 00:28:29 +00:00
|
|
|
{
|
2019-11-07 11:11:38 +00:00
|
|
|
/// Fill index granularity for this block
|
|
|
|
/// if it's unknown (in case of insert data or horizontal merge,
|
|
|
|
/// but not in case of vertical merge)
|
|
|
|
if (compute_granularity)
|
2020-04-26 21:19:25 +00:00
|
|
|
{
|
|
|
|
size_t index_granularity_for_block = computeIndexGranularity(block);
|
|
|
|
fillIndexGranularity(index_granularity_for_block, block.rows());
|
|
|
|
}
|
2019-11-27 19:57:07 +00:00
|
|
|
|
2019-12-09 21:21:17 +00:00
|
|
|
auto offset_columns = written_offset_columns ? *written_offset_columns : WrittenOffsetColumns{};
|
2020-12-10 08:57:52 +00:00
|
|
|
Block primary_key_block;
|
|
|
|
if (settings.rewrite_primary_key)
|
|
|
|
primary_key_block = getBlockAndPermute(block, metadata_snapshot->getPrimaryKeyColumns(), permutation);
|
|
|
|
|
2020-12-11 08:41:02 +00:00
|
|
|
Block skip_indexes_block = getBlockAndPermute(block, getSkipIndicesColumns(), permutation);
|
2019-10-21 00:28:29 +00:00
|
|
|
|
|
|
|
auto it = columns_list.begin();
|
|
|
|
for (size_t i = 0; i < columns_list.size(); ++i, ++it)
|
|
|
|
{
|
|
|
|
const ColumnWithTypeAndName & column = block.getByName(it->name);
|
|
|
|
|
|
|
|
if (permutation)
|
|
|
|
{
|
|
|
|
if (primary_key_block.has(it->name))
|
|
|
|
{
|
|
|
|
const auto & primary_column = *primary_key_block.getByName(it->name).column;
|
2019-12-09 21:21:17 +00:00
|
|
|
writeColumn(column.name, *column.type, primary_column, offset_columns);
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
else if (skip_indexes_block.has(it->name))
|
|
|
|
{
|
|
|
|
const auto & index_column = *skip_indexes_block.getByName(it->name).column;
|
2019-12-09 21:21:17 +00:00
|
|
|
writeColumn(column.name, *column.type, index_column, offset_columns);
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/// We rearrange the columns that are not included in the primary key here; Then the result is released - to save RAM.
|
|
|
|
ColumnPtr permuted_column = column.column->permute(*permutation, 0);
|
2019-12-09 21:21:17 +00:00
|
|
|
writeColumn(column.name, *column.type, *permuted_column, offset_columns);
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-09 21:21:17 +00:00
|
|
|
writeColumn(column.name, *column.type, *column.column, offset_columns);
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-10 08:57:52 +00:00
|
|
|
|
|
|
|
if (settings.rewrite_primary_key)
|
|
|
|
calculateAndSerializePrimaryIndex(primary_key_block);
|
|
|
|
|
|
|
|
calculateAndSerializeSkipIndices(skip_indexes_block);
|
|
|
|
next();
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeDataPartWriterWide::writeSingleMark(
|
|
|
|
const String & name,
|
|
|
|
const IDataType & type,
|
|
|
|
WrittenOffsetColumns & offset_columns,
|
|
|
|
size_t number_of_rows,
|
|
|
|
DB::IDataType::SubstreamPath & path)
|
|
|
|
{
|
2020-12-10 16:29:10 +00:00
|
|
|
StreamsWithMarks marks = getCurrentMarksForColumn(name, type, offset_columns, path);
|
|
|
|
for (const auto & mark : marks)
|
|
|
|
flushMarkToFile(mark, number_of_rows);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeDataPartWriterWide::flushMarkToFile(const StreamNameAndMark & stream_with_mark, size_t rows_in_mark)
|
|
|
|
{
|
|
|
|
Stream & stream = *column_streams[stream_with_mark.stream_name];
|
|
|
|
writeIntBinary(stream_with_mark.mark.offset_in_compressed_file, stream.marks);
|
|
|
|
writeIntBinary(stream_with_mark.mark.offset_in_decompressed_block, stream.marks);
|
|
|
|
if (settings.can_use_adaptive_granularity)
|
|
|
|
writeIntBinary(rows_in_mark, stream.marks);
|
|
|
|
}
|
|
|
|
|
|
|
|
StreamsWithMarks MergeTreeDataPartWriterWide::getCurrentMarksForColumn(
|
|
|
|
const String & name,
|
|
|
|
const IDataType & type,
|
|
|
|
WrittenOffsetColumns & offset_columns,
|
|
|
|
DB::IDataType::SubstreamPath & path)
|
|
|
|
{
|
|
|
|
StreamsWithMarks result;
|
2020-09-18 11:37:58 +00:00
|
|
|
type.enumerateStreams([&] (const IDataType::SubstreamPath & substream_path, const IDataType & /* substream_type */)
|
2020-12-10 16:29:10 +00:00
|
|
|
{
|
|
|
|
bool is_offsets = !substream_path.empty() && substream_path.back().type == IDataType::Substream::ArraySizes;
|
|
|
|
|
|
|
|
String stream_name = IDataType::getFileNameForStream(name, substream_path);
|
|
|
|
|
|
|
|
/// Don't write offsets more than one time for Nested type.
|
|
|
|
if (is_offsets && offset_columns.count(stream_name))
|
|
|
|
return;
|
2019-10-21 00:28:29 +00:00
|
|
|
|
2020-12-10 16:29:10 +00:00
|
|
|
Stream & stream = *column_streams[stream_name];
|
2019-10-21 00:28:29 +00:00
|
|
|
|
2020-12-10 16:29:10 +00:00
|
|
|
/// There could already be enough data to compress into the new block.
|
|
|
|
if (stream.compressed.offset() >= settings.min_compress_block_size)
|
|
|
|
stream.compressed.next();
|
2019-10-21 00:28:29 +00:00
|
|
|
|
2020-12-10 16:29:10 +00:00
|
|
|
StreamNameAndMark stream_with_mark;
|
|
|
|
stream_with_mark.stream_name = stream_name;
|
|
|
|
stream_with_mark.mark.offset_in_compressed_file = stream.plain_hashing.count();
|
|
|
|
stream_with_mark.mark.offset_in_decompressed_block = stream.compressed.offset();
|
2019-10-21 00:28:29 +00:00
|
|
|
|
2020-12-10 16:29:10 +00:00
|
|
|
result.push_back(stream_with_mark);
|
|
|
|
}, path);
|
2019-10-21 00:28:29 +00:00
|
|
|
|
2020-12-10 16:29:10 +00:00
|
|
|
return result;
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t MergeTreeDataPartWriterWide::writeSingleGranule(
|
|
|
|
const String & name,
|
|
|
|
const IDataType & type,
|
|
|
|
const IColumn & column,
|
|
|
|
WrittenOffsetColumns & offset_columns,
|
|
|
|
IDataType::SerializeBinaryBulkStatePtr & serialization_state,
|
|
|
|
IDataType::SerializeBinaryBulkSettings & serialize_settings,
|
|
|
|
size_t from_row,
|
|
|
|
size_t number_of_rows,
|
|
|
|
bool write_marks)
|
|
|
|
{
|
|
|
|
if (write_marks)
|
2019-12-09 21:21:17 +00:00
|
|
|
writeSingleMark(name, type, offset_columns, number_of_rows, serialize_settings.path);
|
2019-10-21 00:28:29 +00:00
|
|
|
|
|
|
|
type.serializeBinaryBulkWithMultipleStreams(column, from_row, number_of_rows, serialize_settings, serialization_state);
|
|
|
|
|
|
|
|
/// So that instead of the marks pointing to the end of the compressed block, there were marks pointing to the beginning of the next one.
|
2020-09-18 11:37:58 +00:00
|
|
|
type.enumerateStreams([&] (const IDataType::SubstreamPath & substream_path, const IDataType & /* substream_type */)
|
2019-10-21 00:28:29 +00:00
|
|
|
{
|
|
|
|
bool is_offsets = !substream_path.empty() && substream_path.back().type == IDataType::Substream::ArraySizes;
|
|
|
|
|
|
|
|
String stream_name = IDataType::getFileNameForStream(name, substream_path);
|
|
|
|
|
|
|
|
/// Don't write offsets more than one time for Nested type.
|
|
|
|
if (is_offsets && offset_columns.count(stream_name))
|
|
|
|
return;
|
|
|
|
|
|
|
|
column_streams[stream_name]->compressed.nextIfAtEnd();
|
|
|
|
}, serialize_settings.path);
|
|
|
|
|
|
|
|
return from_row + number_of_rows;
|
|
|
|
}
|
|
|
|
|
2019-12-18 15:54:45 +00:00
|
|
|
/// Column must not be empty. (column.size() !== 0)
|
|
|
|
void MergeTreeDataPartWriterWide::writeColumn(
|
2019-10-21 00:28:29 +00:00
|
|
|
const String & name,
|
|
|
|
const IDataType & type,
|
|
|
|
const IColumn & column,
|
2019-12-09 21:21:17 +00:00
|
|
|
WrittenOffsetColumns & offset_columns)
|
2019-10-21 00:28:29 +00:00
|
|
|
{
|
2019-11-07 11:11:38 +00:00
|
|
|
auto [it, inserted] = serialization_states.emplace(name, nullptr);
|
|
|
|
if (inserted)
|
|
|
|
{
|
|
|
|
IDataType::SerializeBinaryBulkSettings serialize_settings;
|
2019-12-09 21:21:17 +00:00
|
|
|
serialize_settings.getter = createStreamGetter(name, offset_columns);
|
2019-11-07 11:11:38 +00:00
|
|
|
type.serializeBinaryBulkStatePrefix(serialize_settings, it->second);
|
|
|
|
}
|
|
|
|
|
2019-12-12 18:55:19 +00:00
|
|
|
const auto & global_settings = storage.global_context.getSettingsRef();
|
2019-10-21 00:28:29 +00:00
|
|
|
IDataType::SerializeBinaryBulkSettings serialize_settings;
|
2019-12-09 21:21:17 +00:00
|
|
|
serialize_settings.getter = createStreamGetter(name, offset_columns);
|
2019-12-12 18:55:19 +00:00
|
|
|
serialize_settings.low_cardinality_max_dictionary_size = global_settings.low_cardinality_max_dictionary_size;
|
|
|
|
serialize_settings.low_cardinality_use_single_dictionary_for_part = global_settings.low_cardinality_use_single_dictionary_for_part != 0;
|
2019-10-21 00:28:29 +00:00
|
|
|
|
|
|
|
size_t total_rows = column.size();
|
|
|
|
size_t current_row = 0;
|
2020-04-29 21:57:58 +00:00
|
|
|
size_t current_column_mark = getCurrentMark();
|
|
|
|
size_t current_index_offset = getIndexOffset();
|
2019-10-21 00:28:29 +00:00
|
|
|
while (current_row < total_rows)
|
|
|
|
{
|
|
|
|
size_t rows_to_write;
|
2019-11-27 11:35:27 +00:00
|
|
|
bool write_marks = true;
|
2019-10-21 00:28:29 +00:00
|
|
|
|
|
|
|
/// If there is `index_offset`, then the first mark goes not immediately, but after this number of rows.
|
2020-04-29 21:57:58 +00:00
|
|
|
if (current_row == 0 && current_index_offset != 0)
|
2019-10-21 00:28:29 +00:00
|
|
|
{
|
|
|
|
write_marks = false;
|
2020-04-29 21:57:58 +00:00
|
|
|
rows_to_write = current_index_offset;
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (index_granularity.getMarksCount() <= current_column_mark)
|
|
|
|
throw Exception(
|
|
|
|
"Incorrect size of index granularity expect mark " + toString(current_column_mark) + " totally have marks " + toString(index_granularity.getMarksCount()),
|
|
|
|
ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
|
|
|
rows_to_write = index_granularity.getMarkRows(current_column_mark);
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:11:38 +00:00
|
|
|
if (rows_to_write != 0)
|
|
|
|
data_written = true;
|
|
|
|
|
2019-10-21 00:28:29 +00:00
|
|
|
current_row = writeSingleGranule(
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
column,
|
|
|
|
offset_columns,
|
2019-11-07 11:11:38 +00:00
|
|
|
it->second,
|
2019-10-21 00:28:29 +00:00
|
|
|
serialize_settings,
|
|
|
|
current_row,
|
|
|
|
rows_to_write,
|
|
|
|
write_marks
|
|
|
|
);
|
|
|
|
|
|
|
|
if (write_marks)
|
|
|
|
current_column_mark++;
|
|
|
|
}
|
|
|
|
|
2020-09-18 11:37:58 +00:00
|
|
|
type.enumerateStreams([&] (const IDataType::SubstreamPath & substream_path, const IDataType & /* substream_type */)
|
2019-10-21 00:28:29 +00:00
|
|
|
{
|
|
|
|
bool is_offsets = !substream_path.empty() && substream_path.back().type == IDataType::Substream::ArraySizes;
|
|
|
|
if (is_offsets)
|
|
|
|
{
|
|
|
|
String stream_name = IDataType::getFileNameForStream(name, substream_path);
|
|
|
|
offset_columns.insert(stream_name);
|
|
|
|
}
|
|
|
|
}, serialize_settings.path);
|
|
|
|
|
2019-11-05 11:53:22 +00:00
|
|
|
next_mark = current_column_mark;
|
|
|
|
next_index_offset = current_row - total_rows;
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 16:55:45 +00:00
|
|
|
void MergeTreeDataPartWriterWide::finishDataSerialization(IMergeTreeDataPart::Checksums & checksums, bool sync)
|
2019-10-21 17:23:06 +00:00
|
|
|
{
|
2019-12-12 18:55:19 +00:00
|
|
|
const auto & global_settings = storage.global_context.getSettingsRef();
|
2019-10-21 17:23:06 +00:00
|
|
|
IDataType::SerializeBinaryBulkSettings serialize_settings;
|
2019-12-12 18:55:19 +00:00
|
|
|
serialize_settings.low_cardinality_max_dictionary_size = global_settings.low_cardinality_max_dictionary_size;
|
|
|
|
serialize_settings.low_cardinality_use_single_dictionary_for_part = global_settings.low_cardinality_use_single_dictionary_for_part != 0;
|
2019-10-21 17:23:06 +00:00
|
|
|
WrittenOffsetColumns offset_columns;
|
|
|
|
|
2019-11-18 15:18:50 +00:00
|
|
|
bool write_final_mark = (with_final_mark && data_written);
|
|
|
|
|
2019-10-21 17:23:06 +00:00
|
|
|
{
|
|
|
|
auto it = columns_list.begin();
|
|
|
|
for (size_t i = 0; i < columns_list.size(); ++i, ++it)
|
|
|
|
{
|
|
|
|
if (!serialization_states.empty())
|
|
|
|
{
|
2019-12-09 21:21:17 +00:00
|
|
|
serialize_settings.getter = createStreamGetter(it->name, written_offset_columns ? *written_offset_columns : offset_columns);
|
2019-11-07 11:11:38 +00:00
|
|
|
it->type->serializeBinaryBulkStateSuffix(serialize_settings, serialization_states[it->name]);
|
2019-10-21 17:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (write_final_mark)
|
2019-11-08 14:36:10 +00:00
|
|
|
{
|
2019-12-09 21:21:17 +00:00
|
|
|
writeFinalMark(it->name, it->type, offset_columns, serialize_settings.path);
|
2019-11-08 14:36:10 +00:00
|
|
|
}
|
2019-10-21 17:23:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 01:59:08 +00:00
|
|
|
for (auto & stream : column_streams)
|
2019-10-21 17:23:06 +00:00
|
|
|
{
|
2020-03-09 01:59:08 +00:00
|
|
|
stream.second->finalize();
|
|
|
|
stream.second->addToChecksums(checksums);
|
2020-06-25 16:55:45 +00:00
|
|
|
if (sync)
|
|
|
|
stream.second->sync();
|
2019-10-21 17:23:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
column_streams.clear();
|
2019-10-22 17:42:59 +00:00
|
|
|
serialization_states.clear();
|
2019-10-21 17:23:06 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 08:57:52 +00:00
|
|
|
void MergeTreeDataPartWriterWide::finish(IMergeTreeDataPart::Checksums & checksums, bool sync)
|
|
|
|
{
|
|
|
|
finishDataSerialization(checksums, sync);
|
|
|
|
if (settings.rewrite_primary_key)
|
|
|
|
finishPrimaryIndexSerialization(checksums, sync);
|
|
|
|
|
|
|
|
finishSkipIndicesSerialization(checksums, sync);
|
|
|
|
}
|
|
|
|
|
2019-10-21 17:23:06 +00:00
|
|
|
void MergeTreeDataPartWriterWide::writeFinalMark(
|
|
|
|
const std::string & column_name,
|
|
|
|
const DataTypePtr column_type,
|
|
|
|
WrittenOffsetColumns & offset_columns,
|
|
|
|
DB::IDataType::SubstreamPath & path)
|
|
|
|
{
|
2019-12-09 21:21:17 +00:00
|
|
|
writeSingleMark(column_name, *column_type, offset_columns, 0, path);
|
2019-10-21 17:23:06 +00:00
|
|
|
/// Memoize information about offsets
|
2020-09-18 11:37:58 +00:00
|
|
|
column_type->enumerateStreams([&] (const IDataType::SubstreamPath & substream_path, const IDataType & /* substream_type */)
|
2019-10-21 17:23:06 +00:00
|
|
|
{
|
|
|
|
bool is_offsets = !substream_path.empty() && substream_path.back().type == IDataType::Substream::ArraySizes;
|
|
|
|
if (is_offsets)
|
|
|
|
{
|
|
|
|
String stream_name = IDataType::getFileNameForStream(column_name, substream_path);
|
|
|
|
offset_columns.insert(stream_name);
|
|
|
|
}
|
|
|
|
}, path);
|
|
|
|
}
|
|
|
|
|
2020-12-09 18:10:09 +00:00
|
|
|
static void fillIndexGranularityImpl(
|
|
|
|
MergeTreeIndexGranularity & index_granularity,
|
|
|
|
size_t index_offset,
|
|
|
|
size_t index_granularity_for_block,
|
|
|
|
size_t rows_in_block)
|
|
|
|
{
|
|
|
|
for (size_t current_row = index_offset; current_row < rows_in_block; current_row += index_granularity_for_block)
|
|
|
|
index_granularity.appendMark(index_granularity_for_block);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeDataPartWriterWide::fillIndexGranularity(size_t index_granularity_for_block, size_t rows_in_block)
|
|
|
|
{
|
|
|
|
fillIndexGranularityImpl(
|
|
|
|
index_granularity,
|
|
|
|
getIndexOffset(),
|
|
|
|
index_granularity_for_block,
|
|
|
|
rows_in_block);
|
|
|
|
}
|
|
|
|
|
2019-10-21 00:28:29 +00:00
|
|
|
}
|