Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
impala::ExchangeNode Class Reference

#include <exchange-node.h>

Inheritance diagram for impala::ExchangeNode:
Collaboration diagram for impala::ExchangeNode:

Public Member Functions

 ExchangeNode (ObjectPool *pool, const TPlanNode &tnode, const DescriptorTbl &descs)
 
virtual Status Init (const TPlanNode &tnode)
 
virtual Status Prepare (RuntimeState *state)
 
virtual Status Open (RuntimeState *state)
 Blocks until the first batch is available for consumption via GetNext(). More...
 
virtual Status GetNext (RuntimeState *state, RowBatch *row_batch, bool *eos)
 
virtual Status Reset (RuntimeState *state)
 
virtual void Close (RuntimeState *state)
 
void set_num_senders (int num_senders)
 
void CollectNodes (TPlanNodeType::type node_type, std::vector< ExecNode * > *nodes)
 
void CollectScanNodes (std::vector< ExecNode * > *nodes)
 Collect all scan node types. More...
 
std::string DebugString () const
 Returns a string representation in DFS order of the plan rooted at this. More...
 
const std::vector< ExprContext * > & conjunct_ctxs () const
 
int id () const
 
TPlanNodeType::type type () const
 
const RowDescriptorrow_desc () const
 
int64_t rows_returned () const
 
int64_t limit () const
 
bool ReachedLimit ()
 
RuntimeProfileruntime_profile ()
 
MemTrackermem_tracker ()
 
MemTrackerexpr_mem_tracker ()
 

Static Public Member Functions

static Status CreateTree (ObjectPool *pool, const TPlan &plan, const DescriptorTbl &descs, ExecNode **root)
 
static void SetDebugOptions (int node_id, TExecNodePhase::type phase, TDebugAction::type action, ExecNode *tree)
 Set debug action for node with given id in 'tree'. More...
 
static bool EvalConjuncts (ExprContext *const *ctxs, int num_ctxs, TupleRow *row)
 
static llvm::Function * CodegenEvalConjuncts (RuntimeState *state, const std::vector< ExprContext * > &conjunct_ctxs, const char *name="EvalConjuncts")
 
static int GetNodeIdFromProfile (RuntimeProfile *p)
 Extract node id from p->name(). More...
 

Static Public Attributes

static const std::string ROW_THROUGHPUT_COUNTER = "RowsReturnedRate"
 Names of counters shared by all exec nodes. More...
 

Protected Member Functions

virtual void DebugString (int indentation_level, std::stringstream *out) const
 
ExecNodechild (int i)
 
bool is_closed ()
 
virtual bool IsScanNode () const
 
void InitRuntimeProfile (const std::string &name)
 
Status ExecDebugAction (TExecNodePhase::type phase, RuntimeState *state)
 
void AddRuntimeExecOption (const std::string &option)
 Appends option to 'runtime_exec_options_'. More...
 
virtual Status QueryMaintenance (RuntimeState *state)
 
void AddExprCtxToFree (ExprContext *ctx)
 
void AddExprCtxsToFree (const std::vector< ExprContext * > &ctxs)
 
void AddExprCtxsToFree (const SortExecExprs &sort_exec_exprs)
 

Static Protected Member Functions

static Status CreateNode (ObjectPool *pool, const TPlanNode &tnode, const DescriptorTbl &descs, ExecNode **node)
 Create a single exec node derived from thrift node; place exec node in 'pool'. More...
 
static Status CreateTreeHelper (ObjectPool *pool, const std::vector< TPlanNode > &tnodes, const DescriptorTbl &descs, ExecNode *parent, int *node_idx, ExecNode **root)
 

Protected Attributes

int id_
 
TPlanNodeType::type type_
 
ObjectPoolpool_
 
std::vector< ExprContext * > conjunct_ctxs_
 
std::vector< ExecNode * > children_
 
RowDescriptor row_descriptor_
 
TExecNodePhase::type debug_phase_
 
TDebugAction::type debug_action_
 
int64_t limit_
 
int64_t num_rows_returned_
 
boost::scoped_ptr< RuntimeProfileruntime_profile_
 
