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

Function plan_copy_from

src/sql/src/plan/query.rs:568–608  ·  view source on GitHub ↗

See the doc comment on [`plan_copy_item`] for the details of what this function returns. TODO(cf3): Merge this method with [`plan_copy_item`].

(
    scx: &StatementContext,
    table_name: ResolvedItemName,
    columns: Vec<Ident>,
)

Source from the content-addressed store, hash-verified

566///
567/// TODO(cf3): Merge this method with [`plan_copy_item`].
568pub fn plan_copy_from(
569 scx: &StatementContext,
570 table_name: ResolvedItemName,
571 columns: Vec<Ident>,
572) -> Result<
573 (
574 CatalogItemId,
575 RelationDesc,
576 Vec<ColumnIndex>,
577 Option<MapFilterProject>,
578 ),
579 PlanError,
580> {
581 let table = scx.get_item_by_resolved_name(&table_name)?;
582
583 // Validate the target of the insert.
584 if table.item_type() != CatalogItemType::Table {
585 sql_bail!(
586 "cannot insert into {} '{}'",
587 table.item_type(),
588 table_name.full_name_str()
589 );
590 }
591
592 let _ = table.writable_table_details().ok_or_else(|| {
593 sql_err!(
594 "cannot insert into non-writeable table '{}'",
595 table_name.full_name_str()
596 )
597 })?;
598
599 if table.id().is_system() {
600 sql_bail!(
601 "cannot insert into system table '{}'",
602 table_name.full_name_str()
603 );
604 }
605 let (id, desc, ordering, mfp) = plan_copy_item(scx, table_name, columns)?;
606
607 Ok((id, desc, ordering, mfp))
608}
609
610/// Builds a plan that adds the default values for the missing columns and re-orders
611/// the datums in the given rows to match the order in the target table.

Callers 1

setup_copy_from_stdinMethod · 0.50

Calls 6

plan_copy_itemFunction · 0.85
item_typeMethod · 0.45
is_systemMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected