Skip to content

Commit

Permalink
Remove more usage of anyhow
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Jul 21, 2024
1 parent 67c1afd commit 96b9397
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
4 changes: 2 additions & 2 deletions src/find.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -71,7 +71,7 @@ impl Finder {
column_index: Option<usize>,
sorter: Option<Arc<sort::Sorter>>,
sort_order: SortOrder,
) -> Result<Self> {
) -> CsvlensResult<Self> {
let internal = FinderInternalState::init(
config,
target.clone(),
Expand Down
11 changes: 7 additions & 4 deletions src/sort.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -147,7 +147,7 @@ impl SorterInternalState {
m: Arc<Mutex<SorterInternalState>>,
config: Arc<csv::CsvConfig>,
column_index: usize,
) -> Result<SortResult> {
) -> CsvlensResult<SortResult> {
// Get schema
let schema =
SorterInternalState::infer_schema(config.filename(), config.delimiter())?;
Expand All @@ -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
Expand Down Expand Up @@ -209,7 +212,7 @@ impl SorterInternalState {
m_state
}

fn infer_schema(filename: &str, delimiter: u8) -> Result<Schema> {
fn infer_schema(filename: &str, delimiter: u8) -> CsvlensResult<Schema> {
let schema = arrow::csv::infer_schema_from_files(
&[filename.to_string()],
delimiter,
Expand Down
3 changes: 1 addition & 2 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(());
}
Expand Down

0 comments on commit 96b9397

Please sign in to comment.