From 3508fddd7451ba3afa6e324b96650eb3ecc0f29d Mon Sep 17 00:00:00 2001 From: fys <40801205+fengys1996@users.noreply.github.com> Date: Mon, 7 Jul 2025 11:30:57 +0800 Subject: [PATCH] feat: support show triggers (#6465) * feat: support show triggers * add enterprise feature * chore: remove unused error --- src/operator/Cargo.toml | 2 +- src/operator/src/error.rs | 9 --------- src/operator/src/statement/show.rs | 8 +++++--- src/query/Cargo.toml | 3 +++ src/query/src/sql.rs | 31 ++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/operator/Cargo.toml b/src/operator/Cargo.toml index f1d2c641e6..8443213d85 100644 --- a/src/operator/Cargo.toml +++ b/src/operator/Cargo.toml @@ -6,7 +6,7 @@ license.workspace = true [features] testing = [] -enterprise = ["common-meta/enterprise", "sql/enterprise"] +enterprise = ["common-meta/enterprise", "sql/enterprise", "query/enterprise"] [lints] workspace = true diff --git a/src/operator/src/error.rs b/src/operator/src/error.rs index 137c72571c..f929c91629 100644 --- a/src/operator/src/error.rs +++ b/src/operator/src/error.rs @@ -829,13 +829,6 @@ pub enum Error { location: Location, }, - #[cfg(feature = "enterprise")] - #[snafu(display("Trigger related operations are not currently supported"))] - UnsupportedTrigger { - #[snafu(implicit)] - location: Location, - }, - #[snafu(display("Invalid time index type: {}", ty))] InvalidTimeIndexType { ty: arrow::datatypes::DataType, @@ -902,8 +895,6 @@ impl ErrorExt for Error { Error::NotSupported { .. } | Error::ShowCreateTableBaseOnly { .. } | Error::SchemaReadOnly { .. } => StatusCode::Unsupported, - #[cfg(feature = "enterprise")] - Error::UnsupportedTrigger { .. } => StatusCode::Unsupported, Error::TableMetadataManager { source, .. } => source.status_code(), Error::ParseSql { source, .. } => source.status_code(), Error::InvalidateTableCache { source, .. } => source.status_code(), diff --git a/src/operator/src/statement/show.rs b/src/operator/src/statement/show.rs index f2f05345a7..5251872559 100644 --- a/src/operator/src/statement/show.rs +++ b/src/operator/src/statement/show.rs @@ -231,10 +231,12 @@ impl StatementExecutor { #[tracing::instrument(skip_all)] pub(super) async fn show_triggers( &self, - _stmt: sql::statements::show::trigger::ShowTriggers, - _query_ctx: QueryContextRef, + stmt: sql::statements::show::trigger::ShowTriggers, + query_ctx: QueryContextRef, ) -> Result { - crate::error::UnsupportedTriggerSnafu.fail() + query::sql::show_triggers(stmt, &self.query_engine, &self.catalog_manager, query_ctx) + .await + .context(ExecuteStatementSnafu) } #[tracing::instrument(skip_all)] diff --git a/src/query/Cargo.toml b/src/query/Cargo.toml index 53f66034e7..df4bd0f299 100644 --- a/src/query/Cargo.toml +++ b/src/query/Cargo.toml @@ -7,6 +7,9 @@ license.workspace = true [lints] workspace = true +[features] +enterprise = [] + [dependencies] ahash.workspace = true api.workspace = true diff --git a/src/query/src/sql.rs b/src/query/src/sql.rs index a30ef071ac..23adae2610 100644 --- a/src/query/src/sql.rs +++ b/src/query/src/sql.rs @@ -950,6 +950,37 @@ pub async fn show_flows( .await } +#[cfg(feature = "enterprise")] +pub async fn show_triggers( + stmt: sql::statements::show::trigger::ShowTriggers, + query_engine: &QueryEngineRef, + catalog_manager: &CatalogManagerRef, + query_ctx: QueryContextRef, +) -> Result { + use catalog::information_schema::TRIGGER_LIST; + + const TRIGGER_NAME: &str = "trigger_name"; + const TRIGGERS_COLUMN: &str = "Triggers"; + + let projects = vec![(TRIGGER_NAME, TRIGGERS_COLUMN)]; + let like_field = Some(TRIGGER_NAME); + let sort = vec![col(TRIGGER_NAME).sort(true, true)]; + + query_from_information_schema_table( + query_engine, + catalog_manager, + query_ctx, + TRIGGER_LIST, + vec![], + projects, + vec![], + like_field, + sort, + stmt.kind, + ) + .await +} + pub fn show_create_flow( flow_name: ObjectName, flow_val: FlowInfoValue,