blob: 2383182f7e770ecc0962bc3b6d3188388fc463c9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include <IO/WithFileName.h>
#include <IO/CompressedReadBufferWrapper.h>
#include <IO/ParallelReadBuffer.h>
#include <IO/PeekableReadBuffer.h>
namespace DB
{
template <typename T>
static String getFileName(const T & entry)
{
if (const auto * with_file_name = dynamic_cast<const WithFileName *>(&entry))
return with_file_name->getFileName();
return "";
}
String getFileNameFromReadBuffer(const ReadBuffer & in)
{
if (const auto * compressed = dynamic_cast<const CompressedReadBufferWrapper *>(&in))
return getFileName(compressed->getWrappedReadBuffer());
else if (const auto * parallel = dynamic_cast<const ParallelReadBuffer *>(&in))
return getFileName(parallel->getReadBuffer());
else if (const auto * peekable = dynamic_cast<const PeekableReadBuffer *>(&in))
return getFileNameFromReadBuffer(peekable->getSubBuffer());
else
return getFileName(in);
}
String getExceptionEntryWithFileName(const ReadBuffer & in)
{
auto filename = getFileNameFromReadBuffer(in);
if (filename.empty())
return "";
return fmt::format(": While reading from: {}", filename);
}
}
|