use crate::{response_writer::Logger, time::TimeRange};
use anyhow::Result;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
use datafusion::{arrow::datatypes::Schema, logical_expr::Expr};
use micromegas_ingestion::data_lake_connection::DataLakeConnection;
use std::sync::Arc;
use super::partition_cache::QueryPartitionProvider;
#[async_trait]
pub trait PartitionSpec: Send + Sync {
fn get_source_data_hash(&self) -> Vec<u8>;
async fn write(&self, lake: Arc<DataLakeConnection>, logger: Arc<dyn Logger>) -> Result<()>;
}
#[derive(Debug, Clone)]
pub struct ViewMetadata {
pub view_set_name: Arc<String>,
pub view_instance_id: Arc<String>,
pub file_schema_hash: Vec<u8>,
}
#[async_trait]
pub trait View: std::fmt::Debug + Send + Sync {
fn get_view_set_name(&self) -> Arc<String>;
fn get_view_instance_id(&self) -> Arc<String>;
async fn make_batch_partition_spec(
&self,
lake: Arc<DataLakeConnection>,
part_provider: Arc<dyn QueryPartitionProvider>,
begin_insert: DateTime<Utc>,
end_insert: DateTime<Utc>,
) -> Result<Arc<dyn PartitionSpec>>;
fn get_file_schema_hash(&self) -> Vec<u8>;
fn get_file_schema(&self) -> Arc<Schema>;
async fn jit_update(
&self,
lake: Arc<DataLakeConnection>,
query_range: Option<TimeRange>,
) -> Result<()>;
fn make_time_filter(&self, _begin: DateTime<Utc>, _end: DateTime<Utc>) -> Result<Vec<Expr>>;
}
impl dyn View {
pub fn get_meta(&self) -> ViewMetadata {
ViewMetadata {
view_set_name: self.get_view_set_name(),
view_instance_id: self.get_view_instance_id(),
file_schema_hash: self.get_file_schema_hash(),
}
}
}