aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/clickhouse/client/columns/tuple.cpp
blob: 3d0d00e772e5381da3b4ef9fbff2115d5015aee3 (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
#include "tuple.h"

namespace NClickHouse {
    static TVector<TTypeRef> CollectTypes(const TVector<TColumnRef>& columns) {
        TVector<TTypeRef> types;
        for (const auto& col : columns) {
            types.push_back(col->Type());
        }
        return types;
    }

    TColumnTuple::TColumnTuple(const TVector<TColumnRef>& columns)
        : TColumn(TType::CreateTuple(CollectTypes(columns)))
        , Columns_(columns)
    {
    }

    TIntrusivePtr<TColumnTuple> TColumnTuple::Create(const TVector<TColumnRef>& columns) {
        return new TColumnTuple(columns);
    }

    size_t TColumnTuple::Size() const {
        return Columns_.empty() ? 0 : Columns_[0]->Size();
    }

    bool TColumnTuple::Load(TCodedInputStream* input, size_t rows) {
        for (auto ci = Columns_.begin(); ci != Columns_.end(); ++ci) {
            if (!(*ci)->Load(input, rows)) {
                return false;
            }
        }

        return true;
    }

    void TColumnTuple::Save(TCodedOutputStream* output) {
        for (auto ci = Columns_.begin(); ci != Columns_.end(); ++ci) {
            (*ci)->Save(output);
        }
    }

}