RuntimeProfile::Counterrows_returned_counter_
 
RuntimeProfile::Counterrows_returned_rate_
 
boost::scoped_ptr< MemTrackermem_tracker_
 Account for peak memory used by this node. More...
 
boost::scoped_ptr< MemTrackerexpr_mem_tracker_
 MemTracker that should be used for ExprContexts. More...
 
boost::mutex exec_options_lock_
 
std::string runtime_exec_options_
 

Private Member Functions

Status GetNextMerging (RuntimeState *state, RowBatch *output_batch, bool *eos)
 
Status FillInputRowBatch (RuntimeState *state)
 

Private Attributes

int num_senders_
 
boost::shared_ptr
< DataStreamRecvr
stream_recvr_
 
RowDescriptor input_row_desc_
 our input rows are a prefix of the rows we produce More...
 
RowBatchinput_batch_
 
int next_row_idx_
 
RuntimeProfile::Counterconvert_row_batch_timer_
 time spent reconstructing received rows More...
 
bool is_merging_
 
SortExecExprs sort_exec_exprs_
 Sort expressions and parameters passed to the merging receiver.. More...
 
std::vector< boolis_asc_order_
 
std::vector< boolnulls_first_
 
int64_t offset_
 Offset specifying number of rows to skip. More...
 
int64_t num_rows_skipped_
 Number of rows skipped so far. More...
 

Detailed Description

Receiver node for data streams. The data stream receiver is created in Prepare() and closed in Close(). is_merging is set to indicate that rows from different senders must be merged according to the sort parameters in sort_exec_exprs_. (It is assumed that the rows received from the senders themselves are sorted.) If is_merging_ is true, the exchange node creates a DataStreamRecvr with the is_merging_ flag and retrieves retrieves rows from the receiver via calls to DataStreamRecvr::GetNext(). It also prepares, opens and closes the ordering exprs in its SortExecExprs member that are used to compare rows. If is_merging_ is false, the exchange node directly retrieves batches from the row batch queue of the DataStreamRecvr via calls to DataStreamRecvr::GetBatch().

Definition at line 39 of file exchange-node.h.

Constructor & Destructor Documentation

ExchangeNode::ExchangeNode ( ObjectPool pool,
const TPlanNode &  tnode,
const DescriptorTbl descs 
)

Definition at line 34 of file exchange-node.cc.

References is_merging_, and offset_.

Member Function Documentation

void impala::ExecNode::AddExprCtxsToFree ( const SortExecExprs sort_exec_exprs)
protectedinherited
void impala::ExecNode::AddExprCtxToFree ( ExprContext ctx)
inlineprotectedinherited

Add an ExprContext to have its local allocations freed by QueryMaintenance(). Exprs that are evaluated in the main execution thread should be added. Exprs evaluated in a separate thread are generally not safe to add, since a local allocation may be freed while it's being used. Rather than using this mechanism, threads should call FreeLocalAllocations() on local ExprContexts periodically.

Definition at line 276 of file exec-node.h.

References impala::ExecNode::expr_ctxs_to_free_.

Referenced by impala::AnalyticEvalNode::Prepare().

ExecNode* impala::ExecNode::child ( int  i)
inlineprotectedinherited

Definition at line 241 of file exec-node.h.

References impala::ExecNode::children_.

