parquet_rowcount/parquet-rowcount.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//! Binary file to return the number of rows found from Parquet file(s).
6//!
7//! # Install
8//!
9//! `parquet-rowcount` can be installed using `cargo`:
10//! ```
11//! cargo install parquet --features=cli
12//! ```
13//! After this `parquet-rowcount` should be available:
14//! ```
15//! parquet-rowcount XYZ.parquet
16//! ```
17//!
18//! The binary can also be built from the source code and run as follows:
19//! ```
20//! cargo run --features=cli --bin parquet-rowcount XYZ.parquet ABC.parquet ZXC.parquet
21//! ```
22//!
23//! Note that `parquet-rowcount` reads full file schema, no projection or filtering is
24//! applied.
25
26use clap::Parser;
27use parquet::file::reader::{FileReader, SerializedFileReader};
28use std::{fs::File, path::Path};
29
30#[derive(Debug, Parser)]
31#[clap(author, version, about("Binary file to return the number of rows found from Parquet file(s)"), long_about = None)]
32struct Args {
33 #[clap(
34 number_of_values(1),
35 help("List of Parquet files to read from separated by space")
36 )]
37 file_paths: Vec<String>,
38}
39
40fn main() {
41 let args = Args::parse();
42
43 for filename in args.file_paths {
44 let path = Path::new(&filename);
45 let file = File::open(path).expect("Unable to open file");
46 let parquet_reader = SerializedFileReader::new(file).expect("Unable to read file");
47 let row_group_metadata = parquet_reader.metadata().row_groups();
48 let mut total_num_rows = 0;
49
50 for group_metadata in row_group_metadata {
51 total_num_rows += group_metadata.num_rows();
52 }
53
54 eprintln!("File {filename}: rowcount={total_num_rows}");
55 }
56}