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

Function plan_create_source

src/sql/src/plan/statement/ddl.rs:751–1018  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    mut stmt: CreateSourceStatement<Aug>,
)

Source from the content-addressed store, hash-verified

749}
750
751pub fn plan_create_source(
752 scx: &StatementContext,
753 mut stmt: CreateSourceStatement<Aug>,
754) -> Result<Plan, PlanError> {
755 let CreateSourceStatement {
756 name,
757 in_cluster: _,
758 col_names,
759 connection: source_connection,
760 envelope,
761 if_not_exists,
762 format,
763 key_constraint,
764 include_metadata,
765 with_options,
766 external_references: referenced_subsources,
767 progress_subsource,
768 } = &stmt;
769
770 mz_ore::soft_assert_or_log!(
771 referenced_subsources.is_none(),
772 "referenced subsources must be cleared in purification"
773 );
774
775 let force_source_table_syntax = scx.catalog.system_vars().enable_create_table_from_source()
776 && scx.catalog.system_vars().force_source_table_syntax();
777
778 // If the new source table syntax is forced all the options related to the primary
779 // source output should be un-set.
780 if force_source_table_syntax {
781 if envelope.is_some() || format.is_some() || !include_metadata.is_empty() {
782 Err(PlanError::UseTablesForSources(
783 "CREATE SOURCE (ENVELOPE|FORMAT|INCLUDE)".to_string(),
784 ))?;
785 }
786 }
787
788 let envelope = envelope.clone().unwrap_or(ast::SourceEnvelope::None);
789
790 if !matches!(source_connection, CreateSourceConnection::Kafka { .. })
791 && include_metadata
792 .iter()
793 .any(|sic| matches!(sic, SourceIncludeMetadata::Headers { .. }))
794 {
795 // TODO(guswynn): should this be `bail_unsupported!`?
796 sql_bail!("INCLUDE HEADERS with non-Kafka sources not supported");
797 }
798 if !matches!(
799 source_connection,
800 CreateSourceConnection::Kafka { .. } | CreateSourceConnection::LoadGenerator { .. }
801 ) && !include_metadata.is_empty()
802 {
803 bail_unsupported!("INCLUDE metadata with non-Kafka sources");
804 }
805
806 if !include_metadata.is_empty()
807 && !matches!(
808 envelope,

Callers 1

planFunction · 0.85

Calls 15

maybe_rename_columnsFunction · 0.85
key_constraint_errFunction · 0.85
unresolved_item_nameFunction · 0.85
create_statementFunction · 0.85
CreateSourceClass · 0.85
is_someMethod · 0.80

Tested by

no test coverage detected