Skip to content

Commit

Permalink
Fix CostModel's error system to match memo trait
Browse files Browse the repository at this point in the history
  • Loading branch information
SarveshOO7 committed Nov 17, 2024
1 parent a7065f1 commit 4b1676d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
23 changes: 13 additions & 10 deletions optd-persistent/src/cost_model/orm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,13 @@ impl CostModelStorageLayer for BackendManager {
match res {
Ok(insert_res) => insert_res.last_insert_id,
Err(_) => {
return Err(BackendError::BackendError(format!(
"failed to insert statistic {:?} into statistic table",
stat
)))
return Err(BackendError::CostModel(
format!(
"failed to insert statistic {:?} into statistic table",
stat
)
.into(),
))
}
}
}
Expand Down Expand Up @@ -450,10 +453,10 @@ impl CostModelStorageLayer for BackendManager {
.collect::<Vec<_>>();

if attr_ids.len() != attr_base_indices.len() {
return Err(BackendError::BackendError(format!(
return Err(BackendError::CostModel(format!(
"Not all attributes found for table_id {} and base indices {:?}",
table_id, attr_base_indices
)));
).into()));
}

self.get_stats_for_attr(attr_ids, stat_type, epoch_id).await
Expand Down Expand Up @@ -505,10 +508,10 @@ impl CostModelStorageLayer for BackendManager {
.one(&self.db)
.await?;
if expr_exists.is_none() {
return Err(BackendError::BackendError(format!(
return Err(BackendError::CostModel(format!(
"physical expression id {} not found when storing cost",
physical_expression_id
)));
).into()));
}

// Check if epoch_id exists in Event table
Expand All @@ -518,10 +521,10 @@ impl CostModelStorageLayer for BackendManager {
.await
.unwrap();
if epoch_exists.is_none() {
return Err(BackendError::BackendError(format!(
return Err(BackendError::CostModel(format!(
"epoch id {} not found when storing cost",
epoch_id
)));
).into()));
}

let new_cost = plan_cost::ActiveModel {
Expand Down
7 changes: 7 additions & 0 deletions optd-persistent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum CostModelError {
// TODO: Add more error types
UnknownStatisticType,
VersionedStatisticNotFound,
CustomError(String),
}

/// TODO convert this to `thiserror`
Expand All @@ -69,6 +70,12 @@ pub enum BackendError {
// TODO: Add other variants as needed for different error types
}

impl From<String> for CostModelError {
fn from(value: String) -> Self {
CostModelError::CustomError(value)
}
}

impl From<CostModelError> for BackendError {
fn from(value: CostModelError) -> Self {
BackendError::CostModel(value)
Expand Down

0 comments on commit 4b1676d

Please sign in to comment.