Referenced by impala::CrossJoinNode::BuildListDebugString(), impala::BlockingJoinNode::BuildSideThread(), impala::HashJoinNode::CodegenCreateOutputRow(), impala::PartitionedHashJoinNode::CodegenCreateOutputRow(), impala::CrossJoinNode::ConstructBuildSide(), impala::HashJoinNode::ConstructBuildSide(), impala::PartitionedHashJoinNode::ConstructBuildSide(), impala::BlockingJoinNode::GetLeftChildRowString(), impala::SelectNode::GetNext(), impala::UnionNode::GetNext(), impala::CrossJoinNode::GetNext(), impala::HashJoinNode::GetNext(), impala::AnalyticEvalNode::GetNextOutputBatch(), impala::PartitionedAggregationNode::Partition::InitStreams(), impala::HashJoinNode::LeftJoinGetNext(), impala::PartitionedHashJoinNode::NextProbeRowBatch(), impala::SelectNode::Open(), impala::SortNode::Open(), impala::TopNNode::Open(), impala::BlockingJoinNode::Open(), impala::AggregationNode::Open(), impala::AnalyticEvalNode::Open(), impala::PartitionedAggregationNode::Open(), impala::UnionNode::OpenCurrentChild(), impala::SelectNode::Prepare(), impala::SortNode::Prepare(), impala::UnionNode::Prepare(), impala::TopNNode::Prepare(), impala::BlockingJoinNode::Prepare(), impala::HashJoinNode::Prepare(), impala::AggregationNode::Prepare(), impala::AnalyticEvalNode::Prepare(), impala::PartitionedHashJoinNode::Prepare(), impala::PartitionedAggregationNode::Prepare(), impala::PartitionedHashJoinNode::ProcessBuildInput(), impala::AnalyticEvalNode::ProcessChildBatches(), and impala::SortNode::SortInput().

void ExchangeNode::Close ( RuntimeState state)
virtual

Close() will get called for every exec node, regardless of what else is called and the status of these calls (i.e. Prepare() may never have been called, or Prepare()/Open()/GetNext() returned with an error). Close() releases all resources that were allocated in Open()/GetNext(), even if the latter ended with an error. Close() can be called if the node has been prepared or the node is closed. The default implementation updates runtime profile counters and calls Close() on the children. Subclasses should check if the node has already been closed (is_closed()), then close themselves, then call the base Close(). Nodes that are using tuples returned by a child may call Close() on their children before their own Close() if the child node has returned eos. It is only safe to call Close() on the child node while the parent node is still returning rows if the parent node fully materializes the child's input.

Reimplemented from impala::ExecNode.

Definition at line 98 of file exchange-node.cc.

References impala::SortExecExprs::Close(), impala::ExecNode::Close(), impala::ExecNode::is_closed(), is_merging_, sort_exec_exprs_, and stream_recvr_.

void impala::ExecNode::CollectNodes ( TPlanNodeType::type  node_type,
std::vector< ExecNode * > *  nodes 
)
inherited

Collect all nodes of given 'node_type' that are part of this subtree, and return in 'nodes'.

Definition at line 359 of file exec-node.cc.

References impala::ExecNode::children_, and impala::ExecNode::type_.

Referenced by impala::ExecNode::CollectScanNodes(), and impala::PlanFragmentExecutor::Prepare().

void impala::ExecNode::CollectScanNodes ( std::vector< ExecNode * > *  nodes)
inherited

Collect all scan node types.

Definition at line 366 of file exec-node.cc.

References impala::ExecNode::CollectNodes().

Referenced by impala::PlanFragmentExecutor::Prepare().

Status impala::ExecNode::CreateNode ( ObjectPool pool,
const TPlanNode &  tnode,
const DescriptorTbl descs,
ExecNode **  node 
)
staticprotectedinherited

Create a single exec node derived from thrift node; place exec node in 'pool'.

Definition at line 260 of file exec-node.cc.

References impala::ObjectPool::Add(), impala::Status::OK, and RETURN_IF_ERROR.

Referenced by impala::ExecNode::CreateTreeHelper().

Status impala::ExecNode::CreateTree ( ObjectPool pool,
const TPlan &  plan,
const DescriptorTbl descs,
ExecNode **  root 
)
staticinherited

Creates exec node tree from list of nodes contained in plan via depth-first traversal. All nodes are placed in pool. Returns error if 'plan' is corrupted, otherwise success.

Definition at line 199 of file exec-node.cc.

References impala::ExecNode::CreateTreeHelper(), impala::Status::OK, and impala::Status::ok().

Referenced by impala::PlanFragmentExecutor::Prepare().

Status impala::ExecNode::CreateTreeHelper ( ObjectPool pool,
const std::vector< TPlanNode > &  tnodes,
const DescriptorTbl descs,
ExecNode parent,
int *  node_idx,
ExecNode **  root 
)
staticprotectedinherited
void ExchangeNode::DebugString ( int  indentation_level,
std::stringstream *  out 
) const
protectedvirtual

