| 323 | } |
| 324 | |
| 325 | inline Status HdfsTableSink::GetOutputPartition(RuntimeState* state, const TupleRow* row, |
| 326 | const string& key, PartitionPair** partition_pair, bool no_more_rows) { |
| 327 | DCHECK(row != nullptr || key == ROOT_PARTITION_KEY); |
| 328 | PartitionMap::iterator existing_partition; |
| 329 | existing_partition = partition_keys_to_output_partitions_.find(key); |
| 330 | if (existing_partition == partition_keys_to_output_partitions_.end()) { |
| 331 | // Create a new OutputPartition, and add it to partition_keys_to_output_partitions. |
| 332 | const HdfsPartitionDescriptor* partition_descriptor = GetPartitionDescriptor(key); |
| 333 | std::unique_ptr<OutputPartition> partition(new OutputPartition()); |
| 334 | // Build the unique name for this partition from the partition keys, e.g. "j=1/f=foo/" |
| 335 | // etc. |
| 336 | RETURN_IF_ERROR(ConstructPartitionInfo(row, partition.get())); |
| 337 | Status status = |
| 338 | InitOutputPartition(state, *partition_descriptor, partition.get(), |
| 339 | no_more_rows); |
| 340 | if (!status.ok()) { |
| 341 | // We failed to create the output partition successfully. Clean it up now |
| 342 | // as it is not added to partition_keys_to_output_partitions_ so won't be |
| 343 | // cleaned up in Close(). |
| 344 | if (partition->writer.get() != nullptr) partition->writer->Close(); |
| 345 | return status; |
| 346 | } |
| 347 | |
| 348 | // Indicate that temporary directory is to be deleted after execution. |
| 349 | bool clean_up_staging_dir = |
| 350 | !no_more_rows && !ShouldSkipStaging(state, partition.get()); |
| 351 | |
| 352 | // Save the partition name so that the coordinator can create the partition |
| 353 | // directory structure if needed. |
| 354 | state->dml_exec_state()->AddPartition( |
| 355 | partition->partition_name, partition_descriptor->id(), |
| 356 | &table_desc_->hdfs_base_dir(), |
| 357 | clean_up_staging_dir ? &partition->tmp_hdfs_dir_name : nullptr); |
| 358 | |
| 359 | partition_keys_to_output_partitions_[key].first = std::move(partition); |
| 360 | *partition_pair = &partition_keys_to_output_partitions_[key]; |
| 361 | } else { |
| 362 | // Use existing output_partition partition. |
| 363 | *partition_pair = &existing_partition->second; |
| 364 | } |
| 365 | return Status::OK(); |
| 366 | } |
| 367 | |
| 368 | Status HdfsTableSink::Send(RuntimeState* state, RowBatch* batch) { |
| 369 | SCOPED_TIMER(profile()->total_time_counter()); |
nothing calls this directly
no test coverage detected