#include #include #include #include #include #include #include namespace DB { using Checksum = CityHash_v1_0_2::uint128; CompressionCodecPtr getCompressionCodecForFile(const DiskPtr & disk, const String & relative_path) { auto read_buffer = disk->readFile(relative_path); read_buffer->ignore(sizeof(Checksum)); UInt8 header_size = ICompressionCodec::getHeaderSize(); PODArray compressed_buffer; compressed_buffer.resize(header_size); read_buffer->readStrict(compressed_buffer.data(), header_size); uint8_t method = ICompressionCodec::readMethod(compressed_buffer.data()); if (method == static_cast(CompressionMethodByte::Multiple)) { compressed_buffer.resize(1); read_buffer->readStrict(compressed_buffer.data(), 1); compressed_buffer.resize(1 + compressed_buffer[0]); read_buffer->readStrict(compressed_buffer.data() + 1, compressed_buffer[0]); auto codecs_bytes = CompressionCodecMultiple::getCodecsBytesFromData(compressed_buffer.data()); Codecs codecs; for (auto byte : codecs_bytes) codecs.push_back(CompressionCodecFactory::instance().get(byte)); return std::make_shared(codecs); } return CompressionCodecFactory::instance().get(method); } }