Recursive helper method for generating a string for DebugString(). Implementations should call DebugString(int, std::stringstream) on their children. Input parameters: indentation_level: Current level in plan tree. Output parameters: out: Stream to accumulate debug string.

Reimplemented from impala::ExecNode.

Definition at line 207 of file exchange-node.cc.

References impala::ExecNode::DebugString(), and num_senders_.

Status ExchangeNode::FillInputRowBatch ( RuntimeState state)
private

Resets input_batch_ to the next batch from the from stream_recvr_'s queue. Only used when is_merging_ is false.

Definition at line 106 of file exchange-node.cc.

References impala::RuntimeState::fragment_instance_id(), input_batch_, is_merging_, impala::Status::IsCancelled(), SCOPED_TIMER, stream_recvr_, impala::RuntimeState::total_network_receive_timer(), and VLOG_FILE.

Referenced by GetNext(), and Open().

Status ExchangeNode::GetNext ( RuntimeState state,
RowBatch row_batch,
bool eos 
)
virtual

Retrieves rows and returns them via row_batch. Sets eos to true if subsequent calls will not retrieve any more rows. Data referenced by any tuples returned in row_batch must not be overwritten by the callee until Close() is called. The memory holding that data can be returned via row_batch's tuple_data_pool (in which case it may be deleted by the caller) or held on to by the callee. The row_batch, including its tuple_data_pool, will be destroyed by the caller at some point prior to the final Close() call. In other words, if the memory holding the tuple data will be referenced by the callee in subsequent GetNext() calls, it must not be attached to the row_batch's tuple_data_pool. Caller must not be holding any io buffers. This will cause deadlock. TODO: AggregationNode and HashJoinNode cannot be "re-opened" yet.

Implements impala::ExecNode.

Definition at line 120 of file exchange-node.cc.

References impala::RowBatch::AddRow(), impala::RowBatch::AtCapacity(), impala::RowBatch::capacity(), impala::RowBatch::ClearRow(), impala::RowBatch::CommitLastRow(), convert_row_batch_timer_, impala::RowBatch::CopyRow(), COUNTER_SET, impala::ExecNode::ExecDebugAction(), FillInputRowBatch(), GetNextMerging(), impala::RowBatch::GetRow(), input_batch_, is_merging_, impala::RowDescriptor::IsPrefixOf(), next_row_idx_, impala::ExecNode::num_rows_returned_, impala::Status::OK, impala::ExecNode::QueryMaintenance(), impala::ExecNode::ReachedLimit(), RETURN_IF_CANCELLED, RETURN_IF_ERROR, impala::RowBatch::row_desc(), impala::ExecNode::rows_returned_counter_, impala::ExecNode::runtime_profile_, SCOPED_TIMER, and stream_recvr_.

int impala::ExecNode::GetNodeIdFromProfile ( RuntimeProfile p)
staticinherited

Extract node id from p->name().

Definition at line 62 of file exec-node.cc.

References impala::RuntimeProfile::metadata().

Status ExchangeNode::Init ( const TPlanNode &  tnode)
virtual

Initializes this object from the thrift tnode desc. The subclass should do any initialization that can fail in Init() rather than the ctor. If overridden in subclass, must first call superclass's Init().

Reimplemented from impala::ExecNode.

Definition at line 51 of file exchange-node.cc.

References impala::SortExecExprs::Init(), impala::ExecNode::Init(), is_asc_order_, is_merging_, nulls_first_, impala::Status::OK, impala::ExecNode::pool_, RETURN_IF_ERROR, and sort_exec_exprs_.

void impala::ExecNode::InitRuntimeProfile ( const std::string &  name)
protectedinherited
virtual bool impala::ExecNode::IsScanNode ( ) const
inlineprotectedvirtualinherited

Reimplemented in impala::ScanNode.

Definition at line 251 of file exec-node.h.

