2020-11-06 14:07:56 +00:00
|
|
|
#include <Storages/Kafka/KafkaBlockOutputStream.h>
|
2019-08-20 11:17:57 +00:00
|
|
|
|
|
|
|
#include <Formats/FormatFactory.h>
|
2019-10-22 10:31:28 +00:00
|
|
|
#include <Storages/Kafka/WriteBufferToKafkaProducer.h>
|
2019-08-20 11:17:57 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-06-16 12:48:10 +00:00
|
|
|
KafkaBlockOutputStream::KafkaBlockOutputStream(
|
|
|
|
StorageKafka & storage_,
|
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
|
|
|
const std::shared_ptr<Context> & context_)
|
|
|
|
: storage(storage_)
|
|
|
|
, metadata_snapshot(metadata_snapshot_)
|
|
|
|
, context(context_)
|
2019-08-20 11:17:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Block KafkaBlockOutputStream::getHeader() const
|
|
|
|
{
|
2020-06-16 12:48:10 +00:00
|
|
|
return metadata_snapshot->getSampleBlockNonMaterialized();
|
2019-08-20 11:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KafkaBlockOutputStream::writePrefix()
|
|
|
|
{
|
2020-02-03 10:02:52 +00:00
|
|
|
buffer = storage.createWriteBuffer(getHeader());
|
2019-08-20 11:17:57 +00:00
|
|
|
|
2020-11-02 07:50:38 +00:00
|
|
|
auto format_settings = getFormatSettings(*context);
|
|
|
|
format_settings.protobuf.allow_many_rows_no_delimiters = true;
|
|
|
|
|
2020-12-30 03:07:30 +00:00
|
|
|
child = FormatFactory::instance().getOutputStream(storage.getFormatName(), *buffer,
|
2020-11-02 07:50:38 +00:00
|
|
|
getHeader(), *context,
|
|
|
|
[this](const Columns & columns, size_t row)
|
|
|
|
{
|
|
|
|
buffer->countRow(columns, row);
|
|
|
|
},
|
|
|
|
format_settings);
|
2019-08-20 11:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KafkaBlockOutputStream::write(const Block & block)
|
|
|
|
{
|
|
|
|
child->write(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KafkaBlockOutputStream::writeSuffix()
|
|
|
|
{
|
2020-08-28 05:26:55 +00:00
|
|
|
if (child)
|
|
|
|
child->writeSuffix();
|
2019-08-20 11:17:57 +00:00
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KafkaBlockOutputStream::flush()
|
|
|
|
{
|
|
|
|
if (buffer)
|
|
|
|
buffer->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|