From 562435ec39ce0a3ea4eea5bf98c5783f9dd1fd59 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Sun, 26 Jun 2022 15:43:38 +0200 Subject: [PATCH] reuse scratch when reading dictionaries --- src/io/ipc/append/mod.rs | 3 ++- src/io/ipc/read/common.rs | 1 + src/io/ipc/read/reader.rs | 10 +++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/io/ipc/append/mod.rs b/src/io/ipc/append/mod.rs index 4a225c4db61..9e084a45896 100644 --- a/src/io/ipc/append/mod.rs +++ b/src/io/ipc/append/mod.rs @@ -32,7 +32,8 @@ impl FileWriter { )); } - let dictionaries = read::read_file_dictionaries(&mut writer, &metadata)?; + let dictionaries = + read::read_file_dictionaries(&mut writer, &metadata, &mut Default::default())?; let last_block = metadata.blocks.last().ok_or_else(|| { Error::oos("An Arrow IPC file must have at least 1 message (the schema message)") diff --git a/src/io/ipc/read/common.rs b/src/io/ipc/read/common.rs index 04504c0f6d7..dededdb817d 100644 --- a/src/io/ipc/read/common.rs +++ b/src/io/ipc/read/common.rs @@ -306,6 +306,7 @@ impl ReadBuffer { /// method on `Vec` this is `safe` because this function guarantees that /// the underlying data always is initialized. pub fn set_len(&mut self, length: usize) { + dbg!(length, self.data.len(), self.data.capacity()); if length > self.data.capacity() { self.data = vec![0; length]; } else if length > self.data.len() { diff --git a/src/io/ipc/read/reader.rs b/src/io/ipc/read/reader.rs index c40adbdd694..9f7ab43346f 100644 --- a/src/io/ipc/read/reader.rs +++ b/src/io/ipc/read/reader.rs @@ -116,9 +116,9 @@ fn read_dictionary_block( pub fn read_file_dictionaries( reader: &mut R, metadata: &FileMetadata, + scratch: &mut ReadBuffer, ) -> Result { let mut dictionaries = Default::default(); - let mut data = vec![].into(); let blocks = if let Some(blocks) = metadata.dictionaries.as_deref() { blocks @@ -127,7 +127,7 @@ pub fn read_file_dictionaries( }; for block in blocks { - read_dictionary_block(reader, metadata, block, &mut dictionaries, &mut data)?; + read_dictionary_block(reader, metadata, block, &mut dictionaries, scratch)?; } Ok(dictionaries) } @@ -343,7 +343,11 @@ impl FileReader { fn read_dictionaries(&mut self) -> Result<()> { if self.dictionaries.is_none() { - self.dictionaries = Some(read_file_dictionaries(&mut self.reader, &self.metadata)?); + self.dictionaries = Some(read_file_dictionaries( + &mut self.reader, + &self.metadata, + &mut self.buffer, + )?); }; Ok(()) }