aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/clickhouse/client/block.h
blob: d85c6ffbf6ab709fa1bd20df863a34fb4e342953 (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
#pragma once

#include "columns/column.h"

namespace NClickHouse {
    struct TBlockInfo {
        ui8 IsOverflows = 0;
        i32 BucketNum = -1;
    };

    class TBlock {
    public:
        /// Allow to iterate over block's columns.
        class TIterator {
        public:
            TIterator(const TBlock& block);

            /// Name of column.
            const TString& Name() const;

            /// Type of column.
            TTypeRef Type() const;

            /// Reference to column object.
            TColumnRef Column() const;

            /// Move to next column.
            void Next();

            /// Is the iterator still valid.
            bool IsValid() const;

        private:
            TIterator() = delete;

            const TBlock& Block_;
            size_t Idx_;
        };

    public:
        TBlock();
        TBlock(size_t cols, size_t rows);
        ~TBlock();

        /// Append named column to the block.
        void AppendColumn(const TString& name, const TColumnRef& col);

        /// Count of columns in the block.
        size_t GetColumnCount() const;

        const TBlockInfo& Info() const;

        /// Count of rows in the block.
        size_t GetRowCount() const;

        /// Append block to the current (vertical scale)
        void AppendBlock(const TBlock& block);

        /// Reference to column by index in the block.
        TColumnRef operator[](size_t idx) const;

    private:
        struct TColumnItem {
            TString Name;
            TColumnRef Column;
        };

        TBlockInfo Info_;
        TVector<TColumnItem> Columns_;
        /// Count of rows in the block.
        size_t Rows_;
    };

}