Skip to content

Commit 547b500

Browse files
committed
add -q flag for silent conversion
1 parent 83bcf7c commit 547b500

File tree

2 files changed

+58
-29
lines changed

2 files changed

+58
-29
lines changed

vortex-tui/src/convert.rs

+44-25
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ use vortex::file::VortexWriteOptions;
1919
use vortex::stream::{ArrayStream, ArrayStreamArrayExt};
2020
use vortex::{Array, ArrayRef};
2121

22+
#[derive(Default)]
23+
pub struct Flags {
24+
pub quiet: bool,
25+
}
26+
2227
/// Convert Parquet files to Vortex.
23-
pub async fn exec_convert(input_path: impl AsRef<Path>) -> VortexResult<()> {
24-
println!(
25-
"Converting input Parquet file: {}",
26-
input_path.as_ref().display()
27-
);
28+
pub async fn exec_convert(input_path: impl AsRef<Path>, flags: Flags) -> VortexResult<()> {
29+
if !flags.quiet {
30+
println!(
31+
"Converting input Parquet file: {}",
32+
input_path.as_ref().display()
33+
);
34+
}
2835

2936
let wall_start = Instant::now();
3037

@@ -42,34 +49,46 @@ pub async fn exec_convert(input_path: impl AsRef<Path>) -> VortexResult<()> {
4249
}
4350

4451
let read_complete = Instant::now();
45-
println!(
46-
"Read Parquet file in {:?}",
47-
read_complete.duration_since(wall_start)
48-
);
52+
53+
if !flags.quiet {
54+
println!(
55+
"Read Parquet file in {:?}",
56+
read_complete.duration_since(wall_start)
57+
);
58+
59+
println!(
60+
"Writing {} chunks to new Vortex file {}",
61+
chunks.len(),
62+
output_path.display()
63+
);
64+
}
4965

5066
let dtype = chunks.first().vortex_expect("empty chunks").dtype().clone();
5167
let chunked_array = ChunkedArray::try_new(chunks, dtype)?;
5268

5369
let writer = VortexWriteOptions::default();
5470

55-
let pb = ProgressBar::new(chunked_array.nchunks() as u64);
56-
let stream = ProgressArrayStream {
57-
inner: chunked_array.to_array_stream(),
58-
progress: pb,
59-
};
60-
61-
println!(
62-
"Writing {} chunks to new Vortex file {}",
63-
chunked_array.nchunks(),
64-
output_path.display()
65-
);
6671
let output_file = File::create(output_path).await?;
67-
writer.write(output_file, stream).await?;
6872

69-
println!(
70-
"Wrote Vortex in {:?}",
71-
Instant::now().duration_since(read_complete)
72-
);
73+
if !flags.quiet {
74+
let pb = ProgressBar::new(chunked_array.nchunks() as u64);
75+
let stream = ProgressArrayStream {
76+
inner: chunked_array.to_array_stream(),
77+
progress: pb,
78+
};
79+
writer.write(output_file, stream).await?;
80+
} else {
81+
writer
82+
.write(output_file, chunked_array.to_array_stream())
83+
.await?;
84+
}
85+
86+
if !flags.quiet {
87+
println!(
88+
"Wrote Vortex in {:?}",
89+
Instant::now().duration_since(read_complete)
90+
);
91+
}
7392

7493
Ok(())
7594
}

vortex-tui/src/main.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use clap::Parser;
1111
use tokio::runtime::Runtime;
1212
use tree::exec_tree;
1313

14-
use crate::convert::exec_convert;
14+
use crate::convert::{Flags, exec_convert};
1515

1616
static TOKIO_RUNTIME: LazyLock<Runtime> =
1717
LazyLock::new(|| Runtime::new().expect("Tokio Runtime::new()"));
@@ -24,17 +24,27 @@ struct Cli {
2424

2525
#[derive(Debug, clap::Subcommand)]
2626
enum Commands {
27+
/// Print the encoding tree of a Vortex file.
2728
Tree { file: PathBuf },
28-
Convert { file: PathBuf },
29+
/// Convert a Parquet file to a Vortex file. Chunking occurs on Parquet RowGroup boundaries.
30+
Convert {
31+
/// Path to the Parquet file on disk to convert to Vortex
32+
file: PathBuf,
33+
34+
/// Execute quietly. No output will be printed.
35+
#[arg(short, long)]
36+
quiet: bool,
37+
},
38+
/// Interactively browse the Vortex file.
2939
Browse { file: PathBuf },
3040
}
3141

3242
fn main() {
3343
let cli = Cli::parse();
3444
match cli.command {
3545
Commands::Tree { file } => TOKIO_RUNTIME.block_on(exec_tree(file)).expect("exec_tre"),
36-
Commands::Convert { file } => TOKIO_RUNTIME
37-
.block_on(exec_convert(file))
46+
Commands::Convert { file, quiet } => TOKIO_RUNTIME
47+
.block_on(exec_convert(file, Flags { quiet }))
3848
.expect("exec_convert"),
3949
Commands::Browse { file } => exec_tui(file).expect("exec_tui"),
4050
}

0 commit comments

Comments
 (0)