diff --git a/src/errors.rs b/src/errors.rs index 4ba6d95..02834a5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -26,6 +26,9 @@ pub enum CsvlensError { #[error(transparent)] CsvError(#[from] csv::Error), + #[error(transparent)] + ArrowError(#[from] arrow::error::ArrowError), + #[error(transparent)] Io(#[from] std::io::Error), } diff --git a/src/find.rs b/src/find.rs index e9702c7..588b279 100644 --- a/src/find.rs +++ b/src/find.rs @@ -1,7 +1,7 @@ use crate::csv; +use crate::errors::CsvlensResult; use crate::sort; use crate::sort::SortOrder; -use anyhow::Result; use regex::Regex; use sorted_vec::SortedVec; use std::cmp::min; @@ -71,7 +71,7 @@ impl Finder { column_index: Option, sorter: Option>, sort_order: SortOrder, - ) -> Result { + ) -> CsvlensResult { let internal = FinderInternalState::init( config, target.clone(), diff --git a/src/sort.rs b/src/sort.rs index 10d2496..135a652 100644 --- a/src/sort.rs +++ b/src/sort.rs @@ -1,11 +1,11 @@ use crate::csv; +use crate::errors::CsvlensResult; use std::fs::File; use std::sync::Arc; use std::sync::Mutex; use std::thread::{self}; -use anyhow::Result; use arrow::array::{Array, ArrayIter}; use arrow::compute::concat; use arrow::compute::kernels; @@ -147,7 +147,7 @@ impl SorterInternalState { m: Arc>, config: Arc, column_index: usize, - ) -> Result { + ) -> CsvlensResult { // Get schema let schema = SorterInternalState::infer_schema(config.filename(), config.delimiter())?; @@ -165,7 +165,10 @@ impl SorterInternalState { let arr = record_batch.column(0); arrs.push(arr.clone()); if m.lock().unwrap().should_terminate { - return Err(anyhow::anyhow!("Terminated")); + return Ok(SortResult { + record_indices: vec![], + record_orders: vec![], + }); } } let ref_arrs = arrs @@ -209,7 +212,7 @@ impl SorterInternalState { m_state } - fn infer_schema(filename: &str, delimiter: u8) -> Result { + fn infer_schema(filename: &str, delimiter: u8) -> CsvlensResult { let schema = arrow::csv::infer_schema_from_files( &[filename.to_string()], delimiter, diff --git a/src/view.rs b/src/view.rs index 1e2116c..e09615b 100644 --- a/src/view.rs +++ b/src/view.rs @@ -4,7 +4,6 @@ use crate::find; use crate::input::Control; use crate::sort::{SortOrder, Sorter}; -use anyhow::Result; use regex::Regex; use std::cmp::min; use std::sync::Arc; @@ -352,7 +351,7 @@ impl RowsView { self.num_rows } - pub fn set_num_rows(&mut self, num_rows: u64) -> Result<()> { + pub fn set_num_rows(&mut self, num_rows: u64) -> CsvlensResult<()> { if num_rows == self.num_rows { return Ok(()); }