Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Use Rayon thread to do sort
Browse files Browse the repository at this point in the history
  • Loading branch information
SarveshOO7 committed Mar 23, 2024
1 parent f0180b9 commit b73f041
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
23 changes: 13 additions & 10 deletions eggstrain/src/execution/operators/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@ impl Sort {
}
}

fn sort_in_mem(&self, rb: RecordBatch) -> Result<RecordBatch> {
assert_eq!(rb.schema(), self.input_schema);
fn sort_in_mem(
rb: RecordBatch,
limit_size: Option<usize>,
sort_expr: Vec<PhysicalSortExpr>,
) -> Result<RecordBatch> {
// assert_eq!(rb.schema(), self.input_schema);

let expressions = self.sort_expr.clone();
let expressions = sort_expr.clone();

let sort_columns = expressions
.iter()
.map(|expr| expr.evaluate_to_sort_column(&rb))
.collect::<Result<Vec<_>>>()?;

let indices = lexsort_to_indices(&sort_columns, self.limit_size)?;
let indices = lexsort_to_indices(&sort_columns, limit_size)?;

let columns = rb
.columns()
Expand Down Expand Up @@ -90,9 +94,11 @@ impl UnaryOperator for Sort {
}

let merged_batch = concat_batches(&self.input_schema, &batches);
match merged_batch {
let limit_size = self.limit_size;
let sort_expr = self.sort_expr.clone();
rayon::spawn(move || match merged_batch {
Ok(merged_batch) => {
let sorted_batch = self.sort_in_mem(merged_batch).unwrap();
let sorted_batch = Sort::sort_in_mem(merged_batch, limit_size, sort_expr).unwrap();
let mut current = 0;
let total_rows = sorted_batch.num_rows();
while current + BATCH_SIZE < total_rows {
Expand All @@ -104,11 +110,8 @@ impl UnaryOperator for Sort {
let batch_to_send = sorted_batch.slice(current, total_rows - current);
tx.send(batch_to_send)
.expect("Unable to send the last sorted batch");

// TODO: do I have to call drop here manually or will rust take care of it?
// drop(sorted_batch);
}
Err(_) => todo!("Could not concat the batches for sorting"),
}
});
}
}
1 change: 1 addition & 0 deletions eggstrain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async fn main() -> Result<()> {

// Run our execution engine on the physical plan
let df_physical_plan = sql.clone().create_physical_plan().await?;
let df_physical_plan = df_physical_plan.children()[0].clone();
let results = run(df_physical_plan).await;

results.into_iter().for_each(|batch| {
Expand Down

0 comments on commit b73f041

Please sign in to comment.