1use std::pin::Pin;
16use std::sync::Arc;
17use std::task::{Context, Poll};
18
19use futures::stream::{self, BoxStream};
20use futures::{Stream, StreamExt};
21use itertools::Itertools;
22use pgwire::pg_field_descriptor::PgFieldDescriptor;
23use pgwire::pg_response::StatementType::{self, ABORT, BEGIN, COMMIT, ROLLBACK, START_TRANSACTION};
24use pgwire::pg_response::{PgResponse, PgResponseBuilder, RowSetResult};
25use pgwire::pg_server::BoxedError;
26use pgwire::types::{Format, Row};
27use risingwave_common::catalog::{AlterDatabaseParam, ICEBERG_SINK_PREFIX};
28use risingwave_common::types::Fields;
29use risingwave_common::util::iter_util::ZipEqFast;
30use risingwave_common::{bail, bail_not_implemented};
31use risingwave_pb::meta::PbThrottleTarget;
32use risingwave_sqlparser::ast::*;
33use thiserror_ext::AsReport;
34use util::get_table_catalog_by_table_name;
35
36use self::util::{DataChunkToRowSetAdapter, SourceSchemaCompatExt};
37use crate::catalog::table_catalog::TableType;
38use crate::error::{ErrorCode, Result};
39use crate::handler::cancel_job::handle_cancel;
40use crate::handler::kill_process::handle_kill;
41use crate::scheduler::{DistributedQueryStream, LocalQueryStream};
42use crate::session::SessionImpl;
43use crate::utils::WithOptions;
44
45mod alter_compaction_group;
46mod alter_connection_props;
47mod alter_database_param;
48mod alter_mv;
49mod alter_owner;
50mod alter_parallelism;
51mod alter_rename;
52mod alter_resource_group;
53mod alter_secret;
54mod alter_set_schema;
55mod alter_sink_props;
56mod alter_source_column;
57mod alter_source_props;
58mod alter_source_with_sr;
59mod alter_streaming_config;
60mod alter_streaming_enable_unaligned_join;
61mod alter_streaming_rate_limit;
62mod alter_subscription_retention;
63mod alter_swap_rename;
64mod alter_system;
65mod alter_table_column;
66pub mod alter_table_drop_connector;
67pub mod alter_table_props;
68mod alter_table_with_sr;
69pub mod alter_user;
70mod alter_utils;
71mod alter_watermark;
72mod backup;
73pub mod cancel_job;
74pub(crate) mod cdc;
75pub mod close_cursor;
76mod comment;
77pub mod create_aggregate;
78pub mod create_connection;
79mod create_database;
80pub mod create_function;
81pub mod create_index;
82pub mod create_mv;
83pub mod create_schema;
84pub mod create_secret;
85pub mod create_sink;
86pub mod create_source;
87pub mod create_sql_function;
88pub mod create_subscription;
89pub mod create_table;
90pub mod create_table_as;
91pub mod create_user;
92pub mod create_view;
93pub mod declare_cursor;
94mod delete_meta_snapshot;
95pub mod describe;
96pub mod discard;
97mod drop_connection;
98mod drop_database;
99pub mod drop_function;
100mod drop_index;
101pub mod drop_mv;
102mod drop_schema;
103pub mod drop_secret;
104pub mod drop_sink;
105pub mod drop_source;
106pub mod drop_subscription;
107pub mod drop_table;
108pub mod drop_user;
109mod drop_view;
110pub mod explain;
111pub mod explain_analyze_stream_job;
112pub mod extended_handle;
113pub mod fetch_cursor;
114mod flush;
115pub mod handle_privilege;
116pub mod kill_process;
117mod prepared_statement;
118pub mod privilege;
119pub mod query;
120mod recover;
121mod refresh;
122mod reset_source;
123pub mod show;
124mod transaction;
125mod use_db;
126pub mod util;
127pub mod vacuum;
128pub mod variable;
129mod wait;
130
131fn rate_limit_type_to_throttle_type(
132 rate_limit_type: AlterRateLimitType,
133) -> risingwave_pb::common::PbThrottleType {
134 match rate_limit_type {
135 AlterRateLimitType::Source => risingwave_pb::common::PbThrottleType::Source,
136 AlterRateLimitType::Backfill => risingwave_pb::common::PbThrottleType::Backfill,
137 AlterRateLimitType::Dml => risingwave_pb::common::PbThrottleType::Dml,
138 AlterRateLimitType::Sink => risingwave_pb::common::PbThrottleType::Sink,
139 }
140}
141
142fn ensure_rate_limit_type_supported(
143 rate_limit: &AlterRateLimit,
144 supported_types: &[AlterRateLimitType],
145 target: &str,
146) -> Result<()> {
147 if supported_types.contains(&rate_limit.rate_limit_type) {
148 Ok(())
149 } else {
150 Err(ErrorCode::InvalidInputSyntax(format!(
151 "ALTER {target} SET {} is not supported",
152 rate_limit.rate_limit_type
153 ))
154 .into())
155 }
156}
157
158pub use alter_table_column::{
159 fetch_table_catalog_for_alter, get_new_table_definition_for_cdc_table, get_replace_table_plan,
160};
161
162pub type RwPgResponseBuilder = PgResponseBuilder<PgResponseStream>;
164
165pub type RwPgResponse = PgResponse<PgResponseStream>;
167
168#[easy_ext::ext(RwPgResponseBuilderExt)]
169impl RwPgResponseBuilder {
170 pub fn rows<T: Fields>(self, rows: impl IntoIterator<Item = T>) -> Self {
172 let fields = T::fields();
173 self.values(
174 rows.into_iter()
175 .map(|row| {
176 Row::new(
177 row.into_owned_row()
178 .into_iter()
179 .zip_eq_fast(&fields)
180 .map(|(datum, (_, ty))| {
181 datum.map(|scalar| {
182 scalar.as_scalar_ref_impl().text_format(ty).into()
183 })
184 })
185 .collect(),
186 )
187 })
188 .collect_vec()
189 .into(),
190 fields_to_descriptors(fields),
191 )
192 }
193}
194
195pub fn fields_to_descriptors(
196 fields: Vec<(&str, risingwave_common::types::DataType)>,
197) -> Vec<PgFieldDescriptor> {
198 fields
199 .iter()
200 .map(|(name, ty)| PgFieldDescriptor::new(name.to_string(), ty.to_oid(), ty.type_len()))
201 .collect()
202}
203
204pub enum PgResponseStream {
205 LocalQuery(DataChunkToRowSetAdapter<LocalQueryStream>),
206 DistributedQuery(DataChunkToRowSetAdapter<DistributedQueryStream>),
207 Rows(BoxStream<'static, RowSetResult>),
208}
209
210impl Stream for PgResponseStream {
211 type Item = std::result::Result<Vec<Row>, BoxedError>;
212
213 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
214 match &mut *self {
215 PgResponseStream::LocalQuery(inner) => inner.poll_next_unpin(cx),
216 PgResponseStream::DistributedQuery(inner) => inner.poll_next_unpin(cx),
217 PgResponseStream::Rows(inner) => inner.poll_next_unpin(cx),
218 }
219 }
220}
221
222impl From<Vec<Row>> for PgResponseStream {
223 fn from(rows: Vec<Row>) -> Self {
224 Self::Rows(stream::iter(vec![Ok(rows)]).boxed())
225 }
226}
227
228#[derive(Clone)]
229pub struct HandlerArgs {
230 pub session: Arc<SessionImpl>,
231 pub sql: Arc<str>,
232 pub normalized_sql: String,
233 pub with_options: WithOptions,
234}
235
236impl HandlerArgs {
237 pub fn new(session: Arc<SessionImpl>, stmt: &Statement, sql: Arc<str>) -> Result<Self> {
238 Ok(Self {
239 session,
240 sql,
241 with_options: WithOptions::try_from(stmt)?,
242 normalized_sql: Self::normalize_sql(stmt),
243 })
244 }
245
246 fn normalize_sql(stmt: &Statement) -> String {
252 let mut stmt = stmt.clone();
253 match &mut stmt {
254 Statement::CreateView {
255 or_replace,
256 if_not_exists,
257 ..
258 } => {
259 *or_replace = false;
260 *if_not_exists = false;
261 }
262 Statement::CreateTable {
263 or_replace,
264 if_not_exists,
265 ..
266 } => {
267 *or_replace = false;
268 *if_not_exists = false;
269 }
270 Statement::CreateIndex { if_not_exists, .. } => {
271 *if_not_exists = false;
272 }
273 Statement::CreateSource {
274 stmt: CreateSourceStatement { if_not_exists, .. },
275 ..
276 } => {
277 *if_not_exists = false;
278 }
279 Statement::CreateSink {
280 stmt:
281 CreateSinkStatement {
282 or_replace,
283 if_not_exists,
284 ..
285 },
286 } => {
287 *or_replace = false;
288 *if_not_exists = false;
289 }
290 Statement::CreateSubscription {
291 stmt: CreateSubscriptionStatement { if_not_exists, .. },
292 } => {
293 *if_not_exists = false;
294 }
295 Statement::CreateConnection {
296 stmt: CreateConnectionStatement { if_not_exists, .. },
297 } => {
298 *if_not_exists = false;
299 }
300 _ => {}
301 }
302 stmt.to_string()
303 }
304}
305
306pub async fn handle(
307 session: Arc<SessionImpl>,
308 stmt: Statement,
309 sql: Arc<str>,
310 formats: Vec<Format>,
311) -> Result<RwPgResponse> {
312 session.clear_cancel_query_flag();
313 let _guard = session.txn_begin_implicit();
314 let handler_args = HandlerArgs::new(session, &stmt, sql)?;
315
316 check_ban_ddl_for_iceberg_engine_table(handler_args.session.clone(), &stmt)?;
317
318 match stmt {
319 Statement::Explain {
320 statement,
321 analyze,
322 options,
323 } => {
324 Box::pin(explain::handle_explain(
325 handler_args,
326 *statement,
327 options,
328 analyze,
329 ))
330 .await
331 }
332 Statement::ExplainAnalyzeStreamJob {
333 target,
334 duration_secs,
335 } => {
336 explain_analyze_stream_job::handle_explain_analyze_stream_job(
337 handler_args,
338 target,
339 duration_secs,
340 )
341 .await
342 }
343 Statement::CreateSource { stmt } => {
344 create_source::handle_create_source(handler_args, stmt).await
345 }
346 Statement::CreateSink { stmt } => {
347 Box::pin(create_sink::handle_create_sink(handler_args, stmt, false)).await
348 }
349 Statement::CreateSubscription { stmt } => {
350 create_subscription::handle_create_subscription(handler_args, stmt).await
351 }
352 Statement::CreateConnection { stmt } => {
353 create_connection::handle_create_connection(handler_args, stmt).await
354 }
355 Statement::CreateSecret { stmt } => {
356 create_secret::handle_create_secret(handler_args, stmt).await
357 }
358 Statement::CreateFunction {
359 or_replace,
360 temporary,
361 if_not_exists,
362 name,
363 args,
364 returns,
365 params,
366 with_options,
367 } => {
368 if params.language.is_none()
371 || !params
372 .language
373 .as_ref()
374 .unwrap()
375 .real_value()
376 .eq_ignore_ascii_case("sql")
377 {
378 create_function::handle_create_function(
379 handler_args,
380 or_replace,
381 temporary,
382 if_not_exists,
383 name,
384 args,
385 returns,
386 params,
387 with_options,
388 )
389 .await
390 } else {
391 create_sql_function::handle_create_sql_function(
392 handler_args,
393 or_replace,
394 temporary,
395 if_not_exists,
396 name,
397 args,
398 returns,
399 params,
400 with_options,
401 )
402 .await
403 }
404 }
405 Statement::CreateAggregate {
406 or_replace,
407 if_not_exists,
408 name,
409 args,
410 returns,
411 params,
412 ..
413 } => {
414 create_aggregate::handle_create_aggregate(
415 handler_args,
416 or_replace,
417 if_not_exists,
418 name,
419 args,
420 returns,
421 params,
422 )
423 .await
424 }
425 Statement::CreateTable {
426 name,
427 columns,
428 wildcard_idx,
429 constraints,
430 query,
431 with_options: _, or_replace,
434 temporary,
435 if_not_exists,
436 format_encode,
437 source_watermarks,
438 append_only,
439 on_conflict,
440 with_version_columns,
441 cdc_table_info,
442 include_column_options,
443 webhook_info,
444 engine,
445 } => {
446 if or_replace {
447 bail_not_implemented!("CREATE OR REPLACE TABLE");
448 }
449 if temporary {
450 bail_not_implemented!("CREATE TEMPORARY TABLE");
451 }
452 if let Some(query) = query {
453 return create_table_as::handle_create_as(
454 handler_args,
455 name,
456 if_not_exists,
457 query,
458 columns,
459 append_only,
460 on_conflict,
461 with_version_columns
462 .iter()
463 .map(|col| col.real_value())
464 .collect(),
465 engine,
466 )
467 .await;
468 }
469 let format_encode = format_encode.map(|s| s.into_v2_with_warning());
470 Box::pin(create_table::handle_create_table(
471 handler_args,
472 name,
473 columns,
474 wildcard_idx,
475 constraints,
476 if_not_exists,
477 format_encode,
478 source_watermarks,
479 append_only,
480 on_conflict,
481 with_version_columns
482 .iter()
483 .map(|col| col.real_value())
484 .collect(),
485 cdc_table_info,
486 include_column_options,
487 webhook_info,
488 engine,
489 ))
490 .await
491 }
492 Statement::CreateDatabase {
493 db_name,
494 if_not_exists,
495 owner,
496 resource_group,
497 barrier_interval_ms,
498 checkpoint_frequency,
499 } => {
500 create_database::handle_create_database(
501 handler_args,
502 db_name,
503 if_not_exists,
504 owner,
505 resource_group,
506 barrier_interval_ms,
507 checkpoint_frequency,
508 )
509 .await
510 }
511 Statement::CreateSchema {
512 schema_name,
513 if_not_exists,
514 owner,
515 } => {
516 create_schema::handle_create_schema(handler_args, schema_name, if_not_exists, owner)
517 .await
518 }
519 Statement::CreateUser(stmt) => create_user::handle_create_user(handler_args, stmt).await,
520 Statement::DeclareCursor { stmt } => {
521 declare_cursor::handle_declare_cursor(handler_args, stmt).await
522 }
523 Statement::FetchCursor { stmt } => {
524 fetch_cursor::handle_fetch_cursor(handler_args, stmt, &formats).await
525 }
526 Statement::CloseCursor { stmt } => {
527 close_cursor::handle_close_cursor(handler_args, stmt).await
528 }
529 Statement::AlterUser(stmt) => alter_user::handle_alter_user(handler_args, stmt).await,
530 Statement::Grant { .. } => {
531 handle_privilege::handle_grant_privilege(handler_args, stmt).await
532 }
533 Statement::Revoke { .. } => {
534 handle_privilege::handle_revoke_privilege(handler_args, stmt).await
535 }
536 Statement::Describe { name, kind } => match kind {
537 DescribeKind::Fragments => {
538 describe::handle_describe_fragments(handler_args, name).await
539 }
540 DescribeKind::Plain => describe::handle_describe(handler_args, name),
541 },
542 Statement::DescribeFragment { fragment_id } => {
543 describe::handle_describe_fragment(handler_args, fragment_id.into()).await
544 }
545 Statement::Discard(..) => discard::handle_discard(handler_args),
546 Statement::ShowObjects {
547 object: show_object,
548 filter,
549 } => show::handle_show_object(handler_args, show_object, filter).await,
550 Statement::ShowCreateObject { create_type, name } => {
551 show::handle_show_create_object(handler_args, create_type, name)
552 }
553 Statement::ShowTransactionIsolationLevel => {
554 transaction::handle_show_isolation_level(handler_args)
555 }
556 Statement::Drop(DropStatement {
557 object_type,
558 object_name,
559 if_exists,
560 drop_mode,
561 }) => {
562 let cascade = if let AstOption::Some(DropMode::Cascade) = drop_mode {
563 match object_type {
564 ObjectType::MaterializedView
565 | ObjectType::View
566 | ObjectType::Sink
567 | ObjectType::Source
568 | ObjectType::Subscription
569 | ObjectType::Index
570 | ObjectType::Table
571 | ObjectType::Schema
572 | ObjectType::Connection
573 | ObjectType::Secret => true,
574 ObjectType::Database | ObjectType::User => {
575 bail_not_implemented!("DROP CASCADE");
576 }
577 }
578 } else {
579 false
580 };
581 match object_type {
582 ObjectType::Table => {
583 drop_table::handle_drop_table(handler_args, object_name, if_exists, cascade)
584 .await
585 }
586 ObjectType::MaterializedView => {
587 drop_mv::handle_drop_mv(handler_args, object_name, if_exists, cascade).await
588 }
589 ObjectType::Index => {
590 drop_index::handle_drop_index(handler_args, object_name, if_exists, cascade)
591 .await
592 }
593 ObjectType::Source => {
594 drop_source::handle_drop_source(handler_args, object_name, if_exists, cascade)
595 .await
596 }
597 ObjectType::Sink => {
598 drop_sink::handle_drop_sink(handler_args, object_name, if_exists, cascade).await
599 }
600 ObjectType::Subscription => {
601 drop_subscription::handle_drop_subscription(
602 handler_args,
603 object_name,
604 if_exists,
605 cascade,
606 )
607 .await
608 }
609 ObjectType::Database => {
610 drop_database::handle_drop_database(handler_args, object_name, if_exists).await
611 }
612 ObjectType::Schema => {
613 drop_schema::handle_drop_schema(handler_args, object_name, if_exists, cascade)
614 .await
615 }
616 ObjectType::User => {
617 drop_user::handle_drop_user(handler_args, object_name, if_exists).await
618 }
619 ObjectType::View => {
620 drop_view::handle_drop_view(handler_args, object_name, if_exists, cascade).await
621 }
622 ObjectType::Connection => {
623 drop_connection::handle_drop_connection(
624 handler_args,
625 object_name,
626 if_exists,
627 cascade,
628 )
629 .await
630 }
631 ObjectType::Secret => {
632 drop_secret::handle_drop_secret(handler_args, object_name, if_exists, cascade)
633 .await
634 }
635 }
636 }
637 Statement::DropFunction {
639 if_exists,
640 func_desc,
641 option,
642 } => {
643 drop_function::handle_drop_function(handler_args, if_exists, func_desc, option, false)
644 .await
645 }
646 Statement::DropAggregate {
647 if_exists,
648 func_desc,
649 option,
650 } => {
651 drop_function::handle_drop_function(handler_args, if_exists, func_desc, option, true)
652 .await
653 }
654 Statement::Query(_)
655 | Statement::Insert { .. }
656 | Statement::Delete { .. }
657 | Statement::Update { .. } => query::handle_query(handler_args, stmt, formats).await,
658 Statement::Copy {
659 entity: CopyEntity::Query(query),
660 target: CopyTarget::Stdout,
661 } => {
662 let response =
663 query::handle_query(handler_args, Statement::Query(query), vec![Format::Text])
664 .await?;
665 Ok(response.into_copy_query_to_stdout())
666 }
667 Statement::CreateView {
668 materialized,
669 if_not_exists,
670 name,
671 columns,
672 query,
673 with_options: _, or_replace, emit_mode,
676 } => {
677 if or_replace {
678 bail_not_implemented!("CREATE OR REPLACE VIEW");
679 }
680 if materialized {
681 create_mv::handle_create_mv(
682 handler_args,
683 if_not_exists,
684 name,
685 *query,
686 columns,
687 emit_mode,
688 )
689 .await
690 } else {
691 create_view::handle_create_view(handler_args, if_not_exists, name, columns, *query)
692 .await
693 }
694 }
695 Statement::Flush => flush::handle_flush(handler_args).await,
696 Statement::Wait(target) => wait::handle_wait(handler_args, target).await,
697 Statement::Backup => backup::handle_backup(handler_args).await,
698 Statement::DeleteMetaSnapshots { snapshot_ids } => {
699 delete_meta_snapshot::handle_delete_meta_snapshots(handler_args, snapshot_ids).await
700 }
701 Statement::Recover => recover::handle_recover(handler_args).await,
702 Statement::SetVariable {
703 local: _,
704 variable,
705 value,
706 } => {
707 if variable.real_value().eq_ignore_ascii_case("database") {
709 let x = variable::set_var_to_param_str(&value);
710 let res = use_db::handle_use_db(
711 handler_args,
712 ObjectName::from(vec![Ident::from_real_value(
713 x.as_deref().unwrap_or("default"),
714 )]),
715 )?;
716 let mut builder = RwPgResponse::builder(StatementType::SET_VARIABLE);
717 for notice in res.notices() {
718 builder = builder.notice(notice);
719 }
720 return Ok(builder.into());
721 }
722 variable::handle_set(handler_args, variable, value)
723 }
724 Statement::SetTimeZone { local: _, value } => {
725 variable::handle_set_time_zone(handler_args, value)
726 }
727 Statement::ShowVariable { variable } => variable::handle_show(handler_args, variable),
728 Statement::CreateIndex {
729 name,
730 table_name,
731 method,
732 columns,
733 include,
734 distributed_by,
735 unique,
736 if_not_exists,
737 with_properties: _,
738 } => {
739 if unique {
740 bail_not_implemented!("create unique index");
741 }
742
743 create_index::handle_create_index(
744 handler_args,
745 if_not_exists,
746 name,
747 table_name,
748 method,
749 columns.clone(),
750 include,
751 distributed_by,
752 )
753 .await
754 }
755 Statement::AlterDatabase { name, operation } => match operation {
756 AlterDatabaseOperation::RenameDatabase { database_name } => {
757 alter_rename::handle_rename_database(handler_args, name, database_name).await
758 }
759 AlterDatabaseOperation::ChangeOwner { new_owner_name } => {
760 alter_owner::handle_alter_owner(
761 handler_args,
762 name,
763 new_owner_name,
764 StatementType::ALTER_DATABASE,
765 None,
766 )
767 .await
768 }
769 AlterDatabaseOperation::SetParam(config_param) => {
770 let ConfigParam { param, value } = config_param;
771
772 let database_param = match param.real_value().to_uppercase().as_str() {
773 "BARRIER_INTERVAL_MS" => {
774 let barrier_interval_ms = match value {
775 SetVariableValue::Default => None,
776 SetVariableValue::Single(SetVariableValueSingle::Literal(
777 Value::Number(num),
778 )) => {
779 let num = num.parse::<u32>().map_err(|e| {
780 ErrorCode::InvalidInputSyntax(format!(
781 "barrier_interval_ms must be a u32 integer: {}",
782 e.as_report()
783 ))
784 })?;
785 Some(num)
786 }
787 _ => {
788 return Err(ErrorCode::InvalidInputSyntax(
789 "barrier_interval_ms must be a u32 integer or DEFAULT"
790 .to_owned(),
791 )
792 .into());
793 }
794 };
795 AlterDatabaseParam::BarrierIntervalMs(barrier_interval_ms)
796 }
797 "CHECKPOINT_FREQUENCY" => {
798 let checkpoint_frequency = match value {
799 SetVariableValue::Default => None,
800 SetVariableValue::Single(SetVariableValueSingle::Literal(
801 Value::Number(num),
802 )) => {
803 let num = num.parse::<u64>().map_err(|e| {
804 ErrorCode::InvalidInputSyntax(format!(
805 "checkpoint_frequency must be a u64 integer: {}",
806 e.as_report()
807 ))
808 })?;
809 Some(num)
810 }
811 _ => {
812 return Err(ErrorCode::InvalidInputSyntax(
813 "checkpoint_frequency must be a u64 integer or DEFAULT"
814 .to_owned(),
815 )
816 .into());
817 }
818 };
819 AlterDatabaseParam::CheckpointFrequency(checkpoint_frequency)
820 }
821 _ => {
822 return Err(ErrorCode::InvalidInputSyntax(format!(
823 "Unsupported database config parameter: {}",
824 param.real_value()
825 ))
826 .into());
827 }
828 };
829
830 alter_database_param::handle_alter_database_param(
831 handler_args,
832 name,
833 database_param,
834 )
835 .await
836 }
837 AlterDatabaseOperation::SetResourceGroup {
838 resource_group,
839 deferred,
840 } => {
841 alter_database_param::handle_alter_database_resource_group(
842 handler_args,
843 name,
844 resource_group,
845 deferred,
846 )
847 .await
848 }
849 },
850 Statement::AlterSchema { name, operation } => match operation {
851 AlterSchemaOperation::RenameSchema { schema_name } => {
852 alter_rename::handle_rename_schema(handler_args, name, schema_name).await
853 }
854 AlterSchemaOperation::ChangeOwner { new_owner_name } => {
855 alter_owner::handle_alter_owner(
856 handler_args,
857 name,
858 new_owner_name,
859 StatementType::ALTER_SCHEMA,
860 None,
861 )
862 .await
863 }
864 AlterSchemaOperation::SwapRenameSchema { target_schema } => {
865 alter_swap_rename::handle_swap_rename(
866 handler_args,
867 name,
868 target_schema,
869 StatementType::ALTER_SCHEMA,
870 )
871 .await
872 }
873 },
874 Statement::AlterTable { name, operation } => match operation {
875 AlterTableOperation::AddColumn { .. }
876 | AlterTableOperation::DropColumn { .. }
877 | AlterTableOperation::AlterColumn { .. } => {
878 Box::pin(alter_table_column::handle_alter_table_column(
879 handler_args,
880 name,
881 operation,
882 ))
883 .await
884 }
885 AlterTableOperation::AlterWatermark {
886 column_name,
887 expr,
888 with_ttl,
889 } => {
890 Box::pin(alter_watermark::handle_alter_watermark(
891 handler_args,
892 name,
893 column_name,
894 expr,
895 with_ttl,
896 ))
897 .await
898 }
899 AlterTableOperation::RenameTable { table_name } => {
900 alter_rename::handle_rename_table(handler_args, TableType::Table, name, table_name)
901 .await
902 }
903 AlterTableOperation::ChangeOwner { new_owner_name } => {
904 alter_owner::handle_alter_owner(
905 handler_args,
906 name,
907 new_owner_name,
908 StatementType::ALTER_TABLE,
909 None,
910 )
911 .await
912 }
913 AlterTableOperation::SetParallelism {
914 parallelism,
915 deferred,
916 } => {
917 alter_parallelism::handle_alter_parallelism(
918 handler_args,
919 name,
920 parallelism,
921 StatementType::ALTER_TABLE,
922 deferred,
923 )
924 .await
925 }
926 AlterTableOperation::SetBackfillParallelism {
927 parallelism,
928 deferred,
929 } => {
930 alter_parallelism::handle_alter_backfill_parallelism(
931 handler_args,
932 name,
933 parallelism,
934 StatementType::ALTER_TABLE,
935 deferred,
936 )
937 .await
938 }
939 AlterTableOperation::SetSchema { new_schema_name } => {
940 alter_set_schema::handle_alter_set_schema(
941 handler_args,
942 name,
943 new_schema_name,
944 StatementType::ALTER_TABLE,
945 None,
946 )
947 .await
948 }
949 AlterTableOperation::RefreshSchema => {
950 Box::pin(alter_table_with_sr::handle_refresh_schema(
951 handler_args,
952 name,
953 ))
954 .await
955 }
956 AlterTableOperation::AlterRateLimit(rate_limit) => {
957 ensure_rate_limit_type_supported(
958 &rate_limit,
959 &[
960 AlterRateLimitType::Source,
961 AlterRateLimitType::Backfill,
962 AlterRateLimitType::Dml,
963 ],
964 "TABLE",
965 )?;
966 alter_streaming_rate_limit::handle_alter_streaming_rate_limit(
967 handler_args,
968 PbThrottleTarget::Table,
969 rate_limit_type_to_throttle_type(rate_limit.rate_limit_type),
970 name,
971 rate_limit.rate_limit,
972 )
973 .await
974 }
975 AlterTableOperation::DropConnector => {
976 Box::pin(
977 alter_table_drop_connector::handle_alter_table_drop_connector(
978 handler_args,
979 name,
980 ),
981 )
982 .await
983 }
984 AlterTableOperation::SetConfig { entries } => {
985 alter_streaming_config::handle_alter_streaming_set_config(
986 handler_args,
987 name,
988 entries,
989 StatementType::ALTER_TABLE,
990 )
991 .await
992 }
993 AlterTableOperation::ResetConfig { keys } => {
994 alter_streaming_config::handle_alter_streaming_reset_config(
995 handler_args,
996 name,
997 keys,
998 StatementType::ALTER_TABLE,
999 )
1000 .await
1001 }
1002 AlterTableOperation::SwapRenameTable { target_table } => {
1003 alter_swap_rename::handle_swap_rename(
1004 handler_args,
1005 name,
1006 target_table,
1007 StatementType::ALTER_TABLE,
1008 )
1009 .await
1010 }
1011 AlterTableOperation::AlterConnectorProps { alter_props } => {
1012 alter_table_props::handle_alter_table_props(handler_args, name, alter_props).await
1013 }
1014 AlterTableOperation::AddConstraint { .. }
1015 | AlterTableOperation::DropConstraint { .. }
1016 | AlterTableOperation::RenameColumn { .. }
1017 | AlterTableOperation::ChangeColumn { .. }
1018 | AlterTableOperation::RenameConstraint { .. } => {
1019 bail_not_implemented!(
1020 "Unhandled statement: {}",
1021 Statement::AlterTable { name, operation }
1022 )
1023 }
1024 },
1025 Statement::AlterIndex { name, operation } => match operation {
1026 AlterIndexOperation::RenameIndex { index_name } => {
1027 alter_rename::handle_rename_index(handler_args, name, index_name).await
1028 }
1029 AlterIndexOperation::SetParallelism {
1030 parallelism,
1031 deferred,
1032 } => {
1033 alter_parallelism::handle_alter_parallelism(
1034 handler_args,
1035 name,
1036 parallelism,
1037 StatementType::ALTER_INDEX,
1038 deferred,
1039 )
1040 .await
1041 }
1042 AlterIndexOperation::SetBackfillParallelism {
1043 parallelism,
1044 deferred,
1045 } => {
1046 alter_parallelism::handle_alter_backfill_parallelism(
1047 handler_args,
1048 name,
1049 parallelism,
1050 StatementType::ALTER_INDEX,
1051 deferred,
1052 )
1053 .await
1054 }
1055 AlterIndexOperation::SetResourceGroup {
1056 resource_group,
1057 deferred,
1058 } => {
1059 alter_resource_group::handle_alter_resource_group(
1060 handler_args,
1061 name,
1062 resource_group,
1063 StatementType::ALTER_INDEX,
1064 deferred,
1065 )
1066 .await
1067 }
1068 AlterIndexOperation::SetConfig { entries } => {
1069 alter_streaming_config::handle_alter_streaming_set_config(
1070 handler_args,
1071 name,
1072 entries,
1073 StatementType::ALTER_INDEX,
1074 )
1075 .await
1076 }
1077 AlterIndexOperation::ResetConfig { keys } => {
1078 alter_streaming_config::handle_alter_streaming_reset_config(
1079 handler_args,
1080 name,
1081 keys,
1082 StatementType::ALTER_INDEX,
1083 )
1084 .await
1085 }
1086 },
1087 Statement::AlterView {
1088 materialized,
1089 name,
1090 operation,
1091 } => {
1092 let statement_type = if materialized {
1093 StatementType::ALTER_MATERIALIZED_VIEW
1094 } else {
1095 StatementType::ALTER_VIEW
1096 };
1097 match operation {
1098 AlterViewOperation::RenameView { view_name } => {
1099 if materialized {
1100 alter_rename::handle_rename_table(
1101 handler_args,
1102 TableType::MaterializedView,
1103 name,
1104 view_name,
1105 )
1106 .await
1107 } else {
1108 alter_rename::handle_rename_view(handler_args, name, view_name).await
1109 }
1110 }
1111 AlterViewOperation::SetParallelism {
1112 parallelism,
1113 deferred,
1114 } => {
1115 if !materialized {
1116 bail_not_implemented!("ALTER VIEW SET PARALLELISM");
1117 }
1118 alter_parallelism::handle_alter_parallelism(
1119 handler_args,
1120 name,
1121 parallelism,
1122 statement_type,
1123 deferred,
1124 )
1125 .await
1126 }
1127 AlterViewOperation::SetBackfillParallelism {
1128 parallelism,
1129 deferred,
1130 } => {
1131 if !materialized {
1132 bail_not_implemented!("ALTER VIEW SET BACKFILL PARALLELISM");
1133 }
1134 alter_parallelism::handle_alter_backfill_parallelism(
1135 handler_args,
1136 name,
1137 parallelism,
1138 statement_type,
1139 deferred,
1140 )
1141 .await
1142 }
1143 AlterViewOperation::SetResourceGroup {
1144 resource_group,
1145 deferred,
1146 } => {
1147 if !materialized {
1148 bail_not_implemented!("ALTER VIEW SET RESOURCE GROUP");
1149 }
1150 alter_resource_group::handle_alter_resource_group(
1151 handler_args,
1152 name,
1153 resource_group,
1154 statement_type,
1155 deferred,
1156 )
1157 .await
1158 }
1159 AlterViewOperation::ChangeOwner { new_owner_name } => {
1160 alter_owner::handle_alter_owner(
1161 handler_args,
1162 name,
1163 new_owner_name,
1164 statement_type,
1165 None,
1166 )
1167 .await
1168 }
1169 AlterViewOperation::SetSchema { new_schema_name } => {
1170 alter_set_schema::handle_alter_set_schema(
1171 handler_args,
1172 name,
1173 new_schema_name,
1174 statement_type,
1175 None,
1176 )
1177 .await
1178 }
1179 AlterViewOperation::AlterRateLimit(rate_limit) => {
1180 ensure_rate_limit_type_supported(
1181 &rate_limit,
1182 &[AlterRateLimitType::Backfill],
1183 "MATERIALIZED VIEW",
1184 )?;
1185 if !materialized {
1186 bail_not_implemented!("ALTER VIEW SET BACKFILL RATE LIMIT");
1187 }
1188 alter_streaming_rate_limit::handle_alter_streaming_rate_limit(
1189 handler_args,
1190 PbThrottleTarget::Mv,
1191 rate_limit_type_to_throttle_type(rate_limit.rate_limit_type),
1192 name,
1193 rate_limit.rate_limit,
1194 )
1195 .await
1196 }
1197 AlterViewOperation::SwapRenameView { target_view } => {
1198 alter_swap_rename::handle_swap_rename(
1199 handler_args,
1200 name,
1201 target_view,
1202 statement_type,
1203 )
1204 .await
1205 }
1206 AlterViewOperation::SetStreamingEnableUnalignedJoin { enable } => {
1207 if !materialized {
1208 bail!(
1209 "ALTER VIEW SET STREAMING_ENABLE_UNALIGNED_JOIN is not supported. Only supported for materialized views"
1210 );
1211 }
1212 alter_streaming_enable_unaligned_join::handle_alter_streaming_enable_unaligned_join(handler_args, name, enable).await
1213 }
1214 AlterViewOperation::AsQuery { query } => {
1215 if !materialized {
1216 bail_not_implemented!("ALTER VIEW AS QUERY");
1217 }
1218 if !cfg!(debug_assertions) {
1220 bail_not_implemented!("ALTER MATERIALIZED VIEW AS QUERY");
1221 }
1222 alter_mv::handle_alter_mv(handler_args, name, query).await
1223 }
1224 AlterViewOperation::SetConfig { entries } => {
1225 if !materialized {
1226 bail!("SET CONFIG is only supported for materialized views");
1227 }
1228 alter_streaming_config::handle_alter_streaming_set_config(
1229 handler_args,
1230 name,
1231 entries,
1232 statement_type,
1233 )
1234 .await
1235 }
1236 AlterViewOperation::ResetConfig { keys } => {
1237 if !materialized {
1238 bail!("RESET CONFIG is only supported for materialized views");
1239 }
1240 alter_streaming_config::handle_alter_streaming_reset_config(
1241 handler_args,
1242 name,
1243 keys,
1244 statement_type,
1245 )
1246 .await
1247 }
1248 }
1249 }
1250
1251 Statement::AlterSink { name, operation } => match operation {
1252 AlterSinkOperation::AlterConnectorProps {
1253 alter_props: changed_props,
1254 } => alter_sink_props::handle_alter_sink_props(handler_args, name, changed_props).await,
1255 AlterSinkOperation::RenameSink { sink_name } => {
1256 alter_rename::handle_rename_sink(handler_args, name, sink_name).await
1257 }
1258 AlterSinkOperation::ChangeOwner { new_owner_name } => {
1259 alter_owner::handle_alter_owner(
1260 handler_args,
1261 name,
1262 new_owner_name,
1263 StatementType::ALTER_SINK,
1264 None,
1265 )
1266 .await
1267 }
1268 AlterSinkOperation::SetSchema { new_schema_name } => {
1269 alter_set_schema::handle_alter_set_schema(
1270 handler_args,
1271 name,
1272 new_schema_name,
1273 StatementType::ALTER_SINK,
1274 None,
1275 )
1276 .await
1277 }
1278 AlterSinkOperation::SetParallelism {
1279 parallelism,
1280 deferred,
1281 } => {
1282 alter_parallelism::handle_alter_parallelism(
1283 handler_args,
1284 name,
1285 parallelism,
1286 StatementType::ALTER_SINK,
1287 deferred,
1288 )
1289 .await
1290 }
1291 AlterSinkOperation::SetBackfillParallelism {
1292 parallelism,
1293 deferred,
1294 } => {
1295 alter_parallelism::handle_alter_backfill_parallelism(
1296 handler_args,
1297 name,
1298 parallelism,
1299 StatementType::ALTER_SINK,
1300 deferred,
1301 )
1302 .await
1303 }
1304 AlterSinkOperation::SetResourceGroup {
1305 resource_group,
1306 deferred,
1307 } => {
1308 alter_resource_group::handle_alter_resource_group(
1309 handler_args,
1310 name,
1311 resource_group,
1312 StatementType::ALTER_SINK,
1313 deferred,
1314 )
1315 .await
1316 }
1317 AlterSinkOperation::SetConfig { entries } => {
1318 alter_streaming_config::handle_alter_streaming_set_config(
1319 handler_args,
1320 name,
1321 entries,
1322 StatementType::ALTER_SINK,
1323 )
1324 .await
1325 }
1326 AlterSinkOperation::ResetConfig { keys } => {
1327 alter_streaming_config::handle_alter_streaming_reset_config(
1328 handler_args,
1329 name,
1330 keys,
1331 StatementType::ALTER_SINK,
1332 )
1333 .await
1334 }
1335 AlterSinkOperation::SwapRenameSink { target_sink } => {
1336 alter_swap_rename::handle_swap_rename(
1337 handler_args,
1338 name,
1339 target_sink,
1340 StatementType::ALTER_SINK,
1341 )
1342 .await
1343 }
1344 AlterSinkOperation::AlterRateLimit(rate_limit) => {
1345 ensure_rate_limit_type_supported(
1346 &rate_limit,
1347 &[AlterRateLimitType::Sink, AlterRateLimitType::Backfill],
1348 "SINK",
1349 )?;
1350 alter_streaming_rate_limit::handle_alter_streaming_rate_limit(
1351 handler_args,
1352 PbThrottleTarget::Sink,
1353 rate_limit_type_to_throttle_type(rate_limit.rate_limit_type),
1354 name,
1355 rate_limit.rate_limit,
1356 )
1357 .await
1358 }
1359 AlterSinkOperation::SetStreamingEnableUnalignedJoin { enable } => {
1360 alter_streaming_enable_unaligned_join::handle_alter_streaming_enable_unaligned_join(
1361 handler_args,
1362 name,
1363 enable,
1364 )
1365 .await
1366 }
1367 },
1368 Statement::AlterSubscription { name, operation } => match operation {
1369 AlterSubscriptionOperation::RenameSubscription { subscription_name } => {
1370 alter_rename::handle_rename_subscription(handler_args, name, subscription_name)
1371 .await
1372 }
1373 AlterSubscriptionOperation::ChangeOwner { new_owner_name } => {
1374 alter_owner::handle_alter_owner(
1375 handler_args,
1376 name,
1377 new_owner_name,
1378 StatementType::ALTER_SUBSCRIPTION,
1379 None,
1380 )
1381 .await
1382 }
1383 AlterSubscriptionOperation::SetSchema { new_schema_name } => {
1384 alter_set_schema::handle_alter_set_schema(
1385 handler_args,
1386 name,
1387 new_schema_name,
1388 StatementType::ALTER_SUBSCRIPTION,
1389 None,
1390 )
1391 .await
1392 }
1393 AlterSubscriptionOperation::SetRetention { retention } => {
1394 alter_subscription_retention::handle_alter_subscription_retention(
1395 handler_args,
1396 name,
1397 retention,
1398 )
1399 .await
1400 }
1401 AlterSubscriptionOperation::SwapRenameSubscription {
1402 target_subscription,
1403 } => {
1404 alter_swap_rename::handle_swap_rename(
1405 handler_args,
1406 name,
1407 target_subscription,
1408 StatementType::ALTER_SUBSCRIPTION,
1409 )
1410 .await
1411 }
1412 },
1413 Statement::AlterSource { name, operation } => match operation {
1414 AlterSourceOperation::AlterConnectorProps { alter_props } => {
1415 alter_source_props::handle_alter_source_connector_props(
1416 handler_args,
1417 name,
1418 alter_props,
1419 )
1420 .await
1421 }
1422 AlterSourceOperation::RenameSource { source_name } => {
1423 alter_rename::handle_rename_source(handler_args, name, source_name).await
1424 }
1425 AlterSourceOperation::AddColumn { .. } => {
1426 alter_source_column::handle_alter_source_column(handler_args, name, operation).await
1427 }
1428 AlterSourceOperation::ChangeOwner { new_owner_name } => {
1429 alter_owner::handle_alter_owner(
1430 handler_args,
1431 name,
1432 new_owner_name,
1433 StatementType::ALTER_SOURCE,
1434 None,
1435 )
1436 .await
1437 }
1438 AlterSourceOperation::SetSchema { new_schema_name } => {
1439 alter_set_schema::handle_alter_set_schema(
1440 handler_args,
1441 name,
1442 new_schema_name,
1443 StatementType::ALTER_SOURCE,
1444 None,
1445 )
1446 .await
1447 }
1448 AlterSourceOperation::FormatEncode { format_encode } => {
1449 alter_source_with_sr::handle_alter_source_with_sr(handler_args, name, format_encode)
1450 .await
1451 }
1452 AlterSourceOperation::RefreshSchema => {
1453 alter_source_with_sr::handler_refresh_schema(handler_args, name).await
1454 }
1455 AlterSourceOperation::AlterRateLimit(rate_limit) => {
1456 ensure_rate_limit_type_supported(
1457 &rate_limit,
1458 &[AlterRateLimitType::Source],
1459 "SOURCE",
1460 )?;
1461 alter_streaming_rate_limit::handle_alter_streaming_rate_limit(
1462 handler_args,
1463 PbThrottleTarget::Source,
1464 rate_limit_type_to_throttle_type(rate_limit.rate_limit_type),
1465 name,
1466 rate_limit.rate_limit,
1467 )
1468 .await
1469 }
1470 AlterSourceOperation::SwapRenameSource { target_source } => {
1471 alter_swap_rename::handle_swap_rename(
1472 handler_args,
1473 name,
1474 target_source,
1475 StatementType::ALTER_SOURCE,
1476 )
1477 .await
1478 }
1479 AlterSourceOperation::SetParallelism {
1480 parallelism,
1481 deferred,
1482 } => {
1483 alter_parallelism::handle_alter_parallelism(
1484 handler_args,
1485 name,
1486 parallelism,
1487 StatementType::ALTER_SOURCE,
1488 deferred,
1489 )
1490 .await
1491 }
1492 AlterSourceOperation::SetBackfillParallelism {
1493 parallelism,
1494 deferred,
1495 } => {
1496 alter_parallelism::handle_alter_backfill_parallelism(
1497 handler_args,
1498 name,
1499 parallelism,
1500 StatementType::ALTER_SOURCE,
1501 deferred,
1502 )
1503 .await
1504 }
1505 AlterSourceOperation::SetConfig { entries } => {
1506 alter_streaming_config::handle_alter_streaming_set_config(
1507 handler_args,
1508 name,
1509 entries,
1510 StatementType::ALTER_SOURCE,
1511 )
1512 .await
1513 }
1514 AlterSourceOperation::ResetConfig { keys } => {
1515 alter_streaming_config::handle_alter_streaming_reset_config(
1516 handler_args,
1517 name,
1518 keys,
1519 StatementType::ALTER_SOURCE,
1520 )
1521 .await
1522 }
1523 AlterSourceOperation::ResetSource => {
1524 reset_source::handle_reset_source(handler_args, name).await
1525 }
1526 },
1527 Statement::AlterFunction {
1528 name,
1529 args,
1530 operation,
1531 } => match operation {
1532 AlterFunctionOperation::SetSchema { new_schema_name } => {
1533 alter_set_schema::handle_alter_set_schema(
1534 handler_args,
1535 name,
1536 new_schema_name,
1537 StatementType::ALTER_FUNCTION,
1538 args,
1539 )
1540 .await
1541 }
1542 AlterFunctionOperation::ChangeOwner { new_owner_name } => {
1543 alter_owner::handle_alter_owner(
1544 handler_args,
1545 name,
1546 new_owner_name,
1547 StatementType::ALTER_FUNCTION,
1548 args,
1549 )
1550 .await
1551 }
1552 },
1553 Statement::AlterConnection { name, operation } => match operation {
1554 AlterConnectionOperation::SetSchema { new_schema_name } => {
1555 alter_set_schema::handle_alter_set_schema(
1556 handler_args,
1557 name,
1558 new_schema_name,
1559 StatementType::ALTER_CONNECTION,
1560 None,
1561 )
1562 .await
1563 }
1564 AlterConnectionOperation::ChangeOwner { new_owner_name } => {
1565 alter_owner::handle_alter_owner(
1566 handler_args,
1567 name,
1568 new_owner_name,
1569 StatementType::ALTER_CONNECTION,
1570 None,
1571 )
1572 .await
1573 }
1574 AlterConnectionOperation::AlterConnectorProps { alter_props } => {
1575 alter_connection_props::handle_alter_connection_connector_props(
1576 handler_args,
1577 name,
1578 alter_props,
1579 )
1580 .await
1581 }
1582 },
1583 Statement::AlterSystem { param, value } => {
1584 alter_system::handle_alter_system(handler_args, param, value).await
1585 }
1586 Statement::AlterSystemClearFileCache { cache_type } => {
1587 alter_system::handle_clear_file_cache(handler_args, cache_type).await
1588 }
1589 Statement::AlterSecret { name, operation } => match operation {
1590 AlterSecretOperation::ChangeCredential {
1591 with_options,
1592 new_credential,
1593 } => {
1594 alter_secret::handle_alter_secret(handler_args, name, with_options, new_credential)
1595 .await
1596 }
1597 AlterSecretOperation::ChangeOwner { new_owner_name } => {
1598 alter_owner::handle_alter_owner(
1599 handler_args,
1600 name,
1601 new_owner_name,
1602 StatementType::ALTER_SECRET,
1603 None,
1604 )
1605 .await
1606 }
1607 },
1608 Statement::AlterFragment {
1609 fragment_ids,
1610 operation,
1611 } => match operation {
1612 AlterFragmentOperation::AlterRateLimit(rate_limit) => {
1613 let [fragment_id] = fragment_ids.as_slice() else {
1614 return Err(ErrorCode::InvalidInputSyntax(
1615 "ALTER FRAGMENT ... SET rate limit supports exactly one fragment id"
1616 .to_owned(),
1617 )
1618 .into());
1619 };
1620 alter_streaming_rate_limit::handle_alter_streaming_rate_limit_by_id(
1621 &handler_args.session,
1622 PbThrottleTarget::Fragment,
1623 rate_limit_type_to_throttle_type(rate_limit.rate_limit_type),
1624 *fragment_id,
1625 rate_limit.rate_limit,
1626 StatementType::SET_VARIABLE,
1627 )
1628 .await
1629 }
1630 AlterFragmentOperation::SetParallelism { parallelism } => {
1631 alter_parallelism::handle_alter_fragment_parallelism(
1632 handler_args,
1633 fragment_ids.into_iter().map_into().collect(),
1634 parallelism,
1635 )
1636 .await
1637 }
1638 },
1639 Statement::AlterDefaultPrivileges { .. } => {
1640 handle_privilege::handle_alter_default_privileges(handler_args, stmt).await
1641 }
1642 Statement::AlterCompactionGroup {
1643 group_ids,
1644 operation,
1645 } => {
1646 alter_compaction_group::handle_alter_compaction_group(
1647 handler_args,
1648 group_ids,
1649 operation,
1650 )
1651 .await
1652 }
1653 Statement::StartTransaction { modes } => {
1654 transaction::handle_begin(handler_args, START_TRANSACTION, modes)
1655 }
1656 Statement::Begin { modes } => transaction::handle_begin(handler_args, BEGIN, modes),
1657 Statement::Commit { chain } => {
1658 transaction::handle_commit(handler_args, COMMIT, chain).await
1659 }
1660 Statement::Abort => transaction::handle_rollback(handler_args, ABORT, false).await,
1661 Statement::Rollback { chain } => {
1662 transaction::handle_rollback(handler_args, ROLLBACK, chain).await
1663 }
1664 Statement::SetTransaction {
1665 modes,
1666 snapshot,
1667 session,
1668 } => transaction::handle_set(handler_args, modes, snapshot, session),
1669 Statement::CancelJobs(jobs) => handle_cancel(handler_args, jobs).await,
1670 Statement::Kill(worker_process_id) => handle_kill(handler_args, worker_process_id).await,
1671 Statement::Comment {
1672 object_type,
1673 object_name,
1674 comment,
1675 } => comment::handle_comment(handler_args, object_type, object_name, comment).await,
1676 Statement::Use { db_name } => use_db::handle_use_db(handler_args, db_name),
1677 Statement::Prepare {
1678 name,
1679 data_types,
1680 statement,
1681 } => prepared_statement::handle_prepare(name, data_types, statement),
1682 Statement::Deallocate { name, prepare } => {
1683 prepared_statement::handle_deallocate(name, prepare)
1684 }
1685 Statement::Vacuum { object_name, mode } => {
1686 vacuum::handle_vacuum(handler_args, object_name, mode).await
1687 }
1688 Statement::Refresh { table_name } => {
1689 refresh::handle_refresh(handler_args, table_name).await
1690 }
1691 _ => bail_not_implemented!("Unhandled statement: {}", stmt),
1692 }
1693}
1694
1695fn check_ban_ddl_for_iceberg_engine_table(
1696 session: Arc<SessionImpl>,
1697 stmt: &Statement,
1698) -> Result<()> {
1699 if let Statement::AlterTable { name, operation } = stmt {
1700 let (table, schema_name) = get_table_catalog_by_table_name(session.as_ref(), name)?;
1701 if table.is_iceberg_engine_table() {
1702 let has_auto_refresh_schema_sink = if matches!(
1703 operation,
1704 AlterTableOperation::AddColumn { .. } | AlterTableOperation::DropColumn { .. }
1705 ) {
1706 let catalog_reader = session.env().catalog_reader().read_guard();
1707 let db_name = session.database();
1708 let sink_name = format!("{}{}", ICEBERG_SINK_PREFIX, table.name());
1709 let sink = catalog_reader
1710 .get_schema_by_name(&db_name, &schema_name)
1711 .ok()
1712 .and_then(|schema| schema.get_created_sink_by_name(&sink_name));
1713 sink.and_then(|s| s.auto_refresh_schema_from_table)
1714 .is_some()
1715 } else {
1716 false
1717 };
1718
1719 check_ban_alter_table_operation_for_iceberg_engine_table(
1720 operation,
1721 &schema_name,
1722 name,
1723 has_auto_refresh_schema_sink,
1724 )?;
1725 }
1726 }
1727
1728 Ok(())
1729}
1730
1731fn check_ban_alter_table_operation_for_iceberg_engine_table(
1732 operation: &AlterTableOperation,
1733 schema_name: &str,
1734 table_name: &ObjectName,
1735 has_auto_refresh_schema_sink: bool,
1736) -> Result<()> {
1737 match operation {
1738 AlterTableOperation::AddColumn { .. } => {
1739 if !has_auto_refresh_schema_sink {
1740 bail!(
1741 "ALTER TABLE {} is not supported for iceberg table without auto schema change sink: {}.{}",
1742 operation,
1743 schema_name,
1744 table_name
1745 );
1746 }
1747 }
1748 AlterTableOperation::DropColumn { .. } => {
1749 if !has_auto_refresh_schema_sink {
1750 bail!(
1751 "ALTER TABLE {} is not supported for iceberg table without auto schema change sink: {}.{}",
1752 operation,
1753 schema_name,
1754 table_name
1755 );
1756 }
1757 }
1758 AlterTableOperation::RenameColumn { .. }
1759 | AlterTableOperation::ChangeColumn { .. }
1760 | AlterTableOperation::AlterColumn { .. } => {
1761 bail!(
1762 "ALTER TABLE {} is not supported for iceberg table: {}.{}. Existing column schema mutation is not supported currently",
1763 operation,
1764 schema_name,
1765 table_name
1766 );
1767 }
1768 AlterTableOperation::RenameTable { .. } => {
1769 bail!(
1770 "ALTER TABLE RENAME is not supported for iceberg table: {}.{}",
1771 schema_name,
1772 table_name
1773 );
1774 }
1775 AlterTableOperation::SetParallelism { .. } => {
1776 bail!(
1777 "ALTER TABLE SET PARALLELISM is not supported for iceberg table: {}.{}",
1778 schema_name,
1779 table_name
1780 );
1781 }
1782 AlterTableOperation::SetBackfillParallelism { .. } => {
1783 bail!(
1784 "ALTER TABLE SET BACKFILL PARALLELISM is not supported for iceberg table: {}.{}",
1785 schema_name,
1786 table_name
1787 );
1788 }
1789 AlterTableOperation::RefreshSchema => {
1790 bail!(
1791 "ALTER TABLE REFRESH SCHEMA is not supported for iceberg table: {}.{}",
1792 schema_name,
1793 table_name
1794 );
1795 }
1796 AlterTableOperation::AlterRateLimit(rate_limit)
1797 if rate_limit.rate_limit_type == AlterRateLimitType::Source =>
1798 {
1799 bail!(
1800 "ALTER TABLE SET SOURCE RATE LIMIT is not supported for iceberg table: {}.{}",
1801 schema_name,
1802 table_name
1803 );
1804 }
1805 AlterTableOperation::AlterWatermark { .. } => {
1806 bail!(
1807 "ALTER TABLE ALTER WATERMARK is not supported for iceberg table: {}.{}",
1808 schema_name,
1809 table_name
1810 );
1811 }
1812 _ => {}
1813 }
1814 Ok(())
1815}