2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBufferFromFileBase.h>
|
2023-04-06 17:00:51 +00:00
|
|
|
#include <IO/Progress.h>
|
2022-12-11 03:26:07 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2015-04-03 13:45:44 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-05-25 14:49:40 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2022-06-20 14:16:17 +00:00
|
|
|
extern const int UNKNOWN_FILE_SIZE;
|
2022-05-25 14:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 16:17:25 +00:00
|
|
|
ReadBufferFromFileBase::ReadBufferFromFileBase() : BufferWithOwnMemory<SeekableReadBuffer>(0)
|
2020-01-04 05:46:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-01-03 16:05:46 +00:00
|
|
|
ReadBufferFromFileBase::ReadBufferFromFileBase(
|
|
|
|
size_t buf_size,
|
|
|
|
char * existing_memory,
|
|
|
|
size_t alignment,
|
|
|
|
std::optional<size_t> file_size_)
|
2020-01-22 16:17:25 +00:00
|
|
|
: BufferWithOwnMemory<SeekableReadBuffer>(buf_size, existing_memory, alignment)
|
2022-01-03 16:05:46 +00:00
|
|
|
, file_size(file_size_)
|
2015-04-03 13:45:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-08 21:18:53 +00:00
|
|
|
ReadBufferFromFileBase::~ReadBufferFromFileBase() = default;
|
2015-04-03 13:45:44 +00:00
|
|
|
|
2022-05-25 14:49:40 +00:00
|
|
|
size_t ReadBufferFromFileBase::getFileSize()
|
|
|
|
{
|
|
|
|
if (file_size)
|
|
|
|
return *file_size;
|
2022-06-20 14:16:17 +00:00
|
|
|
throw Exception(ErrorCodes::UNKNOWN_FILE_SIZE, "Cannot find out file size for read buffer");
|
2022-05-25 14:49:40 +00:00
|
|
|
}
|
|
|
|
|
2022-12-11 03:26:07 +00:00
|
|
|
void ReadBufferFromFileBase::setProgressCallback(ContextPtr context)
|
|
|
|
{
|
|
|
|
auto file_progress_callback = context->getFileProgressCallback();
|
|
|
|
|
|
|
|
if (!file_progress_callback)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setProfileCallback([file_progress_callback](const ProfileInfo & progress)
|
|
|
|
{
|
2023-06-22 17:24:43 +00:00
|
|
|
file_progress_callback(FileProgress(progress.bytes_read));
|
2022-12-11 03:26:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-03 13:45:44 +00:00
|
|
|
}
|