Skip to content
Merged
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
12 changes: 12 additions & 0 deletions clickhouse/columns/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ ColumnRef ColumnArray::GetData() {
return data_;
}

std::shared_ptr<const Column> ColumnArray::GetData() const {
return data_;
}

std::shared_ptr<ColumnUInt64>& ColumnArray::GetOffsets() {
return offsets_;
}

std::shared_ptr<const ColumnUInt64> ColumnArray::GetOffsets() const {
return offsets_;
}

void ColumnArray::Reset() {
data_.reset();
offsets_.reset();
Expand Down
24 changes: 17 additions & 7 deletions clickhouse/columns/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,26 @@ class ColumnArray : public Column {

void OffsetsIncrease(size_t);

/// Gets the backing data array of the Array's. This does not include any Array Bounds.
ColumnRef GetData();
std::shared_ptr<const Column> GetData() const;

/// Gets all offsets denoting the list boundaries overlayed GetData.
/// The layout is [size_i, ...] where `i` is the row.
std::shared_ptr<ColumnUInt64>& GetOffsets();
std::shared_ptr<const ColumnUInt64> GetOffsets() const;

/// Gets the offset of the start of row `n` into `GetData()`.
size_t GetOffset(size_t n) const;

/// Gets the element count of row `n`.
size_t GetSize(size_t n) const;

protected:
template<typename T> friend class ColumnArrayT;

ColumnArray(ColumnArray&& array);

size_t GetOffset(size_t n) const;
size_t GetSize(size_t n) const;
ColumnRef GetData();
void AddOffset(size_t n);
void Reset();

Expand Down Expand Up @@ -262,11 +274,9 @@ class ColumnArrayT : public ColumnArray {
template <typename Container>
inline void Append(Container&& container) {
using container_type = decltype(container);
if constexpr (std::is_lvalue_reference_v<container_type> ||
std::is_const_v<std::remove_reference_t<container_type>>) {
if constexpr (std::is_lvalue_reference_v<container_type> || std::is_const_v<std::remove_reference_t<container_type>>) {
Append(std::begin(container), std::end(container));
}
else {
} else {
Append(std::make_move_iterator(std::begin(container)),
std::make_move_iterator(std::end(container)));
}
Expand Down
44 changes: 44 additions & 0 deletions ut/column_array_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,47 @@ TEST(ColumnArrayT, const_right_value_no_move) {
EXPECT_EQ(values[2], value2);
}
}

TEST(ColumnArray, GetData) {
auto col = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{1, 2, 3}));
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{4, 5}));

ColumnRef data = col->GetData();
EXPECT_EQ(data->Size(), 5u);

const auto& ccol = *col;
std::shared_ptr<const Column> cdata = ccol.GetData();
EXPECT_EQ(cdata->Size(), 5u);
}

TEST(ColumnArray, GetOffsets) {
auto col = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{1, 2, 3}));
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{4, 5}));

auto& offsets = col->GetOffsets();
ASSERT_EQ(offsets->Size(), 2u);
EXPECT_EQ((*offsets)[0], 3u);
EXPECT_EQ((*offsets)[1], 5u);

const auto& ccol = *col;
std::shared_ptr<const ColumnUInt64> coffsets = ccol.GetOffsets();
EXPECT_EQ((*coffsets)[0], 3u);
EXPECT_EQ((*coffsets)[1], 5u);
}

TEST(ColumnArray, GetOffsetAndSize) {
auto col = std::make_shared<ColumnArray>(std::make_shared<ColumnUInt64>());
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{10, 20}));
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{30}));
col->AppendAsColumn(std::make_shared<ColumnUInt64>(std::vector<uint64_t>{}));

EXPECT_EQ(col->GetOffset(0), 0u);
EXPECT_EQ(col->GetOffset(1), 2u);
EXPECT_EQ(col->GetOffset(2), 3u);

EXPECT_EQ(col->GetSize(0), 2u);
EXPECT_EQ(col->GetSize(1), 1u);
EXPECT_EQ(col->GetSize(2), 0u);
}
Loading