MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / sequence_alter_source

Method sequence_alter_source

src/adapter/src/coord/sequencer/inner.rs:3792–4124  ·  view source on GitHub ↗
(
        &mut self,
        session: &Session,
        plan::AlterSourcePlan {
            item_id,
            ingestion_id,
            action,
        }: plan::AlterSourcePlan,
    )

Source from the content-addressed store, hash-verified

3790
3791 #[instrument]
3792 pub(super) async fn sequence_alter_source(
3793 &mut self,
3794 session: &Session,
3795 plan::AlterSourcePlan {
3796 item_id,
3797 ingestion_id,
3798 action,
3799 }: plan::AlterSourcePlan,
3800 ) -> Result<ExecuteResponse, AdapterError> {
3801 let cur_entry = self.catalog().get_entry(&item_id);
3802 let cur_source = cur_entry.source().expect("known to be source");
3803
3804 let create_sql_to_stmt_deps = |coord: &Coordinator, err_cx, create_source_sql| {
3805 // Parse statement.
3806 let create_source_stmt = match mz_sql::parse::parse(create_source_sql)
3807 .expect("invalid create sql persisted to catalog")
3808 .into_element()
3809 .ast
3810 {
3811 Statement::CreateSource(stmt) => stmt,
3812 _ => unreachable!("proved type is source"),
3813 };
3814
3815 let catalog = coord.catalog().for_system_session();
3816
3817 // Resolve items in statement
3818 mz_sql::names::resolve(&catalog, create_source_stmt)
3819 .map_err(|e| AdapterError::internal(err_cx, e))
3820 };
3821
3822 match action {
3823 plan::AlterSourceAction::AddSubsourceExports {
3824 subsources,
3825 options,
3826 } => {
3827 const ALTER_SOURCE: &str = "ALTER SOURCE...ADD SUBSOURCES";
3828
3829 let mz_sql::plan::AlterSourceAddSubsourceOptionExtracted {
3830 text_columns: mut new_text_columns,
3831 exclude_columns: mut new_exclude_columns,
3832 ..
3833 } = options.try_into()?;
3834
3835 // Resolve items in statement
3836 let (mut create_source_stmt, resolved_ids) =
3837 create_sql_to_stmt_deps(self, ALTER_SOURCE, cur_entry.create_sql())?;
3838
3839 // Get all currently referred-to items
3840 let catalog = self.catalog();
3841 let curr_references: BTreeSet<_> = catalog
3842 .get_entry(&item_id)
3843 .used_by()
3844 .into_iter()
3845 .filter_map(|subsource| {
3846 catalog
3847 .get_entry(subsource)
3848 .subsource_details()
3849 .map(|(_id, reference, _details)| reference)

Callers 1

sequence_planMethod · 0.80

Calls 15

resolveFunction · 0.85
CreateSourceClass · 0.85
expectMethod · 0.80
into_elementMethod · 0.80
sortMethod · 0.80
anyMethod · 0.80
create_source_innerMethod · 0.80
catalog_transactMethod · 0.80
parseFunction · 0.50
planFunction · 0.50

Tested by

no test coverage detected