Skip to content

Commit

Permalink
Fix some clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
lewiszlw committed Feb 23, 2024
1 parent d3b8846 commit e8b2ac9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
4 changes: 2 additions & 2 deletions bustubx/src/catalog/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ impl Schema {
.iter()
.enumerate()
.find(|(_, col)| match (relation, &col.relation) {
(Some(rel), Some(col_rel)) => rel.resolved_eq(col_rel) && name == &col.name,
(Some(rel), Some(col_rel)) => rel.resolved_eq(col_rel) && name == col.name,
(Some(_), None) => false,
(None, Some(_)) | (None, None) => name == &col.name,
(None, Some(_)) | (None, None) => name == col.name,
})
.ok_or_else(|| BustubxError::Plan(format!("Unable to get column named \"{name}\"")))?;
Ok(idx)
Expand Down
32 changes: 14 additions & 18 deletions bustubx/src/execution/physical_plan/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,21 @@ impl VolcanoExecutor for PhysicalAggregate {
// build output rows
if output_rows_len == 0 {
let mut groups: HashMap<Vec<ScalarValue>, Vec<Box<dyn Accumulator>>> = HashMap::new();
loop {
if let Some(tuple) = self.input.next(context)? {
let group_key = self
.group_exprs
.iter()
.map(|e| e.evaluate(&tuple))
.collect::<BustubxResult<Vec<ScalarValue>>>()?;
let group_accumulators = if let Some(acc) = groups.get_mut(&group_key) {
acc
} else {
let accumulators = self.build_accumulators()?;
groups.insert(group_key.clone(), accumulators);
groups.get_mut(&group_key).unwrap()
};
for (idx, acc) in group_accumulators.iter_mut().enumerate() {
acc.update_value(&self.aggr_exprs[idx].evaluate(&tuple)?)?;
}
while let Some(tuple) = self.input.next(context)? {
let group_key = self
.group_exprs
.iter()
.map(|e| e.evaluate(&tuple))
.collect::<BustubxResult<Vec<ScalarValue>>>()?;
let group_accumulators = if let Some(acc) = groups.get_mut(&group_key) {
acc
} else {
break;
let accumulators = self.build_accumulators()?;
groups.insert(group_key.clone(), accumulators);
groups.get_mut(&group_key).unwrap()
};
for (idx, acc) in group_accumulators.iter_mut().enumerate() {
acc.update_value(&self.aggr_exprs[idx].evaluate(&tuple)?)?;
}
}

Expand Down
8 changes: 2 additions & 6 deletions bustubx/src/execution/physical_plan/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ impl VolcanoExecutor for PhysicalSort {
if all_tuples_len == 0 {
// load all tuples from input
let mut all_tuples = Vec::new();
loop {
if let Some(tuple) = self.input.next(context)? {
all_tuples.push(tuple);
} else {
break;
}
while let Some(tuple) = self.input.next(context)? {
all_tuples.push(tuple);
}

// sort all tuples
Expand Down
8 changes: 4 additions & 4 deletions bustubx/src/storage/table_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,18 +377,18 @@ mod tests {

let mut iterator = table_heap.iter(None, None);

let (meta, tuple) = iterator.next(&mut table_heap).unwrap();
let (meta, tuple) = iterator.next(&table_heap).unwrap();
assert_eq!(meta, meta1);
assert_eq!(tuple.data, vec![1i8.into(), 1i16.into()]);

let (meta, tuple) = iterator.next(&mut table_heap).unwrap();
let (meta, tuple) = iterator.next(&table_heap).unwrap();
assert_eq!(meta, meta2);
assert_eq!(tuple.data, vec![2i8.into(), 2i16.into()]);

let (meta, tuple) = iterator.next(&mut table_heap).unwrap();
let (meta, tuple) = iterator.next(&table_heap).unwrap();
assert_eq!(meta, meta3);
assert_eq!(tuple.data, vec![3i8.into(), 3i16.into()]);

assert!(iterator.next(&mut table_heap).is_none());
assert!(iterator.next(&table_heap).is_none());
}
}

0 comments on commit e8b2ac9

Please sign in to comment.