int64_t impala::ExecNode::limit ( ) const
inlineinherited
Status ExchangeNode::Prepare ( RuntimeState state)
virtual

Sets up internal structures, etc., without doing any actual work. Must be called prior to Open(). Will only be called once in this node's lifetime. All code generation (adding functions to the LlvmCodeGen object) must happen in Prepare(). Retrieving the jit compiled function pointer must happen in Open(). If overridden in subclass, must first call superclass's Prepare().

Reimplemented from impala::ExecNode.

Definition at line 61 of file exchange-node.cc.

References ADD_TIMER, impala::ExecNode::AddExprCtxsToFree(), convert_row_batch_timer_, impala::DataStreamMgr::CreateRecvr(), impala::ExecNode::expr_mem_tracker(), impala::RuntimeState::fragment_instance_id(), impala::ExecEnv::GetInstance(), impala::ExecNode::id_, input_row_desc_, is_merging_, num_senders_, impala::Status::OK, impala::SortExecExprs::Prepare(), impala::ExecNode::Prepare(), RETURN_IF_ERROR, impala::ExecNode::row_descriptor_, impala::ExecNode::runtime_profile(), sort_exec_exprs_, impala::ExecEnv::stream_mgr(), and stream_recvr_.

Status impala::ExecNode::QueryMaintenance ( RuntimeState state)
protectedvirtualinherited
Status ExchangeNode::Reset ( RuntimeState state)
virtual

Resets all data-specific state, returning this node to the state it was in after calling Prepare() and before calling Open(). Prepare() must have already been called before calling Reset(). Open() and GetNext() may have optionally been called. Close() must not have been called. If overridden in a subclass, must call superclass's Reset() at the end. The default implementation calls Reset() on children. Note that this function may be called many times, so should be fast. For example, accumulated memory does not need to be freed on every call if it's expensive.

Reimplemented from impala::ExecNode.

Definition at line 93 of file exchange-node.cc.

const RowDescriptor& impala::ExecNode::row_desc ( ) const
inlineinherited
void impala::ExchangeNode::set_num_senders ( int  num_senders)
inline

the number of senders needs to be set after the c'tor, because it's not recorded in TPlanNode, and before calling Prepare()

Definition at line 53 of file exchange-node.h.

References num_senders_.

void impala::ExecNode::SetDebugOptions ( int  node_id,
TExecNodePhase::type  phase,
TDebugAction::type  action,
ExecNode tree 
)
staticinherited

Set debug action for node with given id in 'tree'.

Definition at line 332 of file exec-node.cc.

References impala::ExecNode::children_, impala::ExecNode::debug_action_, impala::ExecNode::debug_phase_, and impala::ExecNode::id_.

Referenced by impala::PlanFragmentExecutor::Prepare().

TPlanNodeType::type impala::ExecNode::type ( ) const
inlineinherited

Member Data Documentation

RuntimeProfile::Counter* impala::ExchangeNode::convert_row_batch_timer_
private

time spent reconstructing received rows

Definition at line 88 of file exchange-node.h.

Referenced by GetNext(), and Prepare().

TDebugAction::type impala::ExecNode::debug_action_
protectedinherited
TExecNodePhase::type impala::ExecNode::debug_phase_
protectedinherited

debug-only: if debug_action_ is not INVALID, node will perform action in debug_phase_

Definition at line 219 of file exec-node.h.

Referenced by impala::ExecNode::ExecDebugAction(), and impala::ExecNode::SetDebugOptions().

boost::mutex impala::ExecNode::exec_options_lock_
protectedinherited

Execution options that are determined at runtime. This is added to the runtime profile at Close(). Examples for options logged here would be "Codegen Enabled"

Definition at line 238 of file exec-node.h.

Referenced by impala::ExecNode::AddRuntimeExecOption().

boost::scoped_ptr<MemTracker> impala::ExecNode::expr_mem_tracker_
protectedinherited

MemTracker that should be used for ExprContexts.

Definition at line 233 of file exec-node.h.

Referenced by impala::ExecNode::expr_mem_tracker(), and impala::ExecNode::Prepare().

RowBatch* impala::ExchangeNode::input_batch_
private

