Skip to content

Commit

Permalink
PARQUET-620: Ensure metadata is written only once
Browse files Browse the repository at this point in the history
Author: Uwe L. Korn <uwelk@xhochy.com>

Closes apache#108 from xhochy/parquet-620 and squashes the following commits:

da122ad [Uwe L. Korn] Ensure metadata is written only once

Change-Id: I7653597fdf69c961545d6c978fdc1367267adee7
  • Loading branch information
xhochy authored and wesm committed May 18, 2016
1 parent 3ff3b58 commit e1e0d28
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cpp/src/parquet/file/writer-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ std::unique_ptr<ParquetFileWriter::Contents> FileSerializer::Open(
}

void FileSerializer::Close() {
if (row_group_writer_) { row_group_writer_->Close(); }
row_group_writer_.reset();
if (is_open_) {
if (row_group_writer_) { row_group_writer_->Close(); }
row_group_writer_.reset();

// Write magic bytes and metadata
WriteMetaData();
// Write magic bytes and metadata
WriteMetaData();

sink_->Close();
sink_->Close();
is_open_ = false;
}
}

int FileSerializer::num_columns() const {
Expand Down Expand Up @@ -238,7 +241,11 @@ void FileSerializer::WriteMetaData() {

FileSerializer::FileSerializer(std::shared_ptr<OutputStream> sink,
std::shared_ptr<GroupNode>& schema, MemoryAllocator* allocator = default_allocator())
: sink_(sink), allocator_(allocator), num_row_groups_(0), num_rows_(0) {
: sink_(sink),
allocator_(allocator),
num_row_groups_(0),
num_rows_(0),
is_open_(true) {
schema_.Init(schema);
StartFile();
}
Expand Down
1 change: 1 addition & 0 deletions cpp/src/parquet/file/writer-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class FileSerializer : public ParquetFileWriter::Contents {
MemoryAllocator* allocator_;
int num_row_groups_;
int num_rows_;
bool is_open_;
std::unique_ptr<RowGroupWriter> row_group_writer_;

void StartFile();
Expand Down

0 comments on commit e1e0d28

Please sign in to comment.