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

Function plan_copy_to_expr

src/sql/src/plan/statement/dml.rs:1870–1955  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    select_plan: SelectPlan,
    desc: RelationDesc,
    to: &Expr<Aug>,
    format: CopyFormat,
    options: CopyOptionExtracted,
)

Source from the content-addressed store, hash-verified

1868}
1869
1870fn plan_copy_to_expr(
1871 scx: &StatementContext,
1872 select_plan: SelectPlan,
1873 desc: RelationDesc,
1874 to: &Expr<Aug>,
1875 format: CopyFormat,
1876 options: CopyOptionExtracted,
1877) -> Result<Plan, PlanError> {
1878 let conn_id = match options.aws_connection {
1879 Some(conn_id) => CatalogItemId::from(conn_id),
1880 None => sql_bail!("AWS CONNECTION is required for COPY ... TO <expr>"),
1881 };
1882 let connection = scx.get_item(&conn_id).connection()?;
1883
1884 match connection {
1885 mz_storage_types::connections::Connection::Aws(_) => {}
1886 _ => sql_bail!("only AWS CONNECTION is supported for COPY ... TO <expr>"),
1887 }
1888
1889 let format = match format {
1890 CopyFormat::Csv => {
1891 let quote = extract_byte_param_value(options.quote, "quote")?;
1892 let escape = extract_byte_param_value(options.escape, "escape")?;
1893 let delimiter = extract_byte_param_value(options.delimiter, "delimiter")?;
1894 S3SinkFormat::PgCopy(CopyFormatParams::Csv(
1895 CopyCsvFormatParams::try_new(
1896 delimiter,
1897 quote,
1898 escape,
1899 options.header,
1900 options.null,
1901 )
1902 .map_err(|e| sql_err!("{}", e))?,
1903 ))
1904 }
1905 CopyFormat::Parquet => {
1906 // Validate that the output desc can be formatted as parquet.
1907 // COPY TO does not apply any type overrides, so pass `|_| None`.
1908 ArrowBuilder::validate_desc_for_parquet(&desc, |_| None)
1909 .map_err(|e| sql_err!("{}", e))?;
1910 S3SinkFormat::Parquet
1911 }
1912 CopyFormat::Binary => bail_unsupported!("FORMAT BINARY"),
1913 CopyFormat::Text => bail_unsupported!("FORMAT TEXT"),
1914 };
1915
1916 // Converting the to expr to a HirScalarExpr
1917 let mut to_expr = to.clone();
1918 transform_ast::transform(scx, &mut to_expr)?;
1919 let relation_type = RelationDesc::empty();
1920 let ecx = &ExprContext {
1921 qcx: &QueryContext::root(scx, QueryLifetime::OneShot),
1922 name: "COPY TO target",
1923 scope: &Scope::empty(),
1924 relation_type: relation_type.typ(),
1925 allow_aggregates: false,
1926 allow_subqueries: false,
1927 allow_parameters: false,

Callers 1

plan_copyFunction · 0.85

Calls 10

extract_byte_param_valueFunction · 0.85
transformFunction · 0.85
plan_exprFunction · 0.85
type_asMethod · 0.80
connectionMethod · 0.45
get_itemMethod · 0.45
cloneMethod · 0.45
typMethod · 0.45
as_bytesMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected