aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Storages/MergeTree/MergeTreeReaderStream.h
blob: baf8ec713f9926df5e12e8232eaacfa95b54d3fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <tuple>
#include <Storages/MarkCache.h>
#include <Storages/MergeTree/MarkRange.h>
#include <Storages/MergeTree/MergeTreeData.h>
#include <Storages/MergeTree/MergeTreeRangeReader.h>
#include <Storages/MergeTree/MergeTreeIndexGranularityInfo.h>
#include <Compression/CachedCompressedReadBuffer.h>
#include <Compression/CompressedReadBufferFromFile.h>
#include <Storages/MergeTree/MergeTreeIOSettings.h>
#include <Storages/MergeTree/MergeTreeMarksLoader.h>
#include <Storages/MergeTree/IMergeTreeDataPartInfoForReader.h>


namespace DB
{

/// Class for reading a single column (or index).
class MergeTreeReaderStream
{
public:
    MergeTreeReaderStream(
        MergeTreeDataPartInfoForReaderPtr data_part_reader_,
        const String & path_prefix_,
        const String & data_file_extension_,
        size_t marks_count_,
        const MarkRanges & all_mark_ranges,
        const MergeTreeReaderSettings & settings_,
        MarkCache * mark_cache,
        UncompressedCache * uncompressed_cache,
        size_t file_size_,
        const MergeTreeIndexGranularityInfo * index_granularity_info_,
        const ReadBufferFromFileBase::ProfileCallback & profile_callback,
        clockid_t clock_type,
        bool is_low_cardinality_dictionary_,
        ThreadPool * load_marks_cache_threadpool_);

    void seekToMark(size_t index);

    void seekToStart();

    /**
     * Does buffer need to know something about mark ranges bounds it is going to read?
     * (In case of MergeTree* tables). Mostly needed for reading from remote fs.
     */
    void adjustRightMark(size_t right_mark);

    ReadBuffer * getDataBuffer();
    CompressedReadBufferBase * getCompressedDataBuffer();

private:
    void init();
    size_t getRightOffset(size_t right_mark);

    const MergeTreeReaderSettings settings;
    const ReadBufferFromFileBase::ProfileCallback profile_callback;
    clockid_t clock_type;
    const MarkRanges all_mark_ranges;
    size_t file_size;
    UncompressedCache * uncompressed_cache;

    DataPartStoragePtr data_part_storage;
    std::string path_prefix;
    std::string data_file_extension;

    bool is_low_cardinality_dictionary = false;

    size_t marks_count;


    ReadBuffer * data_buffer;
    CompressedReadBufferBase * compressed_data_buffer;
    MarkCache * mark_cache;
    bool save_marks_in_cache;
    bool initialized = false;

    std::optional<size_t> last_right_offset;

    const MergeTreeIndexGranularityInfo * index_granularity_info;

    std::unique_ptr<CachedCompressedReadBuffer> cached_buffer;
    std::unique_ptr<CompressedReadBufferFromFile> non_cached_buffer;

    MergeTreeMarksLoader marks_loader;
};

}