ClickHouse/src/Storages/Kafka/KafkaBlockOutputStream.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

2020-11-06 14:07:56 +00:00
#include <Storages/Kafka/KafkaBlockOutputStream.h>
#include <Formats/FormatFactory.h>
#include <Storages/Kafka/WriteBufferToKafkaProducer.h>
namespace DB
{
2021-07-23 14:25:35 +00:00
KafkaSink::KafkaSink(
StorageKafka & storage_,
const StorageMetadataPtr & metadata_snapshot_,
const ContextPtr & context_)
2021-07-23 14:25:35 +00:00
: SinkToStorage(metadata_snapshot_->getSampleBlockNonMaterialized())
, storage(storage_)
, metadata_snapshot(metadata_snapshot_)
, context(context_)
{
}
2021-07-23 14:25:35 +00:00
void KafkaSink::onStart()
{
buffer = storage.createWriteBuffer(getHeader());
auto format_settings = getFormatSettings(context);
format_settings.protobuf.allow_multiple_rows_without_delimiter = true;
2020-12-30 03:07:30 +00:00
child = FormatFactory::instance().getOutputStream(storage.getFormatName(), *buffer,
getHeader(), context,
[this](const Columns & columns, size_t row)
{
buffer->countRow(columns, row);
},
format_settings);
}
2021-07-23 14:25:35 +00:00
void KafkaSink::consume(Chunk chunk)
{
child->write(getHeader().cloneWithColumns(chunk.detachColumns()));
}
2021-07-23 14:25:35 +00:00
void KafkaSink::onFinish()
{
2020-08-28 05:26:55 +00:00
if (child)
child->writeSuffix();
2021-07-23 14:25:35 +00:00
//flush();
if (buffer)
buffer->flush();
}
}