(
scx: &StatementContext,
stmt: CreateSubsourceStatement<Aug>,
)
| 1587 | ); |
| 1588 | |
| 1589 | pub fn plan_create_subsource( |
| 1590 | scx: &StatementContext, |
| 1591 | stmt: CreateSubsourceStatement<Aug>, |
| 1592 | ) -> Result<Plan, PlanError> { |
| 1593 | let CreateSubsourceStatement { |
| 1594 | name, |
| 1595 | columns, |
| 1596 | of_source, |
| 1597 | constraints, |
| 1598 | if_not_exists, |
| 1599 | with_options, |
| 1600 | } = &stmt; |
| 1601 | |
| 1602 | let CreateSubsourceOptionExtracted { |
| 1603 | progress, |
| 1604 | retain_history, |
| 1605 | external_reference, |
| 1606 | text_columns, |
| 1607 | exclude_columns, |
| 1608 | details, |
| 1609 | seen: _, |
| 1610 | } = with_options.clone().try_into()?; |
| 1611 | |
| 1612 | // This invariant is enforced during purification; we are responsible for |
| 1613 | // creating the AST for subsources as a response to CREATE SOURCE |
| 1614 | // statements, so this would fire in integration testing if we failed to |
| 1615 | // uphold it. |
| 1616 | if !(progress ^ (external_reference.is_some() && of_source.is_some())) { |
| 1617 | bail_internal!( |
| 1618 | "CREATE SUBSOURCE statement must specify either PROGRESS or REFERENCES option" |
| 1619 | ); |
| 1620 | } |
| 1621 | |
| 1622 | let desc = plan_source_export_desc(scx, name, columns, constraints)?; |
| 1623 | |
| 1624 | let data_source = if let Some(source_reference) = of_source { |
| 1625 | // If the new source table syntax is forced we should not be creating any non-progress |
| 1626 | // subsources. |
| 1627 | if scx.catalog.system_vars().enable_create_table_from_source() |
| 1628 | && scx.catalog.system_vars().force_source_table_syntax() |
| 1629 | { |
| 1630 | Err(PlanError::UseTablesForSources( |
| 1631 | "CREATE SUBSOURCE".to_string(), |
| 1632 | ))?; |
| 1633 | } |
| 1634 | |
| 1635 | // This is a subsource with the "natural" dependency order, i.e. it is |
| 1636 | // not a legacy subsource with the inverted structure. |
| 1637 | let ingestion_id = *source_reference.item_id(); |
| 1638 | let external_reference = external_reference.ok_or_else(|| { |
| 1639 | sql_err!("CREATE SUBSOURCE with REFERENCES requires EXTERNAL REFERENCE option") |
| 1640 | })?; |
| 1641 | |
| 1642 | // Decode the details option stored on the subsource statement, which contains information |
| 1643 | // created during the purification process. |
| 1644 | let details = details |
| 1645 | .as_ref() |
| 1646 | .ok_or_else(|| internal_err!("source-export subsource missing details"))?; |
no test coverage detected