blob: 7992636ac112a9b4cfea7b8d35fd659f82489851 (
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include <Storages/Distributed/DistributedAsyncInsertSource.h>
#include <Storages/Distributed/DistributedAsyncInsertHeader.h>
#include <IO/ReadBufferFromFile.h>
#include <Compression/CompressedReadBuffer.h>
#include <Formats/NativeReader.h>
#include <Poco/Logger.h>
namespace DB
{
struct DistributedAsyncInsertSource::Data
{
Poco::Logger * log = nullptr;
ReadBufferFromFile in;
CompressedReadBuffer decompressing_in;
NativeReader block_in;
Block first_block;
explicit Data(const String & file_name)
: log(&Poco::Logger::get("DistributedAsyncInsertSource"))
, in(file_name)
, decompressing_in(in)
, block_in(decompressing_in, DistributedAsyncInsertHeader::read(in, log).revision)
, first_block(block_in.read())
{
}
};
DistributedAsyncInsertSource::DistributedAsyncInsertSource(const String & file_name)
: DistributedAsyncInsertSource(std::make_unique<Data>(file_name))
{
}
DistributedAsyncInsertSource::DistributedAsyncInsertSource(std::unique_ptr<Data> data_)
: ISource(data_->first_block.cloneEmpty())
, data(std::move(data_))
{
}
DistributedAsyncInsertSource::~DistributedAsyncInsertSource() = default;
Chunk DistributedAsyncInsertSource::generate()
{
if (data->first_block)
{
size_t num_rows = data->first_block.rows();
Chunk res(data->first_block.getColumns(), num_rows);
data->first_block.clear();
return res;
}
auto block = data->block_in.read();
if (!block)
return {};
size_t num_rows = block.rows();
return Chunk(block.getColumns(), num_rows);
}
}
|