aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Formats/IndexForNativeFormat.h
blob: 646f539ebd00568937d18391decbfde12598b817 (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
#pragma once

#include <Core/Names.h>
#include <Formats/MarkInCompressedFile.h>

namespace DB
{

/** The Native format can contain a separately located index,
  *  which allows you to understand where what column is located,
  *  and skip unnecessary columns.
  */

/** The position of one piece of a single column. */
struct IndexOfOneColumnForNativeFormat
{
    String name;
    String type;
    MarkInCompressedFile location;
};

/** The index for the data block. */
struct IndexOfBlockForNativeFormat
{
    using Columns = std::vector<IndexOfOneColumnForNativeFormat>;

    size_t num_columns;
    size_t num_rows;
    Columns columns;

    /// Reads the index for the data block.
    void read(ReadBuffer & istr);

    /// Writes the index for the data block.
    void write(WriteBuffer & ostr) const;

    /// Returns the index only for the required columns.
    IndexOfBlockForNativeFormat extractIndexForColumns(const NameSet & required_columns) const;
};

/** The whole index. */
struct IndexForNativeFormat
{
    using Blocks = std::vector<IndexOfBlockForNativeFormat>;
    Blocks blocks;

    bool empty() const { return blocks.empty(); }
    void clear() { blocks.clear(); }

    /// Reads the index.
    void read(ReadBuffer & istr);

    /// Writes the index.
    void write(WriteBuffer & ostr) const;

    /// Returns the index only for the required columns.
    IndexForNativeFormat extractIndexForColumns(const NameSet & required_columns) const;
};

}