Skip to content

Commit

Permalink
Merge pull request #161 from Enmk/query_id
Browse files Browse the repository at this point in the history
Query_ID support
  • Loading branch information
Enmk authored Mar 8, 2022
2 parents f1f32f1 + 07a928f commit a5c39d4
Show file tree
Hide file tree
Showing 22 changed files with 458 additions and 117 deletions.
16 changes: 15 additions & 1 deletion clickhouse/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Block::Iterator::Iterator(const Block& block)
{
}

Block::Iterator::Iterator(const Block& block, Block::Iterator::ConstructAtEndTag /*at_end*/)
: block_(block)
, idx_(block.GetColumnCount())
{}

const std::string& Block::Iterator::Name() const {
return block_.columns_[idx_].name;
}
Expand All @@ -22,8 +27,9 @@ ColumnRef Block::Iterator::Column() const {
return block_.columns_[idx_].column;
}

void Block::Iterator::Next() {
bool Block::Iterator::Next() {
++idx_;
return IsValid();
}

bool Block::Iterator::IsValid() const {
Expand Down Expand Up @@ -95,4 +101,12 @@ ColumnRef Block::operator [] (size_t idx) const {
throw std::out_of_range("column index is out of range. Index: ["+std::to_string(idx)+"], columns: [" + std::to_string(columns_.size())+"]");
}

Block::Iterator Block::begin() const {
return Iterator(*this);
}

Block::Iterator Block::end() const {
return Iterator(*this, Iterator::ConstructAtEndTag{});
}

}
31 changes: 29 additions & 2 deletions clickhouse/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,35 @@ class Block {
/// Reference to column object.
ColumnRef Column() const;

/// Move to next column.
void Next();
/// Move to next column, returns false if next call to IsValid() would return false;
bool Next();

/// Is the iterator still valid.
bool IsValid() const;

size_t ColumnIndex() const {
return idx_;
}

Iterator& operator*() { return *this; }
const Iterator& operator*() const { return *this; }

bool operator==(const Iterator & other) const {
return &block_ == &other.block_ && idx_ == other.idx_;
}
bool operator!=(const Iterator & other) const {
return !(*this == other);
}

Iterator& operator++() {
this->Next();
return *this;
}

private:
friend class Block;
struct ConstructAtEndTag {};
Iterator(const Block& block, ConstructAtEndTag at_end);
Iterator() = delete;

const Block& block_;
Expand Down Expand Up @@ -63,6 +85,11 @@ class Block {
/// Reference to column by index in the block.
ColumnRef operator [] (size_t idx) const;

Iterator begin() const;
Iterator end() const;
Iterator cbegin() const { return begin(); }
Iterator cend() const { return end(); }

private:
struct ColumnItem {
std::string name;
Expand Down
Loading

0 comments on commit a5c39d4

Please sign in to comment.