Current batch of rows from the receiver queue being processed by this node. Only valid if is_merging_ is false. (If is_merging_ is true, GetNext() is delegated to the receiver). Owned by the stream receiver.

Definition at line 80 of file exchange-node.h.

Referenced by FillInputRowBatch(), and GetNext().

RowDescriptor impala::ExchangeNode::input_row_desc_
private

our input rows are a prefix of the rows we produce

Definition at line 75 of file exchange-node.h.

Referenced by Prepare().

std::vector<bool> impala::ExchangeNode::is_asc_order_
private

Definition at line 96 of file exchange-node.h.

Referenced by Init(), and Open().

bool impala::ExchangeNode::is_merging_
private

True if this is a merging exchange node. If true, GetNext() is delegated to the underlying stream_recvr_, and input_batch_ is not used/valid.

Definition at line 92 of file exchange-node.h.

Referenced by Close(), ExchangeNode(), FillInputRowBatch(), GetNext(), Init(), Open(), and Prepare().

boost::scoped_ptr<MemTracker> impala::ExecNode::mem_tracker_
protectedinherited

Account for peak memory used by this node.

Definition at line 230 of file exec-node.h.

Referenced by impala::ExecNode::mem_tracker(), and impala::ExecNode::Prepare().

int impala::ExchangeNode::next_row_idx_
private

Next row to copy from input_batch_. For non-merging exchanges, input_batch_ is retrieved directly from the sender queue in the stream recvr, and rows from input_batch_ must be copied to the output batch in GetNext().

Definition at line 85 of file exchange-node.h.

Referenced by GetNext().

std::vector<bool> impala::ExchangeNode::nulls_first_
private

Definition at line 97 of file exchange-node.h.

Referenced by Init(), and Open().

int64_t impala::ExchangeNode::num_rows_skipped_
private

Number of rows skipped so far.

Definition at line 103 of file exchange-node.h.

Referenced by GetNextMerging().

int impala::ExchangeNode::num_senders_
private

Definition at line 67 of file exchange-node.h.

Referenced by DebugString(), Prepare(), and set_num_senders().

int64_t impala::ExchangeNode::offset_
private

Offset specifying number of rows to skip.

Definition at line 100 of file exchange-node.h.

Referenced by ExchangeNode(), and GetNextMerging().

RowDescriptor impala::ExecNode::row_descriptor_
protectedinherited
const string impala::ExecNode::ROW_THROUGHPUT_COUNTER = "RowsReturnedRate"
staticinherited

Names of counters shared by all exec nodes.

Definition at line 169 of file exec-node.h.

Referenced by impala::ExecNode::Prepare().

RuntimeProfile::Counter* impala::ExecNode::rows_returned_rate_
protectedinherited

Definition at line 227 of file exec-node.h.

Referenced by impala::ExecNode::Prepare().

std::string impala::ExecNode::runtime_exec_options_
protectedinherited

Definition at line 239 of file exec-node.h.

Referenced by impala::ExecNode::AddRuntimeExecOption().

boost::scoped_ptr<RuntimeProfile> impala::ExecNode::runtime_profile_
protectedinherited
SortExecExprs impala::ExchangeNode::sort_exec_exprs_
private

Sort expressions and parameters passed to the merging receiver..

Definition at line 95 of file exchange-node.h.

Referenced by Close(), Init(), Open(), and Prepare().

boost::shared_ptr<DataStreamRecvr> impala::ExchangeNode::stream_recvr_
private

The underlying DataStreamRecvr instance. Ownership is shared between this exchange node instance and the DataStreamMgr used to create the receiver. stream_recvr_->Close() must be called before this instance is destroyed.

Definition at line 72 of file exchange-node.h.

Referenced by Close(), FillInputRowBatch(), GetNext(), GetNextMerging(), Open(), and Prepare().

TPlanNodeType::type impala::ExecNode::type_
protectedinherited

Definition at line 210 of file exec-node.h.

Referenced by impala::ExecNode::CollectNodes(), and impala::ExecNode::type().


The documentation for this class was generated from the following files: