|
| 1 | +#![allow(dead_code, unused_imports)] |
| 2 | + |
| 3 | +use crate::entities::cascades_group; |
| 4 | +use crate::entities::event::Model as event_model; |
| 5 | +use crate::entities::logical_expression; |
| 6 | +use crate::entities::physical_expression; |
| 7 | +use crate::StorageResult; |
| 8 | +use sea_orm::*; |
| 9 | +use sea_orm_migration::prelude::*; |
| 10 | +use serde_json::json; |
| 11 | +use std::sync::Arc; |
| 12 | + |
| 13 | +pub enum CatalogSource { |
| 14 | + Iceberg(), |
| 15 | +} |
| 16 | + |
| 17 | +#[trait_variant::make(Send)] |
| 18 | +pub trait CostModelStorageLayer { |
| 19 | + type GroupId; |
| 20 | + type TableId; |
| 21 | + type AttrId; |
| 22 | + type ExprId; |
| 23 | + type EpochId; |
| 24 | + type StatId; |
| 25 | + |
| 26 | + // TODO: Change EpochId to event::Model::epoch_id |
| 27 | + async fn create_new_epoch( |
| 28 | + &mut self, |
| 29 | + source: String, |
| 30 | + data: String, |
| 31 | + ) -> StorageResult<Self::EpochId>; |
| 32 | + |
| 33 | + async fn update_stats_from_catalog( |
| 34 | + &self, |
| 35 | + c: CatalogSource, |
| 36 | + epoch_id: Self::EpochId, |
| 37 | + ) -> StorageResult<()>; |
| 38 | + |
| 39 | + // i32 in `stats:i32` is a placeholder for the stats type |
| 40 | + async fn update_stats(&self, stats: i32, epoch_id: Self::EpochId) -> StorageResult<()>; |
| 41 | + |
| 42 | + async fn store_cost( |
| 43 | + &self, |
| 44 | + expr_id: Self::ExprId, |
| 45 | + cost: i32, |
| 46 | + epoch_id: Self::EpochId, |
| 47 | + ) -> StorageResult<()>; |
| 48 | + |
| 49 | + async fn store_expr_stats_mappings( |
| 50 | + &self, |
| 51 | + expr_id: Self::ExprId, |
| 52 | + stat_ids: Vec<Self::StatId>, |
| 53 | + ) -> StorageResult<()>; |
| 54 | + |
| 55 | + /// Get the statistics for a given table. |
| 56 | + /// |
| 57 | + /// If `epoch_id` is None, it will return the latest statistics. |
| 58 | + async fn get_stats_for_table( |
| 59 | + &self, |
| 60 | + table_id: Self::TableId, |
| 61 | + // TODO: Add enum for stat_type |
| 62 | + stat_type: i32, |
| 63 | + epoch_id: Option<Self::EpochId>, |
| 64 | + ) -> StorageResult<Option<f32>>; |
| 65 | + |
| 66 | + /// Get the statistics for a given attribute. |
| 67 | + /// |
| 68 | + /// If `epoch_id` is None, it will return the latest statistics. |
| 69 | + async fn get_stats_for_attr( |
| 70 | + &self, |
| 71 | + attr_id: Self::AttrId, |
| 72 | + stat_type: i32, |
| 73 | + epoch_id: Option<Self::EpochId>, |
| 74 | + ) -> StorageResult<Option<f32>>; |
| 75 | + |
| 76 | + /// Get the joint statistics for a list of attributes. |
| 77 | + /// |
| 78 | + /// If `epoch_id` is None, it will return the latest statistics. |
| 79 | + async fn get_stats_for_attrs( |
| 80 | + &self, |
| 81 | + attr_ids: Vec<Self::AttrId>, |
| 82 | + stat_type: i32, |
| 83 | + epoch_id: Option<Self::EpochId>, |
| 84 | + ) -> StorageResult<Option<f32>>; |
| 85 | + |
| 86 | + async fn get_cost_analysis( |
| 87 | + &self, |
| 88 | + expr_id: Self::ExprId, |
| 89 | + epoch_id: Self::EpochId, |
| 90 | + ) -> StorageResult<Option<i32>>; |
| 91 | + |
| 92 | + async fn get_cost(&self, expr_id: Self::ExprId) -> StorageResult<Option<i32>>; |
| 93 | +} |
0 commit comments