2019-02-05 14:50:25 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeIndexReader.h>
|
|
|
|
|
2021-08-05 18:09:17 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace DB;
|
|
|
|
|
|
|
|
std::unique_ptr<MergeTreeReaderStream> makeIndexReader(
|
|
|
|
const std::string & extension,
|
|
|
|
MergeTreeIndexPtr index,
|
|
|
|
MergeTreeData::DataPartPtr part,
|
|
|
|
size_t marks_count,
|
|
|
|
const MarkRanges & all_mark_ranges,
|
|
|
|
MergeTreeReaderSettings settings)
|
|
|
|
{
|
|
|
|
return std::make_unique<MergeTreeReaderStream>(
|
|
|
|
part->volume->getDisk(),
|
|
|
|
part->getFullRelativePath() + index->getFileName(), extension, marks_count,
|
|
|
|
all_mark_ranges,
|
|
|
|
std::move(settings), nullptr, nullptr,
|
|
|
|
part->getFileSizeOrZero(index->getFileName() + extension),
|
|
|
|
&part->index_granularity_info,
|
|
|
|
ReadBufferFromFileBase::ProfileCallback{}, CLOCK_MONOTONIC_COARSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-02-05 14:50:25 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
MergeTreeIndexReader::MergeTreeIndexReader(
|
2020-06-25 19:31:54 +00:00
|
|
|
MergeTreeIndexPtr index_, MergeTreeData::DataPartPtr part_, size_t marks_count_, const MarkRanges & all_mark_ranges_,
|
|
|
|
MergeTreeReaderSettings settings)
|
2021-08-05 18:09:17 +00:00
|
|
|
: index(index_)
|
2019-02-05 14:50:25 +00:00
|
|
|
{
|
2021-08-05 18:09:17 +00:00
|
|
|
const std::string & path_prefix = part_->getFullRelativePath() + index->getFileName();
|
|
|
|
auto index_format = index->getDeserializedFormat(part_->volume->getDisk(), path_prefix);
|
|
|
|
|
|
|
|
stream = makeIndexReader(index_format.extension, index_, part_, marks_count_, all_mark_ranges_, std::move(settings));
|
|
|
|
version = index_format.version;
|
|
|
|
|
|
|
|
stream->seekToStart();
|
2019-02-05 14:50:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 18:09:17 +00:00
|
|
|
MergeTreeIndexReader::~MergeTreeIndexReader() = default;
|
|
|
|
|
2019-02-05 14:50:25 +00:00
|
|
|
void MergeTreeIndexReader::seek(size_t mark)
|
|
|
|
{
|
2021-08-05 18:09:17 +00:00
|
|
|
stream->seekToMark(mark);
|
2019-02-05 14:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeIndexGranulePtr MergeTreeIndexReader::read()
|
|
|
|
{
|
|
|
|
auto granule = index->createIndexGranule();
|
2021-08-05 18:09:17 +00:00
|
|
|
granule->deserializeBinary(*stream->data_buffer, version);
|
2019-02-05 14:50:25 +00:00
|
|
|
return granule;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|