diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 93061f4b..c3f32cb4 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -13,8 +13,8 @@ mod run; mod summaries; // used in main.rs but not lib.rs -use tokio as _; use eyre as _; +use tokio as _; pub use args::Args; pub use parse::parse_opts; diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 535ce9e6..a733f4d3 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -14,8 +14,8 @@ use eyre::Result; async fn main() -> Result<()> { let args = Args::parse(); match run::run(args).await { - Ok(Some(_freeze_summary)) => { Ok(()) }, - Ok(None) => { Ok(()) }, + Ok(Some(_freeze_summary)) => Ok(()), + Ok(None) => Ok(()), Err(e) => Err(eyre::Report::from(e)), } } diff --git a/crates/cli/src/parse/args.rs b/crates/cli/src/parse/args.rs index 4360756b..fc4f7b2c 100644 --- a/crates/cli/src/parse/args.rs +++ b/crates/cli/src/parse/args.rs @@ -2,8 +2,8 @@ use std::sync::Arc; use cryo_freeze::FileOutput; use cryo_freeze::MultiQuery; -use cryo_freeze::Source; use cryo_freeze::ParseError; +use cryo_freeze::Source; use crate::args::Args; diff --git a/crates/cli/src/parse/file_output.rs b/crates/cli/src/parse/file_output.rs index 449d7c35..ae1695b8 100644 --- a/crates/cli/src/parse/file_output.rs +++ b/crates/cli/src/parse/file_output.rs @@ -12,12 +12,19 @@ use crate::args::Args; pub(crate) fn parse_file_output(args: &Args, source: &Source) -> Result { // process output directory let output_dir = std::fs::canonicalize(args.output_dir.clone()) - .map_err(|_e| ParseError::ParseError("Failed to canonicalize output directory".to_string()))? + .map_err(|_e| { + ParseError::ParseError("Failed to canonicalize output directory".to_string()) + })? .to_string_lossy() .into_owned(); match fs::create_dir_all(&output_dir) { Ok(_) => {} - Err(e) => return Err(ParseError::ParseError(format!("Error creating directory: {}", e))), + Err(e) => { + return Err(ParseError::ParseError(format!( + "Error creating directory: {}", + e + ))) + } }; let file_suffix = &args.file_suffix; @@ -65,7 +72,9 @@ pub(crate) fn parse_network_name(args: &Args, chain_id: u64) -> String { pub(crate) fn parse_output_format(args: &Args) -> Result { match (args.csv, args.json) { - (true, true) => Err(ParseError::ParseError("choose one of parquet, csv, or json".to_string())), + (true, true) => Err(ParseError::ParseError( + "choose one of parquet, csv, or json".to_string(), + )), (true, _) => Ok(FileFormat::Csv), (_, true) => Ok(FileFormat::Json), (false, false) => Ok(FileFormat::Parquet), @@ -81,30 +90,44 @@ fn parse_compression(input: &Vec) -> Result match level_str.parse::() { Ok(level) => match GzipLevel::try_new(level) { Ok(gzip_level) => Ok(ParquetCompression::Gzip(Some(gzip_level))), - Err(_) => Err(ParseError::ParseError("Invalid compression level".to_string())), + Err(_) => Err(ParseError::ParseError( + "Invalid compression level".to_string(), + )), }, - Err(_) => Err(ParseError::ParseError("Invalid compression level".to_string())), + Err(_) => Err(ParseError::ParseError( + "Invalid compression level".to_string(), + )), }, [algorithm, level_str] if algorithm.as_str() == "brotli" => { match level_str.parse::() { Ok(level) => match BrotliLevel::try_new(level) { Ok(brotli_level) => Ok(ParquetCompression::Brotli(Some(brotli_level))), - Err(_) => Err(ParseError::ParseError("Invalid compression level".to_string())), + Err(_) => Err(ParseError::ParseError( + "Invalid compression level".to_string(), + )), }, - Err(_) => Err(ParseError::ParseError("Invalid compression level".to_string())), + Err(_) => Err(ParseError::ParseError( + "Invalid compression level".to_string(), + )), } } [algorithm, level_str] if algorithm.as_str() == "zstd" => match level_str.parse::() { Ok(level) => match ZstdLevel::try_new(level) { Ok(zstd_level) => Ok(ParquetCompression::Zstd(Some(zstd_level))), - Err(_) => Err(ParseError::ParseError("Invalid compression level".to_string())), + Err(_) => Err(ParseError::ParseError( + "Invalid compression level".to_string(), + )), }, - Err(_) => Err(ParseError::ParseError("Invalid compression level".to_string())), + Err(_) => Err(ParseError::ParseError( + "Invalid compression level".to_string(), + )), }, - [algorithm] if ["gzip", "brotli", "zstd"].contains(&algorithm.as_str()) => { - Err(ParseError::ParseError("Missing compression level".to_string())) - } - _ => Err(ParseError::ParseError("Invalid compression algorithm".to_string())), + [algorithm] if ["gzip", "brotli", "zstd"].contains(&algorithm.as_str()) => Err( + ParseError::ParseError("Missing compression level".to_string()), + ), + _ => Err(ParseError::ParseError( + "Invalid compression algorithm".to_string(), + )), } } diff --git a/crates/cli/src/parse/query.rs b/crates/cli/src/parse/query.rs index a4d0846c..e9bbdbed 100644 --- a/crates/cli/src/parse/query.rs +++ b/crates/cli/src/parse/query.rs @@ -109,9 +109,10 @@ fn parse_schemas(args: &Args) -> Result, ParseError> { ) .map(|schema| (*datatype, schema)) .map_err(|_e| { - ParseError::ParseError( - format!("Failed to get schema for datatype: {:?}", datatype), - ) + ParseError::ParseError(format!( + "Failed to get schema for datatype: {:?}", + datatype + )) }) }) .collect(); diff --git a/crates/cli/src/run.rs b/crates/cli/src/run.rs index 3bbc354f..5bf27a1e 100644 --- a/crates/cli/src/run.rs +++ b/crates/cli/src/run.rs @@ -3,8 +3,8 @@ use std::time::SystemTime; use crate::args; use crate::parse; use crate::summaries; -use cryo_freeze::FreezeSummary; use cryo_freeze::FreezeError; +use cryo_freeze::FreezeSummary; /// run freeze for given Args pub async fn run(args: args::Args) -> Result, FreezeError> { diff --git a/crates/freeze/src/types/dataframes/export.rs b/crates/freeze/src/types/dataframes/export.rs index ba1f701e..a21ebc78 100644 --- a/crates/freeze/src/types/dataframes/export.rs +++ b/crates/freeze/src/types/dataframes/export.rs @@ -79,7 +79,9 @@ fn df_to_csv(df: &mut DataFrame, filename: &str) -> Result<(), FileError> { /// write polars dataframe to json file fn df_to_json(df: &mut DataFrame, filename: &str) -> Result<(), FileError> { let file = std::fs::File::create(filename).map_err(|_e| FileError::FileWriteError)?; - let result = JsonWriter::new(file).with_json_format(JsonFormat::Json).finish(df); + let result = JsonWriter::new(file) + .with_json_format(JsonFormat::Json) + .finish(df); match result { Err(_e) => Err(FileError::FileWriteError), _ => Ok(()), diff --git a/crates/freeze/src/types/errors.rs b/crates/freeze/src/types/errors.rs index 5152b7d4..bc542328 100644 --- a/crates/freeze/src/types/errors.rs +++ b/crates/freeze/src/types/errors.rs @@ -67,7 +67,6 @@ pub enum ParseError { ParseIntError(#[from] std::num::ParseIntError), } - /// Error performing a chunk operation #[derive(Error, Debug)] pub enum ChunkError { diff --git a/crates/freeze/src/types/summaries.rs b/crates/freeze/src/types/summaries.rs index 3f697965..78add650 100644 --- a/crates/freeze/src/types/summaries.rs +++ b/crates/freeze/src/types/summaries.rs @@ -1,5 +1,5 @@ -use std::collections::HashMap; use crate::types::Datatype; +use std::collections::HashMap; /// Summary of freeze operation pub struct FreezeSummary { @@ -34,9 +34,9 @@ impl FreezeSummaryAgg for Vec { } for (datatype, path) in chunk_summary.paths { paths_by_type - .entry(datatype) - .or_insert_with(Vec::new) - .push(path); + .entry(datatype) + .or_insert_with(Vec::new) + .push(path); } }