Fix getting filename from read buffer wrappers

This commit is contained in:
avogar 2024-01-27 21:13:08 +00:00
parent 75edbdd39c
commit 00c140b7bb
4 changed files with 26 additions and 7 deletions

View File

@ -1,11 +1,12 @@
#pragma once #pragma once
#include <IO/BufferWithOwnMemory.h> #include <IO/BufferWithOwnMemory.h>
#include <IO/ReadBuffer.h> #include <IO/ReadBuffer.h>
#include <IO/ReadBufferWrapperBase.h>
namespace DB namespace DB
{ {
class CompressedReadBufferWrapper : public BufferWithOwnMemory<ReadBuffer> class CompressedReadBufferWrapper : public BufferWithOwnMemory<ReadBuffer>, public ReadBufferWrapperBase
{ {
public: public:
CompressedReadBufferWrapper( CompressedReadBufferWrapper(
@ -16,7 +17,7 @@ public:
: BufferWithOwnMemory<ReadBuffer>(buf_size, existing_memory, alignment) : BufferWithOwnMemory<ReadBuffer>(buf_size, existing_memory, alignment)
, in(std::move(in_)) {} , in(std::move(in_)) {}
const ReadBuffer & getWrappedReadBuffer() const { return *in; } const ReadBuffer & getWrappedReadBuffer() const override { return *in; }
ReadBuffer & getWrappedReadBuffer() { return *in; } ReadBuffer & getWrappedReadBuffer() { return *in; }
void prefetch(Priority priority) override { in->prefetch(priority); } void prefetch(Priority priority) override { in->prefetch(priority); }

View File

@ -1,4 +1,5 @@
#include <IO/ReadBuffer.h> #include <IO/ReadBuffer.h>
#include <IO/ReadBufferWrapperBase.h>
namespace DB namespace DB
@ -7,7 +8,7 @@ namespace DB
namespace namespace
{ {
template <typename CustomData> template <typename CustomData>
class ReadBufferWrapper : public ReadBuffer class ReadBufferWrapper : public ReadBuffer, public ReadBufferWrapperBase
{ {
public: public:
ReadBufferWrapper(ReadBuffer & in_, CustomData && custom_data_) ReadBufferWrapper(ReadBuffer & in_, CustomData && custom_data_)
@ -15,6 +16,8 @@ namespace
{ {
} }
const ReadBuffer & getWrappedReadBuffer() const override { return in; }
private: private:
ReadBuffer & in; ReadBuffer & in;
CustomData custom_data; CustomData custom_data;

View File

@ -0,0 +1,15 @@
#pragma once
#include <IO/ReadBuffer.h>
namespace DB
{
class ReadBufferWrapperBase
{
public:
virtual const ReadBuffer & getWrappedReadBuffer() const = 0;
virtual ~ReadBufferWrapperBase() = default;
};
}

View File

@ -1,5 +1,5 @@
#include <IO/WithFileName.h> #include <IO/WithFileName.h>
#include <IO/CompressedReadBufferWrapper.h> #include <IO/ReadBufferWrapperBase.h>
#include <IO/ParallelReadBuffer.h> #include <IO/ParallelReadBuffer.h>
#include <IO/PeekableReadBuffer.h> #include <IO/PeekableReadBuffer.h>
@ -16,10 +16,10 @@ static String getFileName(const T & entry)
String getFileNameFromReadBuffer(const ReadBuffer & in) String getFileNameFromReadBuffer(const ReadBuffer & in)
{ {
if (const auto * compressed = dynamic_cast<const CompressedReadBufferWrapper *>(&in)) if (const auto * wrapper = dynamic_cast<const ReadBufferWrapperBase *>(&in))
return getFileName(compressed->getWrappedReadBuffer()); return getFileNameFromReadBuffer(wrapper->getWrappedReadBuffer());
else if (const auto * parallel = dynamic_cast<const ParallelReadBuffer *>(&in)) else if (const auto * parallel = dynamic_cast<const ParallelReadBuffer *>(&in))
return getFileName(parallel->getReadBuffer()); return getFileNameFromReadBuffer(parallel->getReadBuffer());
else if (const auto * peekable = dynamic_cast<const PeekableReadBuffer *>(&in)) else if (const auto * peekable = dynamic_cast<const PeekableReadBuffer *>(&in))
return getFileNameFromReadBuffer(peekable->getSubBuffer()); return getFileNameFromReadBuffer(peekable->getSubBuffer());
else else