| 206 | } |
| 207 | |
| 208 | void TopNPlanNode::Codegen(FragmentState* state) { |
| 209 | DCHECK(state->ShouldCodegen()); |
| 210 | PlanNode::Codegen(state); |
| 211 | if (IsNodeCodegenDisabled()) return; |
| 212 | LlvmCodeGen* codegen = state->codegen(); |
| 213 | DCHECK(codegen != NULL); |
| 214 | |
| 215 | llvm::Function* compare_fn = nullptr; |
| 216 | llvm::Function* intra_partition_compare_fn = nullptr; |
| 217 | Status codegen_status = ordering_comparator_config_->Codegen(state, &compare_fn); |
| 218 | if (codegen_status.ok() && is_partitioned()) { |
| 219 | codegen_status = |
| 220 | Sorter::TupleSorter::Codegen(state, compare_fn, output_tuple_desc_->byte_size(), |
| 221 | &codegend_sort_helper_fn_); |
| 222 | } |
| 223 | if (codegen_status.ok() && is_partitioned()) { |
| 224 | // TODO: IMPALA-10228: replace comparisons in std::map. |
| 225 | codegen_status = partition_comparator_config_->Codegen(state); |
| 226 | } |
| 227 | if (codegen_status.ok() && is_partitioned()) { |
| 228 | codegen_status = |
| 229 | intra_partition_comparator_config_->Codegen(state, &intra_partition_compare_fn); |
| 230 | } |
| 231 | if (codegen_status.ok()) { |
| 232 | llvm::Function* insert_batch_fn = codegen->GetFunction(is_partitioned() ? |
| 233 | IRFunction::TOPN_NODE_INSERT_BATCH_PARTITIONED : |
| 234 | IRFunction::TOPN_NODE_INSERT_BATCH_UNPARTITIONED, true); |
| 235 | DCHECK(insert_batch_fn != NULL); |
| 236 | |
| 237 | // Generate two MaterializeExprs() functions, one with no pool that |
| 238 | // does a shallow copy (used in partitioned and unpartitioned modes) and |
| 239 | // one with 'tuple_pool_' that does a deep copy of the data. |
| 240 | DCHECK(output_tuple_desc_ != NULL); |
| 241 | llvm::Function* materialize_exprs_tuple_pool_fn = nullptr; |
| 242 | llvm::Function* materialize_exprs_no_pool_fn = nullptr; |
| 243 | |
| 244 | if (!is_partitioned()) { |
| 245 | codegen_status = Tuple::CodegenMaterializeExprs(codegen, false, |
| 246 | *output_tuple_desc_, output_tuple_exprs_, |
| 247 | true, &materialize_exprs_tuple_pool_fn); |
| 248 | } |
| 249 | |
| 250 | if (codegen_status.ok()) { |
| 251 | codegen_status = Tuple::CodegenMaterializeExprs(codegen, false, |
| 252 | *output_tuple_desc_, output_tuple_exprs_, |
| 253 | false, &materialize_exprs_no_pool_fn); |
| 254 | } |
| 255 | |
| 256 | if (codegen_status.ok()) { |
| 257 | int replaced; |
| 258 | if (!is_partitioned()) { |
| 259 | replaced = codegen->ReplaceCallSites(insert_batch_fn, |
| 260 | materialize_exprs_tuple_pool_fn, Tuple::MATERIALIZE_EXPRS_SYMBOL); |
| 261 | DCHECK_REPLACE_COUNT(replaced, 1) << LlvmCodeGen::Print(insert_batch_fn); |
| 262 | } |
| 263 | |
| 264 | replaced = codegen->ReplaceCallSites(insert_batch_fn, |
| 265 | materialize_exprs_no_pool_fn, Tuple::MATERIALIZE_EXPRS_NULL_POOL_SYMBOL); |
nothing calls this directly
no test coverage detected