Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segfault in Avro #33566

Merged
merged 3 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Processors/Formats/Impl/AvroRowOutputFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Avogar marked this conversation as resolved.
Show resolved Hide resolved
file_writer_ptr->syncIfNeeded();
serializer.serializeRow(columns, row_num, file_writer_ptr->encoder());
file_writer_ptr->incr();
Expand Down
2 changes: 2 additions & 0 deletions src/Processors/Formats/Impl/AvroRowOutputFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class AvroRowOutputFormat : public IRowOutputFormat
virtual void writePrefix() override;
virtual void writeSuffix() override;

void createFileWriter();

FormatSettings settings;
AvroSerializer serializer;
std::unique_ptr<avro::DataFileWriterBase> file_writer_ptr;
Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/02168_avro_bug.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
OK
5 changes: 5 additions & 0 deletions tests/queries/0_stateless/02168_avro_bug.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Tags: no-fasttest
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';