Skip to main content

arrow_file_to_stream/
arrow-file-to-stream.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5//! Converts an Arrow IPC file to an Arrow IPC stream.
6
7use arrow::error::Result;
8use arrow::ipc::reader::FileReader;
9use arrow::ipc::writer::StreamWriter;
10use clap::Parser;
11use std::fs::File;
12use std::io::{self, BufReader};
13
14#[derive(Debug, Parser)]
15#[clap(author, version, about("Read an arrow file and stream to stdout"), long_about = None)]
16struct Args {
17    file_name: String,
18}
19
20fn main() -> Result<()> {
21    let args = Args::parse();
22    let f = File::open(args.file_name)?;
23    let reader = BufReader::new(f);
24    let mut reader = FileReader::try_new(reader, None)?;
25    let schema = reader.schema();
26
27    let mut writer = StreamWriter::try_new(io::stdout(), &schema)?;
28
29    reader.try_for_each(|batch| {
30        let batch = batch?;
31        writer.write(&batch)
32    })?;
33    writer.finish()?;
34
35    Ok(())
36}