2019-08-20 11:17:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <IO/WriteBuffer.h>
|
2020-02-03 10:02:52 +00:00
|
|
|
#include <Columns/IColumn.h>
|
2019-08-20 11:17:57 +00:00
|
|
|
|
|
|
|
#include <cppkafka/cppkafka.h>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2020-02-03 10:02:52 +00:00
|
|
|
class Block;
|
2019-08-20 11:17:57 +00:00
|
|
|
using ProducerPtr = std::shared_ptr<cppkafka::Producer>;
|
|
|
|
|
|
|
|
class WriteBufferToKafkaProducer : public WriteBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WriteBufferToKafkaProducer(
|
|
|
|
ProducerPtr producer_,
|
|
|
|
const std::string & topic_,
|
|
|
|
std::optional<char> delimiter,
|
|
|
|
size_t rows_per_message,
|
|
|
|
size_t chunk_size_,
|
2020-02-03 10:02:52 +00:00
|
|
|
std::chrono::milliseconds poll_timeout,
|
2020-02-04 21:19:34 +00:00
|
|
|
const Block & header);
|
2019-08-20 11:17:57 +00:00
|
|
|
~WriteBufferToKafkaProducer() override;
|
|
|
|
|
2020-03-23 02:12:31 +00:00
|
|
|
void countRow(const Columns & columns, size_t row);
|
2019-08-20 11:17:57 +00:00
|
|
|
void flush();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void nextImpl() override;
|
|
|
|
|
|
|
|
ProducerPtr producer;
|
|
|
|
const std::string topic;
|
|
|
|
const std::optional<char> delim;
|
|
|
|
const size_t max_rows;
|
|
|
|
const size_t chunk_size;
|
|
|
|
const std::chrono::milliseconds timeout;
|
|
|
|
|
|
|
|
size_t rows = 0;
|
|
|
|
std::list<std::string> chunks;
|
2020-02-03 10:02:52 +00:00
|
|
|
std::optional<size_t> key_column_index;
|
|
|
|
std::optional<size_t> timestamp_column_index;
|
2019-08-20 11:17:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|