mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 12:22:12 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
50 lines
1.1 KiB
C++
50 lines
1.1 KiB
C++
#include "KafkaBlockOutputStream.h"
|
|
|
|
#include <Formats/FormatFactory.h>
|
|
#include <Storages/Kafka/WriteBufferToKafkaProducer.h>
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int CANNOT_CREATE_IO_BUFFER;
|
|
}
|
|
|
|
KafkaBlockOutputStream::KafkaBlockOutputStream(StorageKafka & storage_, const Context & context_) : storage(storage_), context(context_)
|
|
{
|
|
}
|
|
|
|
Block KafkaBlockOutputStream::getHeader() const
|
|
{
|
|
return storage.getSampleBlockNonMaterialized();
|
|
}
|
|
|
|
void KafkaBlockOutputStream::writePrefix()
|
|
{
|
|
buffer = storage.createWriteBuffer(getHeader());
|
|
if (!buffer)
|
|
throw Exception("Failed to create Kafka producer!", ErrorCodes::CANNOT_CREATE_IO_BUFFER);
|
|
|
|
child = FormatFactory::instance().getOutput(storage.getFormatName(), *buffer, getHeader(), context, [this](const Columns & columns, size_t row){ buffer->countRow(columns, row); });
|
|
}
|
|
|
|
void KafkaBlockOutputStream::write(const Block & block)
|
|
{
|
|
child->write(block);
|
|
}
|
|
|
|
void KafkaBlockOutputStream::writeSuffix()
|
|
{
|
|
child->writeSuffix();
|
|
flush();
|
|
}
|
|
|
|
void KafkaBlockOutputStream::flush()
|
|
{
|
|
if (buffer)
|
|
buffer->flush();
|
|
}
|
|
|
|
}
|