Write a record batch to the file
(&mut self, batch: &RecordBatch)
| 1159 | |
| 1160 | /// Write a record batch to the file |
| 1161 | pub fn write(&mut self, batch: &RecordBatch) -> Result<(), ArrowError> { |
| 1162 | if self.finished { |
| 1163 | return Err(ArrowError::IpcError( |
| 1164 | "Cannot write record batch to file writer as it is closed".to_string(), |
| 1165 | )); |
| 1166 | } |
| 1167 | |
| 1168 | let (encoded_dictionaries, encoded_message) = self.data_gen.encode( |
| 1169 | batch, |
| 1170 | &mut self.dictionary_tracker, |
| 1171 | &self.write_options, |
| 1172 | &mut self.compression_context, |
| 1173 | )?; |
| 1174 | |
| 1175 | for encoded_dictionary in encoded_dictionaries { |
| 1176 | let (meta, data) = |
| 1177 | write_message(&mut self.writer, encoded_dictionary, &self.write_options)?; |
| 1178 | |
| 1179 | let block = crate::Block::new(self.block_offsets as i64, meta as i32, data as i64); |
| 1180 | self.dictionary_blocks.push(block); |
| 1181 | self.block_offsets += meta + data; |
| 1182 | } |
| 1183 | |
| 1184 | let (meta, data) = write_message(&mut self.writer, encoded_message, &self.write_options)?; |
| 1185 | |
| 1186 | // add a record block for the footer |
| 1187 | let block = crate::Block::new( |
| 1188 | self.block_offsets as i64, |
| 1189 | meta as i32, // TODO: is this still applicable? |
| 1190 | data as i64, |
| 1191 | ); |
| 1192 | self.record_blocks.push(block); |
| 1193 | self.block_offsets += meta + data; |
| 1194 | Ok(()) |
| 1195 | } |
| 1196 | |
| 1197 | /// Write footer and closing tag, then mark the writer as done |
| 1198 | pub fn finish(&mut self) -> Result<(), ArrowError> { |