| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Processors/Formats/IRowOutputFormat.h> |
| 4 | #include <Core/Block.h> |
| 5 | |
| 6 | #include <Core/MySQLProtocol.h> |
| 7 | #include <Formats/FormatSettings.h> |
| 8 | |
| 9 | namespace DB |
| 10 | { |
| 11 | |
| 12 | class IColumn; |
| 13 | class IDataType; |
| 14 | class WriteBuffer; |
| 15 | class Context; |
| 16 | |
| 17 | /** A stream for outputting data in a binary line-by-line format. |
| 18 | */ |
| 19 | class MySQLOutputFormat final : public IOutputFormat |
| 20 | { |
| 21 | public: |
| 22 | MySQLOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & settings_); |
| 23 | |
| 24 | String getName() const override { return "MySQLOutputFormat"; } |
| 25 | |
| 26 | void setContext(const Context & context_) |
| 27 | { |
| 28 | context = &context_; |
| 29 | packet_sender = std::make_unique<MySQLProtocol::PacketSender>(out, const_cast<uint8_t &>(context_.mysql.sequence_id)); /// TODO: fix it |
| 30 | packet_sender->max_packet_size = context_.mysql.max_packet_size; |
| 31 | } |
| 32 | |
| 33 | void consume(Chunk) override; |
| 34 | void finalize() override; |
| 35 | void flush() override; |
| 36 | void doWritePrefix() override { initialize(); } |
| 37 | |
| 38 | void initialize(); |
| 39 | |
| 40 | private: |
| 41 | |
| 42 | bool initialized = false; |
| 43 | |
| 44 | const Context * context = nullptr; |
| 45 | std::unique_ptr<MySQLProtocol::PacketSender> packet_sender; |
| 46 | FormatSettings format_settings; |
| 47 | DataTypes data_types; |
| 48 | }; |
| 49 | |
| 50 | } |
| 51 |