30 #include "gen-cpp/Exprs_types.h"
31 #include "gen-cpp/PlanNodes_types.h"
35 using std::priority_queue;
36 using namespace impala;
40 offset_(tnode.sort_node.__isset.
offset ? tnode.sort_node.
offset : 0),
41 num_rows_skipped_(0) {
51 <<
"TopNNode should never have predicates to evaluate.";
93 for (
int i = 0; i < batch.num_rows(); ++i) {
117 int row_idx = row_batch->
AddRow();
121 row_batch->
CopyRow(src_row, dst_row);
132 DCHECK(
false) <<
"NYI";
145 Tuple* insert_tuple = NULL;
148 insert_tuple =
reinterpret_cast<Tuple*
>(
161 insert_tuple = top_tuple;
185 *out << string(indentation_level * 2,
' ');
189 *out << (i > 0 ?
" " :
"")
std::vector< bool > is_asc_order_
int64_t num_rows_returned_
MemTracker * mem_tracker()
void InsertTupleRow(TupleRow *tuple_row)
boost::scoped_ptr< RuntimeProfile > runtime_profile_
virtual Status Reset(RuntimeState *state)
A tuple with 0 materialised slots is represented as NULL.
#define RETURN_IF_ERROR(stmt)
some generally useful macros
virtual Status Init(const TPlanNode &tnode)
TupleRow * GetRow(int row_idx)
RowDescriptor row_descriptor_
const RowDescriptor & row_desc() const
Status ExecDebugAction(TExecNodePhase::type phase, RuntimeState *state)
Status Open(RuntimeState *state)
Open all expressions used for sorting and tuple materialization.
Tuple * DeepCopy(const TupleDescriptor &desc, MemPool *pool, bool convert_ptrs=false)
boost::scoped_ptr< TupleRowComparator > tuple_row_less_than_
std::vector< bool > nulls_first_
boost::scoped_ptr< MemPool > tuple_pool_
Stores everything referenced in priority_queue_.
virtual Status Prepare(RuntimeState *state)
std::string DebugString() const
Returns a string representation in DFS order of the plan rooted at this.
MemTracker * expr_mem_tracker()
std::vector< Tuple * >::iterator get_next_iter_
virtual Status Init(const TPlanNode &tnode)
void Reset()
Resets the row batch, returning all resources it has accumulated.
virtual void Close(RuntimeState *state)
#define RETURN_IF_CANCELLED(state)
Status Init(const TSortInfo &sort_info, ObjectPool *pool)
Initialize the expressions from a TSortInfo using the specified pool.
virtual Status GetNext(RuntimeState *state, RowBatch *row_batch, bool *eos)
TopNNode(ObjectPool *pool, const TPlanNode &tnode, const DescriptorTbl &descs)
int64_t offset_
Number of rows to skip.
virtual Status Prepare(RuntimeState *state)
std::vector< Tuple * > sorted_top_n_
After computing the TopN in the priority_queue, pop them and put them in this vector.
const std::vector< ExprContext * > & lhs_ordering_expr_ctxs() const
Can only be used after calling Prepare()
void AddExprCtxsToFree(const std::vector< ExprContext * > &ctxs)
virtual Status QueryMaintenance(RuntimeState *state)
#define COUNTER_SET(c, v)
RuntimeProfile::Counter * rows_returned_counter_
const std::vector< TupleDescriptor * > & tuple_descriptors() const
Return descriptors for all tuples in this row, in order of appearance.
TupleDescriptor * materialized_tuple_desc_
Cached descriptor for the materialized tuple. Assigned in Prepare().
void CopyRow(TupleRow *src, TupleRow *dest)
uint8_t offset[7 *64-sizeof(uint64_t)]
Status Prepare(RuntimeState *state, const RowDescriptor &child_row_desc, const RowDescriptor &output_row_desc, MemTracker *expr_mem_tracker)
Prepare all expressions used for sorting and tuple materialization.
void MaterializeExprs(TupleRow *row, const TupleDescriptor &desc, const std::vector< ExprContext * > &materialize_expr_ctxs, MemPool *pool, std::vector< StringValue * > *non_null_var_len_values=NULL, int *total_var_len=NULL)
SortExecExprs sort_exec_exprs_
virtual Status Open(RuntimeState *state)
virtual Status Open(RuntimeState *state)
void PrepareForOutput()
Flatten and reverse the priority queue.
boost::scoped_ptr< std::priority_queue< Tuple *, std::vector< Tuple * >, TupleRowComparator > > priority_queue_
std::vector< ExprContext * > conjunct_ctxs_
int64_t num_rows_skipped_
virtual void Close(RuntimeState *state)
virtual std::string DebugString() const
void Close(RuntimeState *state)
Close all expressions used for sorting and tuple materialization.
const std::vector< ExprContext * > & sort_tuple_slot_expr_ctxs() const
const std::vector< ExprContext * > & rhs_ordering_expr_ctxs() const
Can only be used after calling Open()