risingwave_frontend/handler/
reset_source.rs1use risingwave_connector::WithPropertiesExt;
16use risingwave_sqlparser::ast::ObjectName;
17
18use super::alter_source_with_sr::fetch_source_catalog_with_db_schema_id;
19use super::{HandlerArgs, RwPgResponse};
20use crate::error::{ErrorCode, Result};
21
22pub async fn handle_reset_source(
26 handler_args: HandlerArgs,
27 name: ObjectName,
28) -> Result<RwPgResponse> {
29 let session = handler_args.session.clone();
30
31 let source = fetch_source_catalog_with_db_schema_id(&session, &name)?;
33
34 if source.is_cdc_table_source() {
35 return Err(ErrorCode::NotSupported(
36 "RESET is not supported for CDC table sources".to_owned(),
37 "Reset the upstream shared CDC source instead".to_owned(),
38 )
39 .into());
40 }
41
42 if source.associated_table_id.is_some() {
44 return Err(ErrorCode::NotSupported(
45 "reset CDC table using RESET SOURCE statement".to_owned(),
46 "try to use RESET TABLE instead".to_owned(),
47 )
48 .into());
49 }
50
51 if !source.with_properties.is_cdc_connector() {
53 return Err(ErrorCode::NotSupported(
54 "RESET SOURCE only supports CDC sources".to_owned(),
55 "This operation is only for CDC sources when offset has expired".to_owned(),
56 )
57 .into());
58 }
59
60 let catalog_writer = session.catalog_writer()?;
62 catalog_writer.reset_source(source.id).await?;
63
64 Ok(pgwire::pg_response::PgResponse::empty_result(
65 pgwire::pg_response::StatementType::ALTER_SOURCE,
66 ))
67}