1use std::collections::HashMap;
18
19use common_meta::key::flow::flow_state::FlowStat;
20use session::context::QueryContext;
21use table::metadata::TableId;
22
23use crate::Error;
24pub type FlowId = u64;
27pub type TableName = [String; 3];
28
29#[derive(Clone)]
30pub struct FlowAuthHeader {
31 auth_schema: api::v1::auth_header::AuthScheme,
32}
33
34impl std::fmt::Debug for FlowAuthHeader {
35 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36 match self.auth() {
37 api::v1::auth_header::AuthScheme::Basic(basic) => f
38 .debug_struct("Basic")
39 .field("username", &basic.username)
40 .field("password", &"<RETRACTED>")
41 .finish(),
42 api::v1::auth_header::AuthScheme::Token(_) => f
43 .debug_struct("Token")
44 .field("token", &"<RETRACTED>")
45 .finish(),
46 }
47 }
48}
49
50impl FlowAuthHeader {
51 pub fn from_user_pwd(username: &str, pwd: &str) -> Self {
52 Self {
53 auth_schema: api::v1::auth_header::AuthScheme::Basic(api::v1::Basic {
54 username: username.to_string(),
55 password: pwd.to_string(),
56 }),
57 }
58 }
59
60 pub fn auth(&self) -> &api::v1::auth_header::AuthScheme {
61 &self.auth_schema
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct CreateFlowArgs {
68 pub flow_id: FlowId,
69 pub sink_table_name: TableName,
70 pub source_table_ids: Vec<TableId>,
71 pub create_if_not_exists: bool,
72 pub or_replace: bool,
73 pub expire_after: Option<i64>,
74 pub eval_interval: Option<i64>,
75 pub comment: Option<String>,
76 pub sql: String,
77 pub flow_options: HashMap<String, String>,
78 pub query_ctx: Option<QueryContext>,
79}
80
81pub trait FlowEngine {
82 async fn create_flow(&self, args: CreateFlowArgs) -> Result<Option<FlowId>, Error>;
84 async fn remove_flow(&self, flow_id: FlowId) -> Result<(), Error>;
86 async fn flush_flow(&self, flow_id: FlowId) -> Result<usize, Error>;
88 async fn flow_exist(&self, flow_id: FlowId) -> Result<bool, Error>;
90 async fn list_flows(&self) -> Result<impl IntoIterator<Item = FlowId>, Error>;
92 async fn handle_flow_inserts(
94 &self,
95 request: api::v1::region::InsertRequests,
96 ) -> Result<(), Error>;
97
98 async fn handle_mark_window_dirty(
99 &self,
100 req: api::v1::flow::DirtyWindowRequests,
101 ) -> Result<(), Error>;
102}
103
104pub trait FlowStatProvider {
106 async fn flow_stat(&self) -> FlowStat;
108}