Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
topn-node.h
Go to the documentation of this file.
1 // Copyright 2012 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_TOPN_NODE_H
17 #define IMPALA_EXEC_TOPN_NODE_H
18 
19 #include <queue>
20 #include <boost/scoped_ptr.hpp>
21 
22 #include "exec/exec-node.h"
23 #include "exec/sort-exec-exprs.h"
24 #include "runtime/descriptors.h" // for TupleId
25 #include "util/tuple-row-compare.h"
26 
27 namespace impala {
28 
29 class MemPool;
30 class RuntimeState;
31 class Tuple;
32 
38 class TopNNode : public ExecNode {
39  public:
40  TopNNode(ObjectPool* pool, const TPlanNode& tnode, const DescriptorTbl& descs);
41 
42  virtual Status Init(const TPlanNode& tnode);
43  virtual Status Prepare(RuntimeState* state);
44  virtual Status Open(RuntimeState* state);
45  virtual Status GetNext(RuntimeState* state, RowBatch* row_batch, bool* eos);
46  virtual Status Reset(RuntimeState* state);
47  virtual void Close(RuntimeState* state);
48 
49  protected:
50  virtual void DebugString(int indentation_level, std::stringstream* out) const;
51 
52  private:
53 
54  friend class TupleLessThan;
55 
58  void InsertTupleRow(TupleRow* tuple_row);
59 
61  void PrepareForOutput();
62 
64  int64_t offset_;
66 
70  std::vector<bool> is_asc_order_;
71  std::vector<bool> nulls_first_;
74 
75  boost::scoped_ptr<TupleRowComparator> tuple_row_less_than_;
76 
81  boost::scoped_ptr<
82  std::priority_queue<Tuple*, std::vector<Tuple*>, TupleRowComparator> >
84 
86  std::vector<Tuple*> sorted_top_n_;
87  std::vector<Tuple*>::iterator get_next_iter_;
88 
90  boost::scoped_ptr<MemPool> tuple_pool_;
95 };
96 
97 };
98 
99 #endif
std::vector< bool > is_asc_order_
Definition: topn-node.h:70
void InsertTupleRow(TupleRow *tuple_row)
Definition: topn-node.cc:144
virtual Status Reset(RuntimeState *state)
Definition: topn-node.cc:131
A tuple with 0 materialised slots is represented as NULL.
Definition: tuple.h:48
boost::scoped_ptr< TupleRowComparator > tuple_row_less_than_
Definition: topn-node.h:75
std::vector< bool > nulls_first_
Definition: topn-node.h:71
boost::scoped_ptr< MemPool > tuple_pool_
Stores everything referenced in priority_queue_.
Definition: topn-node.h:90
virtual Status Prepare(RuntimeState *state)
Definition: topn-node.cc:56
std::string DebugString() const
Returns a string representation in DFS order of the plan rooted at this.
Definition: exec-node.cc:345
std::vector< Tuple * >::iterator get_next_iter_
Definition: topn-node.h:87
virtual Status Init(const TPlanNode &tnode)
Definition: topn-node.cc:44
virtual void Close(RuntimeState *state)
Definition: topn-node.cc:136
ObjectPool pool
virtual Status GetNext(RuntimeState *state, RowBatch *row_batch, bool *eos)
Definition: topn-node.cc:106
TopNNode(ObjectPool *pool, const TPlanNode &tnode, const DescriptorTbl &descs)
Definition: topn-node.cc:38
int64_t offset_
Number of rows to skip.
Definition: topn-node.h:64
std::vector< Tuple * > sorted_top_n_
After computing the TopN in the priority_queue, pop them and put them in this vector.
Definition: topn-node.h:86
Tuple * tmp_tuple_
Definition: topn-node.h:94
TupleDescriptor * materialized_tuple_desc_
Cached descriptor for the materialized tuple. Assigned in Prepare().
Definition: topn-node.h:73
friend class TupleLessThan
Definition: topn-node.h:54
SortExecExprs sort_exec_exprs_
Definition: topn-node.h:69
virtual Status Open(RuntimeState *state)
Definition: topn-node.cc:70
void PrepareForOutput()
Flatten and reverse the priority queue.
Definition: topn-node.cc:170
boost::scoped_ptr< std::priority_queue< Tuple *, std::vector< Tuple * >, TupleRowComparator > > priority_queue_
Definition: topn-node.h:83
int64_t num_rows_skipped_
Definition: topn-node.h:65