| 775 | } |
| 776 | |
| 777 | Status HdfsScanner::DecompressFileToBuffer(uint8_t** buffer, int64_t* bytes_read) { |
| 778 | // For other compressed file: attempt to read and decompress the entire file, point |
| 779 | // to the decompressed buffer, and then continue normal processing. |
| 780 | DCHECK(decompression_type_ != THdfsCompression::SNAPPY); |
| 781 | const HdfsFileDesc* desc = scan_node_->GetFileDesc( |
| 782 | context_->partition_descriptor()->id(), stream_->filename()); |
| 783 | int64_t file_size = desc->file_length; |
| 784 | DCHECK_GT(file_size, 0); |
| 785 | |
| 786 | Status status; |
| 787 | if (!stream_->GetBytes(file_size, buffer, bytes_read, &status)) { |
| 788 | DCHECK(!status.ok()); |
| 789 | return status; |
| 790 | } |
| 791 | |
| 792 | // If didn't read anything, return. |
| 793 | if (*bytes_read == 0) return Status::OK(); |
| 794 | |
| 795 | // Need to read the entire file. |
| 796 | if (file_size > *bytes_read) { |
| 797 | return Status(Substitute("Expected to read a compressed text file of size $0 bytes. " |
| 798 | "But only read $1 bytes. This may indicate data file corruption. (file: $3).", |
| 799 | file_size, *bytes_read, stream_->filename())); |
| 800 | } |
| 801 | |
| 802 | // Decompress and adjust the buffer and bytes_read accordingly. |
| 803 | int64_t decompressed_len = 0; |
| 804 | uint8_t* decompressed_buffer = nullptr; |
| 805 | SCOPED_TIMER(decompress_timer_); |
| 806 | // TODO: Once the writers are in, add tests with very large compressed files (4GB) |
| 807 | // that could overflow. |
| 808 | RETURN_IF_ERROR(decompressor_->ProcessBlock(false, *bytes_read, *buffer, |
| 809 | &decompressed_len, &decompressed_buffer)); |
| 810 | |
| 811 | // Inform 'stream_' that the buffer with the compressed text can be released. |
| 812 | context_->ReleaseCompletedResources(true); |
| 813 | |
| 814 | VLOG_FILE << "Decompressed " << *bytes_read << " to " << decompressed_len; |
| 815 | *buffer = decompressed_buffer; |
| 816 | *bytes_read = decompressed_len; |
| 817 | return Status::OK(); |
| 818 | } |
| 819 | |
| 820 | Status HdfsScanner::DecompressStreamToBuffer(uint8_t** buffer, int64_t* bytes_read, |
| 821 | MemPool* pool, bool* eosr) { |
nothing calls this directly
no test coverage detected