Skip to content

Commit cdf8263

Browse files
committed
chore: fix code with clippy
1 parent 202e376 commit cdf8263

3 files changed

Lines changed: 95 additions & 90 deletions

File tree

src/bin/bench_runner_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async fn main() {
8888

8989
println!("Starting ArgusDB server on {}:{}", host, port);
9090
let mut command = Command::new("./target/release/argusdb");
91-
command.args(&[
91+
command.args([
9292
"--jstable-dir",
9393
&db_path,
9494
"--host",

src/db.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ impl<'a> Iterator for HybridIterator<'a> {
5151
continue; // Tombstone
5252
}
5353

54-
if let Some(pred) = &self.predicate {
55-
if evaluate_expression(pred, val) != Value::Bool(true) {
56-
continue;
57-
}
54+
if let Some(pred) = &self.predicate
55+
&& evaluate_expression(pred, val) != Value::Bool(true)
56+
{
57+
continue;
5858
}
5959

6060
if let Some(projs) = &self.projections {
@@ -92,10 +92,10 @@ impl<'a> Iterator for HybridIterator<'a> {
9292
continue; // Tombstone
9393
}
9494

95-
if let Some(pred) = &self.predicate {
96-
if evaluate_expression(pred, val) != Value::Bool(true) {
97-
continue;
98-
}
95+
if let Some(pred) = &self.predicate
96+
&& evaluate_expression(pred, val) != Value::Bool(true)
97+
{
98+
continue;
9999
}
100100

101101
if let Some(projs) = &self.projections {
@@ -128,10 +128,10 @@ impl<'a> Iterator for HybridIterator<'a> {
128128
if self.memtable.contains_key(res.id()) {
129129
continue;
130130
}
131-
if let Some(frozen) = self.frozen_memtable {
132-
if frozen.contains_key(res.id()) {
133-
continue;
134-
}
131+
if let Some(frozen) = self.frozen_memtable
132+
&& frozen.contains_key(res.id())
133+
{
134+
continue;
135135
}
136136
return Some(res);
137137
} else {
@@ -196,10 +196,10 @@ impl<'a> Iterator for MergedIterator<'a> {
196196
use jsonb_schema::Value as JsonbValue;
197197
if !matches!(val, JsonbValue::Null) {
198198
// Check predicate if exists
199-
if let Some(pred) = &self.predicate {
200-
if evaluate_expression(pred, val) != Value::Bool(true) {
201-
continue;
202-
}
199+
if let Some(pred) = &self.predicate
200+
&& evaluate_expression(pred, val) != Value::Bool(true)
201+
{
202+
continue;
203203
}
204204

205205
if let Some(projs) = &self.projections {
@@ -225,10 +225,10 @@ impl<'a> Iterator for MergedIterator<'a> {
225225
ExecutionResult::Lazy(doc) => {
226226
if !doc.is_tombstone() {
227227
// Check predicate if exists
228-
if let Some(pred) = &self.predicate {
229-
if evaluate_expression_lazy(pred, doc) != Value::Bool(true) {
230-
continue;
231-
}
228+
if let Some(pred) = &self.predicate
229+
&& evaluate_expression_lazy(pred, doc) != Value::Bool(true)
230+
{
231+
continue;
232232
}
233233

234234
if let Some(projs) = &self.projections {
@@ -540,14 +540,14 @@ impl Collection {
540540
}
541541

542542
// 2. Check Frozen MemTable
543-
if let Some(frozen) = &self.frozen_memtable {
544-
if let Some(doc) = frozen.documents.get(id) {
545-
use jsonb_schema::Value as JsonbValue;
546-
if matches!(doc, JsonbValue::Null) {
547-
return None; // Tombstone
548-
}
549-
return Some(doc.clone());
543+
if let Some(frozen) = &self.frozen_memtable
544+
&& let Some(doc) = frozen.documents.get(id)
545+
{
546+
use jsonb_schema::Value as JsonbValue;
547+
if matches!(doc, JsonbValue::Null) {
548+
return None; // Tombstone
550549
}
550+
return Some(doc.clone());
551551
}
552552

553553
// 3. Check JSTables (Newer to Older)

src/query.rs

Lines changed: 67 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ pub struct Batch {
207207
pub items: Vec<ExecutionResult>,
208208
}
209209

210+
impl Default for Batch {
211+
fn default() -> Self {
212+
Self::new()
213+
}
214+
}
215+
210216
impl Batch {
211217
pub fn new() -> Self {
212218
Batch {
@@ -269,10 +275,10 @@ impl<'a> Iterator for FlattenOperator<'a> {
269275
type Item = ExecutionResult;
270276
fn next(&mut self) -> Option<Self::Item> {
271277
loop {
272-
if let Some(iter) = &mut self.current_batch {
273-
if let Some(item) = iter.next() {
274-
return Some(item);
275-
}
278+
if let Some(iter) = &mut self.current_batch
279+
&& let Some(item) = iter.next()
280+
{
281+
return Some(item);
276282
}
277283
// Need next batch
278284
if let Some(batch) = self.input.next() {
@@ -372,62 +378,61 @@ impl<'a> BatchFilterOperator<'a> {
372378
}
373379

374380
fn filter_batch(&mut self, batch: &mut Batch) {
375-
if let Expression::Binary { left, op, right } = &self.predicate {
376-
if let (Expression::FieldReference(_, _), Expression::Literal(Value::Number(n))) =
381+
if let Expression::Binary { left, op, right } = &self.predicate
382+
&& let (Expression::FieldReference(_, _), Expression::Literal(Value::Number(n))) =
377383
(left.as_ref(), right.as_ref())
378-
{
379-
let threshold = match n {
380-
jsonb_schema::Number::Float64(f) => *f,
381-
jsonb_schema::Number::Int64(i) => *i as f64,
382-
jsonb_schema::Number::UInt64(u) => *u as f64,
383-
_ => {
384-
self.fallback_filter(batch);
385-
return;
386-
}
387-
};
384+
{
385+
let threshold = match n {
386+
jsonb_schema::Number::Float64(f) => *f,
387+
jsonb_schema::Number::Int64(i) => *i as f64,
388+
jsonb_schema::Number::UInt64(u) => *u as f64,
389+
_ => {
390+
self.fallback_filter(batch);
391+
return;
392+
}
393+
};
388394

389-
// Recycle buffers
390-
self.buf_values.clear();
391-
self.buf_valid.clear();
392-
393-
for item in &batch.items {
394-
let maybe_f = match item {
395-
ExecutionResult::Value(_, v) => match evaluate_expression(left, v) {
396-
Value::Number(n) => get_f64_from_number(&n),
397-
_ => None,
398-
},
399-
ExecutionResult::Lazy(doc) => evaluate_to_f64_lazy(left, doc),
400-
};
395+
// Recycle buffers
396+
self.buf_values.clear();
397+
self.buf_valid.clear();
398+
399+
for item in &batch.items {
400+
let maybe_f = match item {
401+
ExecutionResult::Value(_, v) => match evaluate_expression(left, v) {
402+
Value::Number(n) => get_f64_from_number(&n),
403+
_ => None,
404+
},
405+
ExecutionResult::Lazy(doc) => evaluate_to_f64_lazy(left, doc),
406+
};
401407

402-
if let Some(f) = maybe_f {
403-
self.buf_values.push(f);
404-
self.buf_valid.push(true);
405-
} else {
406-
self.buf_values.push(0.0);
407-
self.buf_valid.push(false);
408-
}
408+
if let Some(f) = maybe_f {
409+
self.buf_values.push(f);
410+
self.buf_valid.push(true);
411+
} else {
412+
self.buf_values.push(0.0);
413+
self.buf_valid.push(false);
409414
}
410-
411-
let mut i = 0;
412-
let buf_values = &self.buf_values;
413-
let buf_valid = &self.buf_valid;
414-
415-
batch.items.retain(|_| {
416-
let valid = buf_valid[i];
417-
let val = buf_values[i];
418-
let keep = match op {
419-
BinaryOperator::Gt => valid && val > threshold,
420-
BinaryOperator::Lt => valid && val < threshold,
421-
BinaryOperator::Gte => valid && val >= threshold,
422-
BinaryOperator::Lte => valid && val <= threshold,
423-
BinaryOperator::Eq => valid && (val - threshold).abs() < f64::EPSILON,
424-
_ => false,
425-
};
426-
i += 1;
427-
keep
428-
});
429-
return;
430415
}
416+
417+
let mut i = 0;
418+
let buf_values = &self.buf_values;
419+
let buf_valid = &self.buf_valid;
420+
421+
batch.items.retain(|_| {
422+
let valid = buf_valid[i];
423+
let val = buf_values[i];
424+
let keep = match op {
425+
BinaryOperator::Gt => valid && val > threshold,
426+
BinaryOperator::Lt => valid && val < threshold,
427+
BinaryOperator::Gte => valid && val >= threshold,
428+
BinaryOperator::Lte => valid && val <= threshold,
429+
BinaryOperator::Eq => valid && (val - threshold).abs() < f64::EPSILON,
430+
_ => false,
431+
};
432+
i += 1;
433+
keep
434+
});
435+
return;
431436
}
432437
self.fallback_filter(batch);
433438
}
@@ -525,13 +530,13 @@ fn is_vectorizable(plan: &LogicalPlan) -> bool {
525530
LogicalPlan::Scan { .. } => true,
526531
LogicalPlan::Filter { input, predicate } => {
527532
let simple_pred = if let Expression::Binary { left, op: _, right } = predicate {
528-
if let (Expression::FieldReference(_, _), Expression::Literal(Value::Number(_))) =
529-
(left.as_ref(), right.as_ref())
530-
{
531-
true
532-
} else {
533-
false
534-
}
533+
matches!(
534+
(left.as_ref(), right.as_ref()),
535+
(
536+
Expression::FieldReference(_, _),
537+
Expression::Literal(Value::Number(_))
538+
)
539+
)
535540
} else {
536541
false
537542
};

0 commit comments

Comments
 (0)