File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,10 @@ ColumnRef ColumnArray::GetAsColumn(size_t n) const {
5959 return data_->Slice (GetOffset (n), GetSize (n));
6060}
6161
62+ ColumnRef ColumnArray::NewColumn () const {
63+ return data_->CloneEmpty ();
64+ }
65+
6266ColumnRef ColumnArray::Slice (size_t begin, size_t size) const {
6367 if (size && begin + size > Size ())
6468 throw ValidationError (" Slice indexes are out of bounds" );
Original file line number Diff line number Diff line change @@ -46,6 +46,15 @@ class ColumnArray : public Column {
4646 return GetAsColumn (n)->AsStrict <T>();
4747 }
4848
49+ // / Create a new, empty column of the same type as the array element.
50+ ColumnRef NewColumn () const ;
51+
52+ // / Shorthand to create a new column casted to a proper type.
53+ template <typename T>
54+ auto NewColumnAsType () const {
55+ return NewColumn ()->AsStrict <T>();
56+ }
57+
4958public:
5059 // / Increase the capacity of the column for large block insertion.
5160 void Reserve (size_t new_cap) override ;
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ TEST(ColumnArray, Append) {
5353 auto arr1 = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
5454 auto arr2 = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
5555
56- auto id = std::make_shared <ColumnUInt64>();
56+ auto id = arr1-> NewColumnAsType <ColumnUInt64>();
5757 id->Append (1 );
5858 arr1->AppendAsColumn (id);
5959
You can’t perform that action at this time.
0 commit comments