Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Made IPC writer take owned schema (#1361)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 18, 2023
1 parent 218b7cf commit 70571d6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion benches/write_ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn write(array: &dyn Array) -> Result<()> {
let columns = Chunk::try_new(vec![clone(array)])?;

let writer = Cursor::new(vec![]);
let mut writer = FileWriter::try_new(writer, &schema, None, Default::default())?;
let mut writer = FileWriter::try_new(writer, schema, None, Default::default())?;

writer.write(&columns, None)
}
Expand Down
8 changes: 6 additions & 2 deletions examples/ipc_file_mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ fn write(
) -> Result<Vec<u8>, Error> {
let result = vec![];
let options = arrow2::io::ipc::write::WriteOptions { compression };
let mut writer =
arrow2::io::ipc::write::FileWriter::try_new(result, schema, ipc_fields.clone(), options)?;
let mut writer = arrow2::io::ipc::write::FileWriter::try_new(
result,
schema.clone(),
ipc_fields.clone(),
options,
)?;
for chunk in chunks {
writer.write(chunk, ipc_fields.as_ref().map(|x| x.as_ref()))?;
}
Expand Down
2 changes: 1 addition & 1 deletion integration-testing/src/bin/arrow-json-integration-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn json_to_arrow(json_name: &str, arrow_name: &str, verbose: bool) -> Result<()>
let options = write::WriteOptions { compression: None };
let mut writer = write::FileWriter::try_new(
arrow_file,
&json_file.schema,
json_file.schema.clone(),
Some(json_file.fields),
options,
)?;
Expand Down
2 changes: 1 addition & 1 deletion integration-testing/src/bin/arrow-stream-to-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() -> Result<()> {
let options = write::WriteOptions { compression: None };
let mut writer = write::FileWriter::try_new(
writer,
&metadata.schema,
metadata.schema.clone(),
Some(metadata.ipc_schema.fields),
options,
)?;
Expand Down
2 changes: 1 addition & 1 deletion src/io/ipc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
//! let y_coord = Field::new("y", DataType::Int32, false);
//! let schema = Schema::from(vec![x_coord, y_coord]);
//! let options = WriteOptions {compression: None};
//! let mut writer = FileWriter::try_new(file, &schema, None, options)?;
//! let mut writer = FileWriter::try_new(file, schema, None, options)?;
//!
//! // Setup the data
//! let x_data = Int32Array::from_slice([-1i32, 1]);
Expand Down
4 changes: 2 additions & 2 deletions src/io/ipc/write/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ impl<W: Write> FileWriter<W> {
/// Creates a new [`FileWriter`] and writes the header to `writer`
pub fn try_new(
writer: W,
schema: &Schema,
schema: Schema,
ipc_fields: Option<Vec<IpcField>>,
options: WriteOptions,
) -> Result<Self> {
let mut slf = Self::new(writer, schema.clone(), ipc_fields, options);
let mut slf = Self::new(writer, schema, ipc_fields, options);
slf.start()?;

Ok(slf)
Expand Down
2 changes: 1 addition & 1 deletion tests/it/io/ipc/write/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn write(
) -> Result<Vec<u8>> {
let result = vec![];
let options = WriteOptions { compression };
let mut writer = FileWriter::try_new(result, schema, ipc_fields.clone(), options)?;
let mut writer = FileWriter::try_new(result, schema.clone(), ipc_fields.clone(), options)?;
for batch in batches {
writer.write(batch, ipc_fields.as_ref().map(|x| x.as_ref()))?;
}
Expand Down

0 comments on commit 70571d6

Please sign in to comment.