Skip to content

Commit

Permalink
#62 allow to limit export to given number of rows
Browse files Browse the repository at this point in the history
  • Loading branch information
klangner committed Apr 19, 2024
1 parent d59ba95 commit 02b7534
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/bin/orc-export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ struct Cli {
/// Output format. If not provided then the output is csv
#[arg(value_enum, short, long)]
format: Option<FileFormat>,
// TODO: head=N
/// export only first N records
#[arg(short, long, value_name = "N")]
num_rows: Option<i64>,
// TODO: convert_dates
// TODO: columns="col1,col2"
}
Expand Down Expand Up @@ -78,8 +80,18 @@ fn main() -> Result<()> {
};

// Convert data
for batch in reader.flatten() {
let mut num_rows = cli.num_rows.unwrap_or(i64::MAX);
for mut batch in reader.flatten() {
if num_rows < batch.num_rows() as i64 {
batch = batch.slice(0, num_rows as usize);
}

output_writer.write(&batch)?;

num_rows = num_rows - batch.num_rows() as i64;
if num_rows <= 0 {
break
}
}

output_writer.finish()?;
Expand Down

0 comments on commit 02b7534

Please sign in to comment.