Skip to content

Commit

Permalink
code fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Feb 9, 2024
1 parent 6c620a7 commit 65054b8
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 56 deletions.
5 changes: 1 addition & 4 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ fn encode_tuples<'a>(tuples: Vec<Tuple>) -> PgWireResult<QueryResponse<'a>> {
results.push(encoder.finish());
}

Ok(QueryResponse::new(
schema,
stream::iter(results),
))
Ok(QueryResponse::new(schema, stream::iter(results)))
}

fn into_pg_type(data_type: &LogicalType) -> PgWireResult<Type> {
Expand Down
14 changes: 12 additions & 2 deletions src/binder/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ impl<'a, T: Transaction> Binder<'a, T> {
self.visit_column_agg_expr(arg)?;
}
}
ScalarExpression::Between { expr, left_expr, right_expr, .. } => {
ScalarExpression::Between {
expr,
left_expr,
right_expr,
..
} => {
self.visit_column_agg_expr(expr)?;
self.visit_column_agg_expr(left_expr)?;
self.visit_column_agg_expr(right_expr)?;
Expand Down Expand Up @@ -262,7 +267,12 @@ impl<'a, T: Transaction> Binder<'a, T> {
self.validate_having_orderby(right_expr)?;
Ok(())
}
ScalarExpression::Between { expr, left_expr, right_expr, .. } => {
ScalarExpression::Between {
expr,
left_expr,
right_expr,
..
} => {
self.validate_having_orderby(expr)?;
self.validate_having_orderby(left_expr)?;
self.validate_having_orderby(right_expr)?;
Expand Down
19 changes: 11 additions & 8 deletions src/binder/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ impl<'a, T: Transaction> Binder<'a, T> {

Ok(ScalarExpression::Constant(Arc::new(value)))
}
Expr::Between { expr, negated, low, high } => {
Ok(ScalarExpression::Between {
negated: *negated,
expr: Box::new(self.bind_expr(expr)?),
left_expr: Box::new(self.bind_expr(low)?),
right_expr: Box::new(self.bind_expr(high)?),
})
}
Expr::Between {
expr,
negated,
low,
high,
} => Ok(ScalarExpression::Between {
negated: *negated,
expr: Box::new(self.bind_expr(expr)?),
left_expr: Box::new(self.bind_expr(low)?),
right_expr: Box::new(self.bind_expr(high)?),
}),
_ => {
todo!()
}
Expand Down
3 changes: 1 addition & 2 deletions src/execution/volcano/dql/aggregate/hash_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ impl HashAggStatus {
pub(crate) fn as_tuples(&mut self) -> Result<Vec<Tuple>, DatabaseError> {
let group_columns = Arc::new(mem::take(&mut self.group_columns));

self
.group_hash_accs
self.group_hash_accs
.drain()
.map(|(group_keys, accs)| {
// Tips: Accumulator First
Expand Down
5 changes: 1 addition & 4 deletions src/execution/volcano/dql/join/hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ impl HashJoinStatus {
let _ = mem::replace(left_init_flag, true);
}

build_map
.entry(hash)
.or_insert_with(Vec::new)
.push(tuple);
build_map.entry(hash).or_insert_with(Vec::new).push(tuple);

Ok(())
}
Expand Down
5 changes: 1 addition & 4 deletions src/execution/volcano/dql/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ pub(crate) fn radix_sort<T>(mut tuples: Vec<(T, Vec<u8>)>) -> Vec<T> {
temp_buckets[index as usize].push((t, bytes));
}

tuples = temp_buckets
.iter_mut()
.flat_map(mem::take)
.collect_vec();
tuples = temp_buckets.iter_mut().flat_map(mem::take).collect_vec();
}
return tuples.into_iter().map(|(tuple, _)| tuple).collect_vec();
}
Expand Down
15 changes: 11 additions & 4 deletions src/expression/evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::cmp::Ordering;
use crate::catalog::ColumnSummary;
use crate::errors::DatabaseError;
use crate::expression::value_compute::{binary_op, unary_op};
Expand All @@ -7,6 +6,7 @@ use crate::types::tuple::Tuple;
use crate::types::value::{DataValue, ValueRef};
use itertools::Itertools;
use lazy_static::lazy_static;
use std::cmp::Ordering;
use std::sync::Arc;

lazy_static! {
Expand Down Expand Up @@ -101,16 +101,23 @@ impl ScalarExpression {

Ok(value)
}
ScalarExpression::Between { expr, left_expr, right_expr, negated } => {
ScalarExpression::Between {
expr,
left_expr,
right_expr,
negated,
} => {
let value = expr.eval(tuple)?;
let left = left_expr.eval(tuple)?;
let right = right_expr.eval(tuple)?;

let mut is_between = match (value.partial_cmp(&left).map(Ordering::is_ge), value.partial_cmp(&right).map(Ordering::is_le)) {
let mut is_between = match (
value.partial_cmp(&left).map(Ordering::is_ge),
value.partial_cmp(&right).map(Ordering::is_le),
) {
(Some(true), Some(true)) => true,
(None, _) | (_, None) => return Ok(Arc::new(DataValue::Boolean(None))),
_ => false,

};
if *negated {
is_between = !is_between;
Expand Down
43 changes: 24 additions & 19 deletions src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub enum ScalarExpression {
expr: Box<ScalarExpression>,
left_expr: Box<ScalarExpression>,
right_expr: Box<ScalarExpression>,
}
},
}

impl ScalarExpression {
Expand Down Expand Up @@ -108,9 +108,12 @@ impl ScalarExpression {
expr.nullable() && args.iter().all(ScalarExpression::nullable)
}
ScalarExpression::AggCall { args, .. } => args.iter().all(ScalarExpression::nullable),
ScalarExpression::Between { expr, left_expr, right_expr, .. } => {
expr.nullable() && left_expr.nullable() && right_expr.nullable()
}
ScalarExpression::Between {
expr,
left_expr,
right_expr,
..
} => expr.nullable() && left_expr.nullable() && right_expr.nullable(),
}
}

Expand All @@ -130,7 +133,9 @@ impl ScalarExpression {
Self::AggCall {
ty: return_type, ..
} => *return_type,
Self::IsNull { .. } | Self::In { .. } | ScalarExpression::Between { .. } => LogicalType::Boolean,
Self::IsNull { .. } | Self::In { .. } | ScalarExpression::Between { .. } => {
LogicalType::Boolean
}
Self::Alias { expr, .. } => expr.return_type(),
}
}
Expand Down Expand Up @@ -203,9 +208,12 @@ impl ScalarExpression {
ScalarExpression::In { expr, args, .. } => {
expr.has_agg_call() || args.iter().any(|arg| arg.has_agg_call())
}
ScalarExpression::Between { expr, left_expr, right_expr, .. } => {
expr.has_agg_call() || left_expr.has_agg_call() || right_expr.has_agg_call()
}
ScalarExpression::Between {
expr,
left_expr,
right_expr,
..
} => expr.has_agg_call() || left_expr.has_agg_call() || right_expr.has_agg_call(),
}
}

Expand Down Expand Up @@ -260,19 +268,16 @@ impl ScalarExpression {
negated,
expr,
} => {
let args_string = args
.iter()
.map(|arg| arg.output_name())
.join(", ");
let args_string = args.iter().map(|arg| arg.output_name()).join(", ");
let op_string = if *negated { "not in" } else { "in" };
format!(
"{} {} ({})",
expr.output_name(),
op_string,
args_string
)
format!("{} {} ({})", expr.output_name(), op_string, args_string)
}
ScalarExpression::Between { expr, left_expr, right_expr, negated } => {
ScalarExpression::Between {
expr,
left_expr,
right_expr,
negated,
} => {
let op_string = if *negated { "not between" } else { "between" };
format!(
"{} {} [{}, {}]",
Expand Down
17 changes: 13 additions & 4 deletions src/expression/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,20 @@ impl ScalarExpression {

let _ = mem::replace(self, new_expr);
}
ScalarExpression::Between { expr, left_expr, right_expr, negated } => {
ScalarExpression::Between {
expr,
left_expr,
right_expr,
negated,
} => {
let (op, left_op, right_op) = if *negated {
(BinaryOperator::Or, BinaryOperator::Lt, BinaryOperator::Gt)
} else {
(BinaryOperator::And, BinaryOperator::GtEq, BinaryOperator::LtEq)
(
BinaryOperator::And,
BinaryOperator::GtEq,
BinaryOperator::LtEq,
)
};
let new_expr = ScalarExpression::Binary {
op,
Expand Down Expand Up @@ -908,7 +917,7 @@ impl ScalarExpression {
| ScalarExpression::TypeCast { expr, .. }
| ScalarExpression::Unary { expr, .. }
| ScalarExpression::In { expr, .. }
| ScalarExpression::Between { expr , ..} => expr.convert_binary(col_id),
| ScalarExpression::Between { expr, .. } => expr.convert_binary(col_id),
ScalarExpression::IsNull { expr, negated, .. } => match expr.as_ref() {
ScalarExpression::ColumnRef(column) => {
Ok(column.id().is_some_and(|id| col_id == &id).then(|| {
Expand All @@ -927,7 +936,7 @@ impl ScalarExpression {
| ScalarExpression::Binary { .. }
| ScalarExpression::AggCall { .. }
| ScalarExpression::In { .. }
|ScalarExpression::Between { .. } => expr.convert_binary(col_id),
| ScalarExpression::Between { .. } => expr.convert_binary(col_id),
},
ScalarExpression::Constant(_)
| ScalarExpression::ColumnRef(_)
Expand Down
4 changes: 1 addition & 3 deletions src/optimizer/core/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ impl HistogramBuilder {
column_id: column.id().ok_or(DatabaseError::OwnerLessColumn)?,
data_type: *column.datatype(),
null_count: 0,
values: capacity
.map(Vec::with_capacity)
.unwrap_or_default(),
values: capacity.map(Vec::with_capacity).unwrap_or_default(),
value_index: 0,
})
}
Expand Down
3 changes: 1 addition & 2 deletions src/optimizer/heuristic/optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ impl HepOptimizer {
})
.transpose()?;

self
.graph
self.graph
.into_plan(memo.as_ref())
.ok_or(DatabaseError::EmptyPlan)
}
Expand Down

0 comments on commit 65054b8

Please sign in to comment.