Skip to content

Commit

Permalink
fix: count - fall back to regular csv reader count if polars count …
Browse files Browse the repository at this point in the history
…returns empty result

previously, it was returning 0, which is wrong
  • Loading branch information
jqnatividad committed Jan 8, 2025
1 parent 3dac590 commit 9321bf1
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/cmd/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,23 @@ pub fn polars_count_input(conf: &Config, low_memory: bool) -> CliResult<u64> {
},
};

let mut count = if let Ok(cnt) = sqlresult_lf.collect()?["len"].u32() {
cnt.get(0).unwrap_or(0) as u64 // Use unwrap_or to handle empty results
} else {
// Polars error, fall back to the regular CSV reader
log::warn!("polars error, falling back to regular reader");
let (count_regular, _) = count_input(conf, CountDelimsMode::NotRequired)?;
count_regular
let mut count = match sqlresult_lf.collect()?["len"].u64() {
Ok(cnt) => {
if let Some(count) = cnt.get(0) {
count
} else {
// Empty result, fall back to regular CSV reader
log::warn!("empty polars result, falling back to regular reader");
let (count_regular, _) = count_input(conf, CountDelimsMode::NotRequired)?;
count_regular
}
},
Err(e) => {
// Polars error, fall back to regular CSV reader
log::warn!("polars error, falling back to regular reader: {e}");
let (count_regular, _) = count_input(conf, CountDelimsMode::NotRequired)?;
count_regular
},
};

// remove the temporary file we created to read from stdin
Expand Down

0 comments on commit 9321bf1

Please sign in to comment.