Skip to content

Commit 8a51cdd

Browse files
committed
Apply comment suggestions
1 parent 66cd4f4 commit 8a51cdd

File tree

4 files changed

+41
-46
lines changed

4 files changed

+41
-46
lines changed
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use optd_persistent::{migrate, TEST_DATABASE_URL};
1+
use optd_persistent::{migrate, TEST_DATABASE_FILE, TEST_DATABASE_URL};
22
use sea_orm::*;
33
use sea_orm_migration::prelude::*;
44

55
#[tokio::main]
66
async fn main() {
7-
let _ = std::fs::remove_file(TEST_DATABASE_URL);
7+
let _ = std::fs::remove_file(TEST_DATABASE_FILE);
88

99
let db = Database::connect(TEST_DATABASE_URL)
1010
.await
@@ -13,11 +13,4 @@ async fn main() {
1313
migrate(&db)
1414
.await
1515
.expect("Something went wrong during migration");
16-
17-
db.execute(sea_orm::Statement::from_string(
18-
sea_orm::DatabaseBackend::Sqlite,
19-
"PRAGMA foreign_keys = ON;".to_owned(),
20-
))
21-
.await
22-
.expect("Unable to enable foreign keys");
2316
}

optd-persistent/src/cost_model/interface.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::entities::cascades_group;
44
use crate::entities::event::Model as event_model;
55
use crate::entities::logical_expression;
66
use crate::entities::physical_expression;
7-
use crate::CostModelStorageResult;
7+
use crate::StorageResult;
88
use sea_orm::*;
99
use sea_orm_migration::prelude::*;
1010
use serde_json::json;
@@ -28,30 +28,29 @@ pub trait CostModelStorageLayer {
2828
&mut self,
2929
source: String,
3030
data: String,
31-
) -> CostModelStorageResult<Self::EpochId>;
31+
) -> StorageResult<Self::EpochId>;
3232

3333
async fn update_stats_from_catalog(
3434
&self,
3535
c: CatalogSource,
3636
epoch_id: Self::EpochId,
37-
) -> CostModelStorageResult<()>;
37+
) -> StorageResult<()>;
3838

3939
// i32 in `stats:i32` is a placeholder for the stats type
40-
async fn update_stats(&self, stats: i32, epoch_id: Self::EpochId)
41-
-> CostModelStorageResult<()>;
40+
async fn update_stats(&self, stats: i32, epoch_id: Self::EpochId) -> StorageResult<()>;
4241

4342
async fn store_cost(
4443
&self,
4544
expr_id: Self::ExprId,
4645
cost: i32,
4746
epoch_id: Self::EpochId,
48-
) -> CostModelStorageResult<()>;
47+
) -> StorageResult<()>;
4948

5049
async fn store_expr_stats_mappings(
5150
&self,
5251
expr_id: Self::ExprId,
5352
stat_ids: Vec<Self::StatId>,
54-
) -> CostModelStorageResult<()>;
53+
) -> StorageResult<()>;
5554

5655
/// Get the statistics for a given table.
5756
///
@@ -62,7 +61,7 @@ pub trait CostModelStorageLayer {
6261
// TODO: Add enum for stat_type
6362
stat_type: i32,
6463
epoch_id: Option<Self::EpochId>,
65-
) -> CostModelStorageResult<Option<f32>>;
64+
) -> StorageResult<Option<f32>>;
6665

6766
/// Get the statistics for a given attribute.
6867
///
@@ -72,7 +71,7 @@ pub trait CostModelStorageLayer {
7271
attr_id: Self::AttrId,
7372
stat_type: i32,
7473
epoch_id: Option<Self::EpochId>,
75-
) -> CostModelStorageResult<Option<f32>>;
74+
) -> StorageResult<Option<f32>>;
7675

7776
/// Get the joint statistics for a list of attributes.
7877
///
@@ -82,13 +81,13 @@ pub trait CostModelStorageLayer {
8281
attr_ids: Vec<Self::AttrId>,
8382
stat_type: i32,
8483
epoch_id: Option<Self::EpochId>,
85-
) -> CostModelStorageResult<Option<f32>>;
84+
) -> StorageResult<Option<f32>>;
8685

8786
async fn get_cost_analysis(
8887
&self,
8988
expr_id: Self::ExprId,
9089
epoch_id: Self::EpochId,
91-
) -> CostModelStorageResult<Option<i32>>;
90+
) -> StorageResult<Option<i32>>;
9291

93-
async fn get_cost(&self, expr_id: Self::ExprId) -> CostModelStorageResult<Option<i32>>;
92+
async fn get_cost(&self, expr_id: Self::ExprId) -> StorageResult<Option<i32>>;
9493
}
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(dead_code, unused_imports, unused_variables)]
22

3-
use crate::{BackendManager, CostModelStorageLayer, CostModelStorageResult};
3+
use crate::{BackendManager, CostModelStorageLayer, StorageResult};
44

55
use super::interface::CatalogSource;
66

@@ -16,23 +16,19 @@ impl CostModelStorageLayer for BackendManager {
1616
&mut self,
1717
source: String,
1818
data: String,
19-
) -> CostModelStorageResult<Self::EpochId> {
19+
) -> StorageResult<Self::EpochId> {
2020
todo!()
2121
}
2222

