You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ne...@apache.org on 2021/02/24 13:34:01 UTC
[arrow] branch master updated: ARROW-11718: [Rust] Don't write IPC
footers on drop
This is an automated email from the ASF dual-hosted git repository.
nevime pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 4b0375b ARROW-11718: [Rust] Don't write IPC footers on drop
4b0375b is described below
commit 4b0375b295e6e1863c77d84d9244b09d93cc7cd5
Author: Steven Fackler <sf...@gmail.com>
AuthorDate: Wed Feb 24 15:32:43 2021 +0200
ARROW-11718: [Rust] Don't write IPC footers on drop
As discussed in #9520, these destructors shouldn't be there at all.
Closes #9536 from sfackler/no-ipc-drop
Authored-by: Steven Fackler <sf...@gmail.com>
Signed-off-by: Neville Dipale <ne...@gmail.com>
---
rust/arrow/src/ipc/writer.rs | 34 +++++++++-------------
.../src/bin/arrow-json-integration-test.rs | 2 ++
2 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/rust/arrow/src/ipc/writer.rs b/rust/arrow/src/ipc/writer.rs
index 7f06fa1..c6b2894 100644
--- a/rust/arrow/src/ipc/writer.rs
+++ b/rust/arrow/src/ipc/writer.rs
@@ -434,6 +434,12 @@ impl<W: Write> FileWriter<W> {
/// Write footer and closing tag, then mark the writer as done
pub fn finish(&mut self) -> Result<()> {
+ if self.finished {
+ return Err(ArrowError::IoError(
+ "Cannot write footer to file writer as it is closed".to_string(),
+ ));
+ }
+
// write EOS
write_continuation(&mut self.writer, &self.write_options, 0)?;
@@ -463,15 +469,6 @@ impl<W: Write> FileWriter<W> {
}
}
-/// Finish the file if it is not 'finished' when it goes out of scope
-impl<W: Write> Drop for FileWriter<W> {
- fn drop(&mut self) {
- if !self.finished {
- let _ = self.finish();
- }
- }
-}
-
pub struct StreamWriter<W: Write> {
/// The object to write to
writer: BufWriter<W>,
@@ -537,6 +534,12 @@ impl<W: Write> StreamWriter<W> {
/// Write continuation bytes, and mark the stream as done
pub fn finish(&mut self) -> Result<()> {
+ if self.finished {
+ return Err(ArrowError::IoError(
+ "Cannot write footer to stream writer as it is closed".to_string(),
+ ));
+ }
+
write_continuation(&mut self.writer, &self.write_options, 0)?;
self.finished = true;
@@ -545,15 +548,6 @@ impl<W: Write> StreamWriter<W> {
}
}
-/// Finish the stream if it is not 'finished' when it goes out of scope
-impl<W: Write> Drop for StreamWriter<W> {
- fn drop(&mut self) {
- if !self.finished {
- let _ = self.finish();
- }
- }
-}
-
/// Stores the encoded data, which is an ipc::Message, and optional Arrow data
pub struct EncodedData {
/// An encoded ipc::Message
@@ -776,7 +770,7 @@ mod tests {
let mut writer = FileWriter::try_new(file, &schema).unwrap();
writer.write(&batch).unwrap();
- // this is inside a block to test the implicit finishing of the file on `Drop`
+ writer.finish().unwrap();
}
{
@@ -826,7 +820,7 @@ mod tests {
FileWriter::try_new_with_options(file, &schema, options).unwrap();
writer.write(&batch).unwrap();
- // this is inside a block to test the implicit finishing of the file on `Drop`
+ writer.finish().unwrap();
}
{
diff --git a/rust/integration-testing/src/bin/arrow-json-integration-test.rs b/rust/integration-testing/src/bin/arrow-json-integration-test.rs
index 52517bc..2578020 100644
--- a/rust/integration-testing/src/bin/arrow-json-integration-test.rs
+++ b/rust/integration-testing/src/bin/arrow-json-integration-test.rs
@@ -78,6 +78,8 @@ fn json_to_arrow(json_name: &str, arrow_name: &str, verbose: bool) -> Result<()>
writer.write(&b)?;
}
+ writer.finish()?;
+
Ok(())
}