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
9namespace DB
10{
11
12class IColumn;
13class IDataType;
14class WriteBuffer;
15class Context;
16
17/** A stream for outputting data in a binary line-by-line format.
18 */
19class MySQLOutputFormat final : public IOutputFormat
20{
21public:
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
40private:
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