1#pragma once
2
3#include <Core/Block.h>
4
5
6namespace DB
7{
8
9/** Column, that is just group of few another columns.
10 *
11 * For constant Tuples, see ColumnConst.
12 * Mixed constant/non-constant columns is prohibited in tuple
13 * for implementation simplicity.
14 */
15class ColumnTuple final : public COWHelper<IColumn, ColumnTuple>
16{
17private:
18 friend class COWHelper<IColumn, ColumnTuple>;
19
20 using TupleColumns = std::vector<WrappedPtr>;
21 TupleColumns columns;
22
23 template <bool positive>
24 struct Less;
25
26 explicit ColumnTuple(MutableColumns && columns);
27 ColumnTuple(const ColumnTuple &) = default;
28
29public:
30 /** Create immutable column using immutable arguments. This arguments may be shared with other columns.
31 * Use IColumn::mutate in order to make mutable column and mutate shared nested columns.
32 */
33 using Base = COWHelper<IColumn, ColumnTuple>;
34 static Ptr create(const Columns & columns);
35 static Ptr create(const TupleColumns & columns);
36 static Ptr create(Columns && arg) { return create(arg); }
37
38 template <typename Arg, typename = typename std::enable_if<std::is_rvalue_reference<Arg &&>::value>::type>
39 static MutablePtr create(Arg && arg) { return Base::create(std::forward<Arg>(arg)); }
40
41 std::string getName() const override;
42 const char * getFamilyName() const override { return "Tuple"; }
43
44 MutableColumnPtr cloneEmpty() const override;
45 MutableColumnPtr cloneResized(size_t size) const override;
46
47 size_t size() const override
48 {
49 return columns.at(0)->size();
50 }
51
52 Field operator[](size_t n) const override;
53 void get(size_t n, Field & res) const override;
54
55 StringRef getDataAt(size_t n) const override;
56 void insertData(const char * pos, size_t length) override;
57 void insert(const Field & x) override;
58 void insertFrom(const IColumn & src_, size_t n) override;
59 void insertDefault() override;
60 void popBack(size_t n) override;
61 StringRef serializeValueIntoArena(size_t n, Arena & arena, char const *& begin) const override;
62 const char * deserializeAndInsertFromArena(const char * pos) override;
63 void updateHashWithValue(size_t n, SipHash & hash) const override;
64 void insertRangeFrom(const IColumn & src, size_t start, size_t length) override;
65 ColumnPtr filter(const Filter & filt, ssize_t result_size_hint) const override;
66 ColumnPtr permute(const Permutation & perm, size_t limit) const override;
67 ColumnPtr index(const IColumn & indexes, size_t limit) const override;
68 ColumnPtr replicate(const Offsets & offsets) const override;
69 MutableColumns scatter(ColumnIndex num_columns, const Selector & selector) const override;
70 void gather(ColumnGathererStream & gatherer_stream) override;
71 int compareAt(size_t n, size_t m, const IColumn & rhs, int nan_direction_hint) const override;
72 void getExtremes(Field & min, Field & max) const override;
73 void getPermutation(bool reverse, size_t limit, int nan_direction_hint, Permutation & res) const override;
74 void reserve(size_t n) override;
75 size_t byteSize() const override;
76 size_t allocatedBytes() const override;
77 void protect() override;
78 void forEachSubcolumn(ColumnCallback callback) override;
79 bool structureEquals(const IColumn & rhs) const override;
80
81 size_t tupleSize() const { return columns.size(); }
82
83 const IColumn & getColumn(size_t idx) const { return *columns[idx]; }
84 IColumn & getColumn(size_t idx) { return *columns[idx]; }
85
86 const TupleColumns & getColumns() const { return columns; }
87 Columns getColumnsCopy() const { return {columns.begin(), columns.end()}; }
88
89 const ColumnPtr & getColumnPtr(size_t idx) const { return columns[idx]; }
90};
91
92
93}
94