#include "WithFileSize.h" #include #include #include #include namespace DB { namespace ErrorCodes { extern const int UNKNOWN_FILE_SIZE; } template static size_t getFileSize(T & in) { if (auto * with_file_size = dynamic_cast(&in)) { return with_file_size->getFileSize(); } throw Exception(ErrorCodes::UNKNOWN_FILE_SIZE, "Cannot find out file size"); } size_t getFileSizeFromReadBuffer(ReadBuffer & in) { if (auto * delegate = dynamic_cast(&in)) { return getFileSize(delegate->getWrappedReadBuffer()); } else if (auto * compressed = dynamic_cast(&in)) { return getFileSize(compressed->getWrappedReadBuffer()); } else if (auto * parallel = dynamic_cast(&in)) { return getFileSize(parallel->getReadBufferFactory()); } return getFileSize(in); } bool isBufferWithFileSize(const ReadBuffer & in) { if (const auto * delegate = dynamic_cast(&in)) { return delegate->isWithFileSize(); } else if (const auto * compressed = dynamic_cast(&in)) { return isBufferWithFileSize(compressed->getWrappedReadBuffer()); } else if (const auto * parallel = dynamic_cast(&in)) { return dynamic_cast(¶llel->getReadBufferFactory()) != nullptr; } return dynamic_cast(&in) != nullptr; } }