Skip to content

Commit a5c39d4

Browse files
authored
Merge pull request #161 from Enmk/query_id
Query_ID support
2 parents f1f32f1 + 07a928f commit a5c39d4

22 files changed

+458
-117
lines changed

clickhouse/block.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Block::Iterator::Iterator(const Block& block)
1010
{
1111
}
1212

13+
Block::Iterator::Iterator(const Block& block, Block::Iterator::ConstructAtEndTag /*at_end*/)
14+
: block_(block)
15+
, idx_(block.GetColumnCount())
16+
{}
17+
1318
const std::string& Block::Iterator::Name() const {
1419
return block_.columns_[idx_].name;
1520
}
@@ -22,8 +27,9 @@ ColumnRef Block::Iterator::Column() const {
2227
return block_.columns_[idx_].column;
2328
}
2429

25-
void Block::Iterator::Next() {
30+
bool Block::Iterator::Next() {
2631
++idx_;
32+
return IsValid();
2733
}
2834

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

104+
Block::Iterator Block::begin() const {
105+
return Iterator(*this);
106+
}
107+
108+
Block::Iterator Block::end() const {
109+
return Iterator(*this, Iterator::ConstructAtEndTag{});
110+
}
111+
98112
}

clickhouse/block.h

+29-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,35 @@ class Block {
2525
/// Reference to column object.
2626
ColumnRef Column() const;
2727

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

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

34+
size_t ColumnIndex() const {
35+
return idx_;
36+
}
37+
38+
Iterator& operator*() { return *this; }
39+
const Iterator& operator*() const { return *this; }
40+
41+
bool operator==(const Iterator & other) const {
42+
return &block_ == &other.block_ && idx_ == other.idx_;
43+
}
44+
bool operator!=(const Iterator & other) const {
45+
return !(*this == other);
46+
}
47+
48+
Iterator& operator++() {
49+
this->Next();
50+
return *this;
51+
}
52+
3453
private:
54+
friend class Block;
55+
struct ConstructAtEndTag {};
56+
Iterator(const Block& block, ConstructAtEndTag at_end);
3557
Iterator() = delete;
3658

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

88+
Iterator begin() const;
89+
Iterator end() const;
90+
Iterator cbegin() const { return begin(); }
91+
Iterator cend() const { return end(); }
92+
6693
private:
6794
struct ColumnItem {
6895
std::string name;

0 commit comments

Comments
 (0)