Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
row-batch-list.h
Go to the documentation of this file.
1 // Copyright 2013 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_EXEC_ROW_BATCH_LIST_H
17 #define IMPALA_EXEC_ROW_BATCH_LIST_H
18 
19 #include <vector>
20 #include <string>
21 
22 #include "runtime/row-batch.h"
23 #include "common/logging.h" // for DCHECK
24 #include "util/debug-util.h"
25 
26 namespace impala {
27 
28 class TupleRow;
29 class RowDescriptor;
30 class MemPool;
31 
34 class RowBatchList {
35  public:
37 
40  public:
42  TupleRowIterator() : list_(NULL), row_idx_(0) { }
43 
45  bool AtEnd() {
46  return batch_it_ == list_->row_batches_.end();
47  }
48 
52  DCHECK(!AtEnd());
53  return (*batch_it_)->GetRow(row_idx_);
54  }
55 
57  void Next() {
58  if (batch_it_ == list_->row_batches_.end()) return;
59  if (++row_idx_ == (*batch_it_)->num_rows()) {
60  ++batch_it_;
61  row_idx_ = 0;
62  }
63  }
64 
65  private:
66  friend class RowBatchList;
67 
69  : list_(list),
70  batch_it_(list->row_batches_.begin()),
71  row_idx_(0) {
72  }
73 
75  std::vector<RowBatch*>::iterator batch_it_;
76  int64_t row_idx_;
77  };
78 
81  void AddRowBatch(RowBatch* row_batch) {
82  if (row_batch->num_rows() == 0) return;
83  row_batches_.push_back(row_batch);
84  total_num_rows_ += row_batch->num_rows();
85  }
86 
88  void Reset() {
89  row_batches_.clear();
90  total_num_rows_ = 0;
91  }
92 
94  std::string DebugString(const RowDescriptor& desc) {
95  std::stringstream out;
96  out << "RowBatchList(";
97  out << "num_rows=" << total_num_rows_ << "; ";
99  while (!it.AtEnd()) {
100  out << " " << PrintRow(it.GetRow(), desc);
101  it.Next();
102  }
103  out << " )";
104  return out.str();
105  }
106 
108  int64_t total_num_rows() { return total_num_rows_; }
109 
112  return TupleRowIterator(this);
113  }
114 
115  private:
116  friend class TupleRowIterator;
117 
118  std::vector<RowBatch*> row_batches_;
119 
122 };
123 
124 }
125 
126 #endif
TupleRowIterator Iterator()
Returns a new iterator over all the tuple rows.
std::vector< RowBatch * > row_batches_
int num_rows() const
Definition: row-batch.h:215
friend class TupleRowIterator
A simple iterator used to scan over all the rows stored in the list.
int64_t total_num_rows_
Total number of rows.
void AddRowBatch(RowBatch *row_batch)
void Reset()
Resets the list.
bool AtEnd()
Returns true if this iterator is at the end, i.e. GetRow() cannot be called.
std::string DebugString(const RowDescriptor &desc)
Outputs a debug string containing the contents of the list.
std::vector< RowBatch * >::iterator batch_it_
string PrintRow(TupleRow *row, const RowDescriptor &d)
Definition: debug-util.cc:192
void Next()
Increments the iterator. No-op if the iterator is at the end.
int64_t total_num_rows()
Returns the total number of rows in all row batches.