2323
async fn update_stats_from_catalog(
2424
&self,
2525
c: CatalogSource,
2626
epoch_id: Self::EpochId,
27-
) -> CostModelStorageResult<()> {
27+
) -> StorageResult<()> {
2828
todo!()
2929
}
3030

31-
async fn update_stats(
32-
&self,
33-
stats: i32,
34-
epoch_id: Self::EpochId,
35-
) -> CostModelStorageResult<()> {
31+
async fn update_stats(&self, stats: i32, epoch_id: Self::EpochId) -> StorageResult<()> {
3632
todo!()
3733
}
3834

@@ -41,60 +37,54 @@ impl CostModelStorageLayer for BackendManager {
4137
expr_id: Self::ExprId,
4238
cost: i32,
4339
epoch_id: Self::EpochId,
44-
) -> CostModelStorageResult<()> {
40+
) -> StorageResult<()> {
4541
todo!()
4642
}
4743

4844
async fn store_expr_stats_mappings(
4945
&self,
5046
expr_id: Self::ExprId,
5147
stat_ids: Vec<Self::StatId>,
52-
) -> CostModelStorageResult<()> {
48+
) -> StorageResult<()> {
5349
todo!()
5450
}
5551

56-
#[doc = " Get the statistics for a given table."]
57-
#[doc = " If `epoch_id` is None, it will return the latest statistics."]
5852
async fn get_stats_for_table(
5953
&self,
6054
table_id: i32,
6155
stat_type: i32,
6256
epoch_id: Option<Self::EpochId>,
63-
) -> CostModelStorageResult<Option<f32>> {
57+
) -> StorageResult<Option<f32>> {
6458
todo!()
6559
}
6660

67-
#[doc = " Get the statistics for a given attribute."]
68-
#[doc = " If `epoch_id` is None, it will return the latest statistics."]
6961
async fn get_stats_for_attr(
7062
&self,
7163
attr_id: i32,
7264
stat_type: i32,
7365
epoch_id: Option<Self::EpochId>,
74-
) -> CostModelStorageResult<Option<f32>> {
66+
) -> StorageResult<Option<f32>> {
7567
todo!()
7668
}
7769

78-
#[doc = " Get the joint statistics for a list of attributes."]
79-
#[doc = " If `epoch_id` is None, it will return the latest statistics."]
8070
async fn get_stats_for_attrs(
8171
&self,
8272
attr_ids: Vec<i32>,
8373
stat_type: i32,
8474
epoch_id: Option<Self::EpochId>,
85-
) -> CostModelStorageResult<Option<f32>> {
75+
) -> StorageResult<Option<f32>> {
8676
todo!()
8777
}
8878

8979
async fn get_cost_analysis(
9080
&self,
9181
expr_id: Self::ExprId,
9282
epoch_id: Self::EpochId,
93-
) -> CostModelStorageResult<Option<i32>> {
83+
) -> StorageResult<Option<i32>> {
9484
todo!()
9585
}
9686

97-
async fn get_cost(&self, expr_id: Self::ExprId) -> CostModelStorageResult<Option<i32>> {
87+
async fn get_cost(&self, expr_id: Self::ExprId) -> StorageResult<Option<i32>> {
9888
todo!()
9989
}
10090
}

optd-persistent/src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,28 @@ mod migrator;
1313
mod cost_model;
1414
pub use cost_model::interface::CostModelStorageLayer;
1515

16-
pub type CostModelStorageResult<T> = Result<T, CostModelError>;
16+
pub type StorageResult<T> = Result<T, BackendError>;
1717

1818
pub enum CostModelError {
1919
// TODO: Add more error types
20+
UnknownStatisticType,
21+
}
22+
23+
pub enum BackendError {
24+
CostModel(CostModelError),
2025
Database(DbErr),
26+
// Add other variants as needed for different error types
27+
}
28+
29+
impl From<CostModelError> for BackendError {
30+
fn from(value: CostModelError) -> Self {
31+
BackendError::CostModel(value)
32+
}
2133
}
2234

23-
impl From<DbErr> for CostModelError {
35+
impl From<DbErr> for BackendError {
2436
fn from(value: DbErr) -> Self {
25-
CostModelError::Database(value)
37+
BackendError::Database(value)
2638
}
2739
}
2840

@@ -33,7 +45,7 @@ pub struct BackendManager {
3345

3446
impl BackendManager {
3547
/// Creates a new `BackendManager`.
36-
pub async fn new() -> CostModelStorageResult<Self> {
48+
pub async fn new() -> StorageResult<Self> {
3749
Ok(Self {
3850
db: Database::connect(DATABASE_URL).await?,
3951
latest_epoch_id: AtomicUsize::new(0),
@@ -44,6 +56,7 @@ impl BackendManager {
4456
pub const DATABASE_URL: &str = "sqlite:./sqlite.db?mode=rwc";
4557
pub const DATABASE_FILE: &str = "./sqlite.db";
4658
pub const TEST_DATABASE_URL: &str = "sqlite:./test.db?mode=rwc";
59+
pub const TEST_DATABASE_FILE: &str = "./test.db";
4760

4861
pub async fn migrate(db: &DatabaseConnection) -> Result<(), DbErr> {
4962
Migrator::refresh(db).await

0 commit comments

Comments
 (0)