Skip to content

Commit

Permalink
made end not consume FileWriter (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Apr 15, 2022
1 parent efc2a91 commit dd5e4e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
18 changes: 11 additions & 7 deletions src/write/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ impl<W: Write> FileWriter<W> {
Ok(())
}

/// Writes the footer of the parquet file. Returns the total size of the file and the
/// underlying writer.
pub fn end(mut self, key_value_metadata: Option<Vec<KeyValue>>) -> Result<(u64, W)> {
/// Writes the footer of the parquet file. Returns the total size of the file.
pub fn end(&mut self, key_value_metadata: Option<Vec<KeyValue>>) -> Result<u64> {
// compute file stats
let num_rows = self.row_groups.iter().map(|group| group.num_rows).sum();

Expand Down Expand Up @@ -166,18 +165,23 @@ impl<W: Write> FileWriter<W> {

let metadata = FileMetaData::new(
self.options.version.into(),
self.schema.into_thrift(),
self.schema.clone().into_thrift(),
num_rows,
self.row_groups,
self.row_groups.clone(),
key_value_metadata,
self.created_by,
self.created_by.clone(),
None,
None,
None,
);

let len = end_file(&mut self.writer, metadata)?;
Ok((self.offset + len, self.writer))
Ok(self.offset + len)
}

/// Returns the underlying writer.
pub fn into_inner(self) -> W {
self.writer
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/it/write/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ fn write_file() -> Result<Vec<u8>> {

writer.start()?;
writer.write(DynIter::new(columns))?;
let writer = writer.end(None)?.1;
writer.end(None)?;

Ok(writer.into_inner())
Ok(writer.into_inner().into_inner())
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions tests/it/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ fn test_column(column: &str, compression: Compression) -> Result<()> {

writer.start()?;
writer.write(DynIter::new(columns))?;
let writer = writer.end(None)?.1;
writer.end(None)?;

let data = writer.into_inner();
let data = writer.into_inner().into_inner();

let (result, statistics) = read_column(&mut Cursor::new(data))?;
assert_eq!(array, result);
Expand Down Expand Up @@ -213,9 +213,9 @@ fn basic() -> Result<()> {

writer.start()?;
writer.write(DynIter::new(columns))?;
let writer = writer.end(None)?.1;
writer.end(None)?;

let data = writer.into_inner();
let data = writer.into_inner().into_inner();
let mut reader = Cursor::new(data);

let metadata = read_metadata(&mut reader)?;
Expand Down

0 comments on commit dd5e4e2

Please sign in to comment.