Fix segfault in Avro

This commit is contained in:
avogar 2022-01-12 18:34:28 +03:00
parent a142b7c55e
commit c5ea4b1bc0
4 changed files with 16 additions and 2 deletions

View File

@ -391,20 +391,27 @@ AvroRowOutputFormat::AvroRowOutputFormat(
AvroRowOutputFormat::~AvroRowOutputFormat() = default;
void AvroRowOutputFormat::writePrefix()
void AvroRowOutputFormat::createFileWriter()
{
// we have to recreate avro::DataFileWriterBase object due to its interface limitations
file_writer_ptr = std::make_unique<avro::DataFileWriterBase>(
std::make_unique<OutputStreamWriteBufferAdapter>(out),
serializer.getSchema(),
settings.avro.output_sync_interval,
getCodec(settings.avro.output_codec));
}
void AvroRowOutputFormat::writePrefix()
{
// we have to recreate avro::DataFileWriterBase object due to its interface limitations
createFileWriter();
file_writer_ptr->syncIfNeeded();
}
void AvroRowOutputFormat::write(const Columns & columns, size_t row_num)
{
if (!file_writer_ptr)
createFileWriter();
file_writer_ptr->syncIfNeeded();
serializer.serializeRow(columns, row_num, file_writer_ptr->encoder());
file_writer_ptr->incr();

View File

@ -58,6 +58,8 @@ private:
virtual void writePrefix() override;
virtual void writeSuffix() override;
void createFileWriter();Z
FormatSettings settings;
AvroSerializer serializer;
std::unique_ptr<avro::DataFileWriterBase> file_writer_ptr;

View File

@ -0,0 +1 @@
OK

View File

@ -0,0 +1,4 @@
insert into table function file('data.avro', 'Avro', 'x UInt64') select * from numbers(10);
insert into table function file('data.avro', 'Avro', 'x UInt64') select * from numbers(10);
insert into table function file('data.avro', 'Avro', 'x UInt64') select * from numbers(10);
select 'OK';