From 14aa90db3146ffaca62aa323b3f3d83844d458d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Thu, 3 Feb 2022 03:41:57 +0100 Subject: [PATCH] Fix empty container creation (#173) Co-authored-by: Francois --- v10/container/writer.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/v10/container/writer.go b/v10/container/writer.go index d5f6a972..22d81879 100644 --- a/v10/container/writer.go +++ b/v10/container/writer.go @@ -120,6 +120,15 @@ func (avroWriter *Writer) WriteRecord(record AvroRecord) error { // Write the current block to the file if it has been filled. It is // best-practise to always call this before the underlying io.Writer is closed. func (avroWriter *Writer) Flush() error { + // Lazily write the header if it hasn't been written yet + if !avroWriter.wroteHeader { + err := avroWriter.writeHeader(avroWriter.schema) + if err != nil { + return err + } + avroWriter.wroteHeader = true + } + if avroWriter.nextBlockRecords == 0 { return nil }