@@ -14,17 +14,23 @@ class ColumnArrayT;
14
14
* Represents column of Array(T).
15
15
*/
16
16
class ColumnArray : public Column {
17
- protected:
18
- struct DoNotCloneDataColumnTag {};
19
-
20
17
public:
21
18
using ValueType = ColumnRef;
22
19
23
- // Create an array of given type, values inside `data` are not taken into account.
20
+ /* * Create an array of given type.
21
+ *
22
+ * `data` is used internaly (and modified) by ColumnArray.
23
+ * Users are strongly advised against supplying non-empty columns and/or modifying
24
+ * contents of `data` afterwards.
25
+ */
24
26
explicit ColumnArray (ColumnRef data);
25
27
26
- // Not expected to be used by users, hence protected `DoNotCloneDataColumnTag`
27
- ColumnArray (ColumnRef data, DoNotCloneDataColumnTag tag);
28
+ /* * Create an array of given type, with actual values and offsets.
29
+ *
30
+ * Both `data` and `offsets` are used (and modified) internally bye ColumnArray.
31
+ * Users are strongly advised against modifying contents of `data` or `offsets` afterwards.
32
+ */
33
+ ColumnArray (ColumnRef data, std::shared_ptr<ColumnUInt64> offsets);
28
34
29
35
// / Converts input column to array and appends
30
36
// / as one row to the current column.
@@ -37,8 +43,7 @@ class ColumnArray : public Column {
37
43
// / Shorthand to get a column casted to a proper type.
38
44
template <typename T>
39
45
auto GetAsColumnTyped (size_t n) const {
40
- auto result = GetAsColumn (n);
41
- return result->AsStrict <T>();
46
+ return GetAsColumn (n)->AsStrict <T>();
42
47
}
43
48
44
49
public:
@@ -80,20 +85,26 @@ class ColumnArray : public Column {
80
85
std::shared_ptr<ColumnUInt64> offsets_;
81
86
};
82
87
83
- template <typename NestedColumnType >
88
+ template <typename ColumnType >
84
89
class ColumnArrayT : public ColumnArray {
85
90
public:
86
91
class ArrayValueView ;
87
92
using ValueType = ArrayValueView;
93
+ using NestedColumnType = ColumnType;
88
94
89
95
explicit ColumnArrayT (std::shared_ptr<NestedColumnType> data)
90
96
: ColumnArray(data)
91
- , typed_nested_data_(this ->GetData ()->template AsStrict<NestedColumnType>())
97
+ , typed_nested_data_(data)
98
+ {}
99
+
100
+ ColumnArrayT (std::shared_ptr<NestedColumnType> data, std::shared_ptr<ColumnUInt64> offsets)
101
+ : ColumnArray(data, offsets)
102
+ , typed_nested_data_(data)
92
103
{}
93
104
94
105
template <typename ...Args>
95
106
explicit ColumnArrayT (Args &&... args)
96
- : ColumnArrayT(std::make_shared<NestedColumnType>(std::forward<Args>(args)...), ColumnArray::DoNotCloneDataColumnTag{} )
107
+ : ColumnArrayT(std::make_shared<NestedColumnType>(std::forward<Args>(args)...))
97
108
{}
98
109
99
110
/* * Create a ColumnArrayT from a ColumnArray, without copying data and offsets, but by 'stealing' those from `col`.
@@ -107,14 +118,10 @@ class ColumnArrayT : public ColumnArray {
107
118
static auto Wrap (ColumnArray&& col) {
108
119
if constexpr (std::is_base_of_v<ColumnArray, NestedColumnType> && !std::is_same_v<ColumnArray, NestedColumnType>) {
109
120
// assuming NestedColumnType is ArrayT specialization
110
-
111
- auto result = std::make_shared<ColumnArrayT<NestedColumnType>>(NestedColumnType::Wrap (col.GetData ()), ColumnArray::DoNotCloneDataColumnTag{});
112
- result->offsets_ = col.offsets_ ;
113
-
114
- return result;
121
+ return std::make_shared<ColumnArrayT<NestedColumnType>>(NestedColumnType::Wrap (col.GetData ()), col.offsets_ );
115
122
} else {
116
123
auto nested_data = col.GetData ()->template AsStrict <NestedColumnType>();
117
- return std::shared_ptr <ColumnArrayT<NestedColumnType>>(new ColumnArrayT<NestedColumnType>( std::move (col), std::move (nested_data)) );
124
+ return std::make_shared <ColumnArrayT<NestedColumnType>>(nested_data, col. offsets_ );
118
125
}
119
126
}
120
127
@@ -255,13 +262,6 @@ class ColumnArrayT : public ColumnArray {
255
262
AddOffset (counter);
256
263
}
257
264
258
- public:
259
- // Helper to allow wrapping 2D-Arrays and also to optimize certain constructors.
260
- ColumnArrayT (std::shared_ptr<NestedColumnType> data, ColumnArray::DoNotCloneDataColumnTag tag)
261
- : ColumnArray(data, tag)
262
- , typed_nested_data_(data)
263
- {}
264
-
265
265
private:
266
266
// / Helper to allow wrapping a "typeless" ColumnArray
267
267
ColumnArrayT (ColumnArray&& array, std::shared_ptr<NestedColumnType> nested_data)
0 commit comments