Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clickhouse/columns/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ ColumnRef ColumnArray::GetAsColumn(size_t n) const {
return data_->Slice(GetOffset(n), GetSize(n));
}

ColumnRef ColumnArray::NewColumn() const {
return data_->CloneEmpty();
}

ColumnRef ColumnArray::Slice(size_t begin, size_t size) const {
if (size && begin + size > Size())
throw ValidationError("Slice indexes are out of bounds");
Expand Down
9 changes: 9 additions & 0 deletions clickhouse/columns/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class ColumnArray : public Column {
return GetAsColumn(n)->AsStrict<T>();
}

/// Create a new, empty column of the same type as the array element.
ColumnRef NewColumn() const;

/// Shorthand to create a new column casted to a proper type.
template <typename T>
auto NewColumnAsType() const {
return NewColumn()->AsStrict<T>();
}

public:
/// Increase the capacity of the column for large block insertion.
void Reserve(size_t new_cap) override;
Expand Down
2 changes: 1 addition & 1 deletion ut/column_array_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST(ColumnArray, Append) {
auto arr1 = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
auto arr2 = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());

auto id = std::make_shared<ColumnUInt64>();
auto id = arr1->NewColumnAsType<ColumnUInt64>();
id->Append(1);
arr1->AppendAsColumn(id);

Expand Down
Loading