MCPcopy Create free account
hub / github.com/apache/impala / InsertMaterializedTuple

Method InsertMaterializedTuple

be/src/exec/topn-node-ir.cc:157–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157void TopNNode::Heap::InsertMaterializedTuple(
158 TopNNode* node, Tuple* materialized_tuple) {
159 DCHECK(node->is_partitioned());
160 const TupleDescriptor& tuple_desc = *node->output_tuple_desc_;
161 Tuple* insert_tuple = nullptr;
162 if (priority_queue_.Size() < heap_capacity()) {
163 // Add all tuples until we hit capacity.
164 insert_tuple =
165 reinterpret_cast<Tuple*>(node->tuple_pool_->Allocate(node->tuple_byte_size()));
166 materialized_tuple->DeepCopy(insert_tuple, tuple_desc, node->tuple_pool_.get());
167 priority_queue_.Push(insert_tuple);
168 return;
169 }
170
171 // We're at capacity - compare to the first row in the priority queue to see if
172 // we need to insert this row into the heap.
173 DCHECK(!priority_queue_.Empty());
174 Tuple* top_tuple = priority_queue_.Top();
175 if (!include_ties()) {
176 ++num_tuples_discarded_; // One of the tuples will be discarded.
177 int cmp_result =
178 node->intra_partition_order_cmp_->Compare(materialized_tuple, top_tuple);
179 if (cmp_result >= 0) return;
180 // Pop off the old head, and replace with the new tuple. Reuse the fixed-length
181 // memory of 'top_tuple' to reduce allocations.
182 materialized_tuple->DeepCopy(top_tuple, tuple_desc, node->tuple_pool_.get());
183 priority_queue_.HeapifyFromTop();
184 return;
185 }
186 num_tuples_discarded_ += InsertTupleWithTieHandling(
187 *node->intra_partition_order_cmp_, node, materialized_tuple);
188}

Callers 1

Calls 11

TopMethod · 0.80
HeapifyFromTopMethod · 0.80
getMethod · 0.65
is_partitionedMethod · 0.45
SizeMethod · 0.45
AllocateMethod · 0.45
tuple_byte_sizeMethod · 0.45
DeepCopyMethod · 0.45
PushMethod · 0.45
EmptyMethod · 0.45
CompareMethod · 0.45

Tested by

no test coverage detected