udb/backend/plugins/
clickhouse.rs1use crate::backend::BackendKind;
7use crate::backend::plugin::{Backend, RegisterCtx};
8
9#[derive(Debug, Default)]
10pub struct ClickHousePlugin;
11
12pub static PLUGIN: ClickHousePlugin = ClickHousePlugin;
13
14#[async_trait::async_trait]
15impl Backend for ClickHousePlugin {
16 fn kind(&self) -> BackendKind {
17 BackendKind::Clickhouse
18 }
19
20 async fn register(&self, ctx: &mut RegisterCtx<'_>) {
21 crate::runtime::core::setup_data::register_clickhouse(ctx).await;
22 }
23
24 fn generate_artifacts(
25 &self,
26 manifest: &crate::generation::CatalogManifest,
27 sql_config: &crate::generation::sql::SqlGenerationConfig,
28 ) -> Result<Vec<crate::generation::GeneratedArtifact>, String> {
29 crate::generation::backends::generate_clickhouse_artifacts(manifest, sql_config)
30 .map_err(|err| err.to_string())
31 }
32}
33
34impl crate::runtime::executors::handle::DispatchFactory for ClickHousePlugin {
35 fn build_dispatch_executor(
36 &self,
37 runtime: &crate::runtime::core::DataBrokerRuntime,
38 instance: Option<&str>,
39 write: bool,
40 _context: Option<&crate::broker::RequestContext>,
41 ) -> Result<crate::runtime::executors::handle::DispatchExecutor, tonic::Status> {
42 let routed = if write {
43 instance.or_else(|| runtime.choose_instance_name("clickhouse", true))
44 } else {
45 instance
46 };
47 Ok(
48 crate::runtime::executors::handle::DispatchExecutor::ClickHouse(
49 runtime.clickhouse_for_instance(routed)?.clone(),
50 ),
51 )
52 }
53}