Skip to content

Commit 93ca5d7

Browse files
committed
invalid: handle the panic in the DataValue::cast method and convert it to TypeError::CastFail
1 parent 11b7c70 commit 93ca5d7

File tree

18 files changed

+402
-388
lines changed

18 files changed

+402
-388
lines changed

src/binder/insert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<S: Storage> Binder<S> {
4848
match self.bind_expr(expr).await? {
4949
ScalarExpression::Constant(value) => {
5050
let cast_value = DataValue::clone(&value)
51-
.cast(columns[i].datatype());
51+
.cast(columns[i].datatype())?;
5252

5353
row.push(Arc::new(cast_value))
5454
},

src/execution/executor/dml/insert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Insert {
5151
});
5252

5353
let tuple_id = if let DataValue::Int64(Some(primary_id)) =
54-
DataValue::clone(&values[*primary_idx]).cast(&LogicalType::Bigint)
54+
DataValue::clone(&values[*primary_idx]).cast(&LogicalType::Bigint)?
5555
{
5656
primary_id
5757
} else {

src/execution/executor/dql/aggregate/avg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Accumulator for AvgAccumulator {
4646
&value,
4747
&quantity,
4848
&BinaryOperator::Divide
49-
)
49+
)?
5050
))
5151
}
5252
}

src/execution/executor/dql/aggregate/hash_agg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl HashAggExecutor {
5353
});
5454

5555
// 2.1 evaluate agg exprs and collect the result values for later accumulators.
56-
let values = self.agg_calls
56+
let values: Vec<ValueRef> = self.agg_calls
5757
.iter()
5858
.map(|expr| {
5959
if let ScalarExpression::AggCall { args, .. } = expr {
@@ -62,12 +62,12 @@ impl HashAggExecutor {
6262
unreachable!()
6363
}
6464
})
65-
.collect_vec();
65+
.try_collect()?;
6666

67-
let group_keys = self.groupby_exprs
67+
let group_keys: Vec<ValueRef> = self.groupby_exprs
6868
.iter()
6969
.map(|expr| expr.eval_column(&tuple))
70-
.collect_vec();
70+
.try_collect()?;
7171

7272
for (acc, value) in group_hash_accs
7373
.entry(group_keys)

src/execution/executor/dql/aggregate/min_max.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl Accumulator for MinMaxAccumulator {
3232
fn update_value(&mut self, value: &ValueRef) -> Result<(), ExecutorError> {
3333
if !value.is_null() {
3434
if let Some(inner_value) = &self.inner {
35-
if let DataValue::Boolean(Some(result)) = binary_op(&inner_value, value, &self.op) {
35+
if let DataValue::Boolean(Some(result)) = binary_op(&inner_value, value, &self.op)? {
3636
result
3737
} else {
3838
unreachable!()

src/execution/executor/dql/aggregate/simple_agg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ impl SimpleAggExecutor {
4646
.collect_vec()
4747
});
4848

49-
let values = self.agg_calls
49+
let values: Vec<ValueRef> = self.agg_calls
5050
.iter()
5151
.map(|expr| match expr {
5252
ScalarExpression::AggCall { args, .. } => {
5353
args[0].eval_column(&tuple)
5454
}
5555
_ => unreachable!()
5656
})
57-
.collect_vec();
57+
.try_collect()?;
5858

5959
for (acc, value) in accs.iter_mut().zip_eq(values.iter()) {
6060
acc.update_value(value)?;

src/execution/executor/dql/aggregate/sum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Accumulator for SumAccumulator {
2727
&self.result,
2828
value,
2929
&BinaryOperator::Plus
30-
);
30+
)?;
3131
}
3232

3333
Ok(())

src/execution/executor/dql/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Filter {
3535
#[for_await]
3636
for tuple in input {
3737
let tuple = tuple?;
38-
if let DataValue::Boolean(option) = predicate.eval_column(&tuple).as_ref() {
38+
if let DataValue::Boolean(option) = predicate.eval_column(&tuple)?.as_ref() {
3939
if let Some(true) = option{
4040
yield tuple;
4141
} else {

src/execution/executor/dql/join/hash_join.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::execution::ExecutorError;
99
use crate::expression::ScalarExpression;
1010
use crate::planner::operator::join::{JoinCondition, JoinOperator, JoinType};
1111
use crate::storage::Storage;
12+
use crate::types::errors::TypeError;
1213
use crate::types::tuple::Tuple;
1314
use crate::types::value::DataValue;
1415

@@ -63,7 +64,7 @@ impl HashJoin {
6364
#[for_await]
6465
for tuple in left_input {
6566
let tuple: Tuple = tuple?;
66-
let hash = Self::hash_row(&on_left_keys, &hash_random_state, &tuple);
67+
let hash = Self::hash_row(&on_left_keys, &hash_random_state, &tuple)?;
6768

6869
if !left_init_flag {
6970
Self::columns_filling(&tuple, &mut join_columns, left_force_nullable);
@@ -82,7 +83,7 @@ impl HashJoin {
8283
for tuple in right_input {
8384
let tuple: Tuple = tuple?;
8485
let right_cols_len = tuple.columns.len();
85-
let hash = Self::hash_row(&on_right_keys, &hash_random_state, &tuple);
86+
let hash = Self::hash_row(&on_right_keys, &hash_random_state, &tuple)?;
8687

8788
if !right_init_flag {
8889
Self::columns_filling(&tuple, &mut join_columns, right_force_nullable);
@@ -122,7 +123,7 @@ impl HashJoin {
122123
let mut filter_tuples = Vec::with_capacity(join_tuples.len());
123124

124125
for mut tuple in join_tuples {
125-
if let DataValue::Boolean(option) = expr.eval_column(&tuple).as_ref() {
126+
if let DataValue::Boolean(option) = expr.eval_column(&tuple)?.as_ref() {
126127
if let Some(false) | None = option {
127128
let full_cols_len = tuple.columns.len();
128129
let left_cols_len = full_cols_len - right_cols_len;
@@ -200,13 +201,14 @@ impl HashJoin {
200201
on_keys: &[ScalarExpression],
201202
hash_random_state: &RandomState,
202203
tuple: &Tuple
203-
) -> u64 {
204-
let values = on_keys
205-
.iter()
206-
.map(|expr| expr.eval_column(tuple))
207-
.collect_vec();
204+
) -> Result<u64, TypeError> {
205+
let mut values = Vec::with_capacity(on_keys.len());
206+
207+
for expr in on_keys {
208+
values.push(expr.eval_column(tuple)?);
209+
}
208210

209-
hash_random_state.hash_one(values)
211+
Ok(hash_random_state.hash_one(values))
210212
}
211213
}
212214

src/execution/executor/dql/projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Projection {
3939
let mut values = Vec::with_capacity(exprs.len());
4040

4141
for expr in exprs.iter() {
42-
values.push(expr.eval_column(&tuple));
42+
values.push(expr.eval_column(&tuple)?);
4343
columns.push(expr.output_columns(&tuple));
4444
}
4545

0 commit comments

Comments
 (0)