message: Parquet: refactor ColumnReader::PreparePage
  preparation to merge compression code with PreparePageV2
diff: @@ -232,43 +232,42 @@ void ColumnReader::PreparePageV2(PageHeader &page_hdr) {
  void ColumnReader::PreparePage(PageHeader &page_hdr) {
  auto &trans = (ThriftFileTransport &)*protocol->getTransport();
  - block = make_shared<ResizeableBuffer>(reader.allocator, page_hdr.compressed_page_size + 1);
  + auto compressed_block = make_shared<ResizeableBuffer>(reader.allocator, page_hdr.compressed_page_size + 1);
  trans.read((uint8_t *)block->ptr, page_hdr.compressed_page_size);
  - // TODO this allocation should probably be avoided
  - shared_ptr<ResizeableBuffer> unpacked_block;
  - if (chunk->meta_data.codec != CompressionCodec::UNCOMPRESSED) {
  - unpacked_block = make_shared<ResizeableBuffer>(reader.allocator, page_hdr.uncompressed_page_size + 1);
  + if (chunk->meta_data.codec == CompressionCodec::UNCOMPRESSED) {
  + move(block, compressed_block);
  + return;
  }
  + block = make_shared<ResizeableBuffer>(reader.allocator, page_hdr.uncompressed_page_size + 1);
  +
  switch (chunk->meta_data.codec) {
  case CompressionCodec::UNCOMPRESSED:
  + D_ASSERT(false);
  break;
  case CompressionCodec::GZIP: {
  MiniZStream s;
  - s.Decompress((const char *)block->ptr, page_hdr.compressed_page_size, (char *)unpacked_block->ptr,
  + s.Decompress((const char *)compressed_block->ptr, page_hdr.compressed_page_size, (char *)block->ptr,
  page_hdr.uncompressed_page_size);
  - block = move(unpacked_block);
  break;
  }
  case CompressionCodec::SNAPPY: {
  - auto res = duckdb_snappy::RawUncompress((const char *)block->ptr, page_hdr.compressed_page_size,
  - (char *)unpacked_block->ptr);
  + auto res = duckdb_snappy::RawUncompress((const char *)compressed_block->ptr, page_hdr.compressed_page_size,
  + (char *)block->ptr);
  if (!res) {
  throw std::runtime_error("Decompression failure");
  }
  - block = move(unpacked_block);
  break;
  }
  case CompressionCodec::ZSTD: {
  - auto res = duckdb_zstd::ZSTD_decompress((char *)unpacked_block->ptr, page_hdr.uncompressed_page_size,
  - (const char *)block->ptr, page_hdr.compressed_page_size);
  + auto res = duckdb_zstd::ZSTD_decompress((char *)block->ptr, page_hdr.uncompressed_page_size,
  + (const char *)compressed_block->ptr, page_hdr.compressed_page_size);
  if (duckdb_zstd::ZSTD_isError(res) || res != (size_t)page_hdr.uncompressed_page_size) {
  throw std::runtime_error("ZSTD Decompression failure");
  }
  - block = move(unpacked_block);
  break;
  }
  