Skip to content

Commit

Permalink
parquet-read: add support to read parquet data from stdin (#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvartolomei committed Aug 18, 2022
1 parent a835ba0 commit e60eef3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions parquet/src/bin/parquet-read.rs
Expand Up @@ -41,12 +41,13 @@ extern crate parquet;
use clap::Parser;
use parquet::file::reader::{FileReader, SerializedFileReader};
use parquet::record::Row;
use std::io::{self, Read};
use std::{fs::File, path::Path};

#[derive(Debug, Parser)]
#[clap(author, version, about("Binary file to read data from a Parquet file"), long_about = None)]
struct Args {
#[clap(short, long, help("Path to a parquet file"))]
#[clap(short, long, help("Path to a parquet file, or - for stdin"))]
file_name: String,
#[clap(
short,
Expand All @@ -66,10 +67,20 @@ fn main() {
let num_records = args.num_records;
let json = args.json;

let path = Path::new(&filename);
let file = File::open(&path).expect("Unable to open file");
let parquet_reader =
SerializedFileReader::new(file).expect("Failed to create reader");
let parquet_reader: Box<dyn FileReader> = if filename == "-" {
let mut buf = Vec::new();
io::stdin()
.read_to_end(&mut buf)
.expect("Failed to read stdin into a buffer");
Box::new(
SerializedFileReader::new(bytes::Bytes::from(buf))
.expect("Failed to create reader"),
)
} else {
let path = Path::new(&filename);
let file = File::open(&path).expect("Unable to open file");
Box::new(SerializedFileReader::new(file).expect("Failed to create reader"))
};

// Use full schema as projected schema
let mut iter = parquet_reader
Expand Down

0 comments on commit e60eef3

Please sign in to comment.