1#pragma once
2
3#include <Core/Block.h>
4#include <DataStreams/IBlockInputStream.h>
5#include <Core/ExternalResultDescription.h>
6
7
8namespace Poco
9{
10namespace MongoDB
11{
12 class Connection;
13 class Cursor;
14}
15}
16
17
18namespace DB
19{
20/// Converts MongoDB Cursor to a stream of Blocks
21class MongoDBBlockInputStream final : public IBlockInputStream
22{
23public:
24 MongoDBBlockInputStream(
25 std::shared_ptr<Poco::MongoDB::Connection> & connection_,
26 std::unique_ptr<Poco::MongoDB::Cursor> cursor_,
27 const Block & sample_block,
28 const UInt64 max_block_size_);
29
30 ~MongoDBBlockInputStream() override;
31
32 String getName() const override { return "MongoDB"; }
33
34 Block getHeader() const override { return description.sample_block.cloneEmpty(); }
35
36private:
37 Block readImpl() override;
38
39 std::shared_ptr<Poco::MongoDB::Connection> connection;
40 std::unique_ptr<Poco::MongoDB::Cursor> cursor;
41 const UInt64 max_block_size;
42 ExternalResultDescription description;
43 bool all_read = false;
44};
45
46}
47