| 276 | } |
| 277 | |
| 278 | Status TableSinkBase::CreateNewTmpFile(RuntimeState* state, |
| 279 | OutputPartition* output_partition) { |
| 280 | SCOPED_TIMER(ADD_TIMER(profile(), "TmpFileCreateTimer")); |
| 281 | string file_name_pattern = |
| 282 | output_partition->writer->file_extension().empty() ? "$0.$1" : "$0.$1.$2"; |
| 283 | string final_location = Substitute(file_name_pattern, |
| 284 | output_partition->final_hdfs_file_name_prefix, output_partition->num_files, |
| 285 | output_partition->writer->file_extension()); |
| 286 | |
| 287 | // If ShouldSkipStaging() is true, then the table sink will write the file(s) for this |
| 288 | // partition to the final location directly. If it is false, the file(s) will be written |
| 289 | // to a temporary staging location which will be moved by the coordinator to the final |
| 290 | // location. |
| 291 | if (ShouldSkipStaging(state, output_partition)) { |
| 292 | output_partition->current_file_name = final_location; |
| 293 | output_partition->current_file_final_name = ""; |
| 294 | } else { |
| 295 | output_partition->current_file_name = Substitute(file_name_pattern, |
| 296 | output_partition->tmp_hdfs_file_name_prefix, output_partition->num_files, |
| 297 | output_partition->writer->file_extension()); |
| 298 | // Save the ultimate destination for this file (it will be moved by the coordinator). |
| 299 | output_partition->current_file_final_name = final_location; |
| 300 | } |
| 301 | // Check if tmp_hdfs_file_name exists. |
| 302 | const char* tmp_hdfs_file_name_cstr = |
| 303 | output_partition->current_file_name.c_str(); |
| 304 | |
| 305 | if (hdfsExists(output_partition->hdfs_connection, tmp_hdfs_file_name_cstr) == 0) { |
| 306 | return Status(GetHdfsErrorMsg("Temporary HDFS file already exists: ", |
| 307 | output_partition->current_file_name)); |
| 308 | } |
| 309 | |
| 310 | // This is the block size from the HDFS partition metadata. |
| 311 | uint64_t block_size = output_partition->partition_descriptor->block_size(); |
| 312 | // hdfsOpenFile takes a 4 byte integer as the block size. |
| 313 | if (block_size > numeric_limits<int32_t>::max()) { |
| 314 | return Status(Substitute("HDFS block size must be smaller than 2GB but is configured " |
| 315 | "in the HDFS partition to $0.", block_size)); |
| 316 | } |
| 317 | |
| 318 | if (block_size == 0) block_size = output_partition->writer->default_block_size(); |
| 319 | if (block_size > numeric_limits<int32_t>::max()) { |
| 320 | return Status(Substitute("HDFS block size must be smaller than 2GB but the target " |
| 321 | "table requires $0.", block_size)); |
| 322 | } |
| 323 | |
| 324 | DCHECK_LE(block_size, numeric_limits<int32_t>::max()); |
| 325 | output_partition->tmp_hdfs_file = hdfsOpenFile(output_partition->hdfs_connection, |
| 326 | tmp_hdfs_file_name_cstr, O_WRONLY, 0, 0, block_size); |
| 327 | |
| 328 | VLOG_FILE << "hdfsOpenFile() file=" << tmp_hdfs_file_name_cstr; |
| 329 | if (output_partition->tmp_hdfs_file == nullptr) { |
| 330 | return Status(GetHdfsErrorMsg("Failed to open HDFS file for writing: ", |
| 331 | output_partition->current_file_name)); |
| 332 | } |
| 333 | |
| 334 | if (IsS3APath(tmp_hdfs_file_name_cstr) || |
| 335 | IsABFSPath(tmp_hdfs_file_name_cstr) || |
nothing calls this directly
no test coverage detected