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

Function plan_copy_from

src/sql/src/plan/statement/dml.rs:1957–2088  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    target: &CopyTarget<Aug>,
    table_name: ResolvedItemName,
    columns: Vec<Ident>,
    format: Option<CopyFormat>,
    options: CopyOptionExtracted,
)

Source from the content-addressed store, hash-verified

1955}
1956
1957fn plan_copy_from(
1958 scx: &StatementContext,
1959 target: &CopyTarget<Aug>,
1960 table_name: ResolvedItemName,
1961 columns: Vec<Ident>,
1962 format: Option<CopyFormat>,
1963 options: CopyOptionExtracted,
1964) -> Result<Plan, PlanError> {
1965 fn only_available_with_csv<T>(option: Option<T>, param: &str) -> Result<(), PlanError> {
1966 match option {
1967 Some(_) => sql_bail!("COPY {} available only in CSV mode", param),
1968 None => Ok(()),
1969 }
1970 }
1971
1972 let source = match target {
1973 CopyTarget::Stdin => CopyFromSource::Stdin,
1974 CopyTarget::Expr(from) => {
1975 // Converting the expr to an HirScalarExpr
1976 let mut from_expr = from.clone();
1977 transform_ast::transform(scx, &mut from_expr)?;
1978 let relation_type = RelationDesc::empty();
1979 let ecx = &ExprContext {
1980 qcx: &QueryContext::root(scx, QueryLifetime::OneShot),
1981 name: "COPY FROM target",
1982 scope: &Scope::empty(),
1983 relation_type: relation_type.typ(),
1984 allow_aggregates: false,
1985 allow_subqueries: false,
1986 allow_parameters: false,
1987 allow_windows: false,
1988 };
1989 let from = plan_expr(ecx, &from_expr)?.type_as(ecx, &SqlScalarType::String)?;
1990
1991 match options.aws_connection {
1992 Some(conn_id) => {
1993 let conn_id = CatalogItemId::from(conn_id);
1994
1995 // Validate the connection type is one we expect.
1996 let connection = match scx.get_item(&conn_id).connection()? {
1997 mz_storage_types::connections::Connection::Aws(conn) => conn,
1998 _ => sql_bail!("only AWS CONNECTION is supported in COPY ... FROM"),
1999 };
2000
2001 CopyFromSource::AwsS3 {
2002 uri: from,
2003 connection,
2004 connection_id: conn_id,
2005 }
2006 }
2007 None => CopyFromSource::Url(from),
2008 }
2009 }
2010 CopyTarget::Stdout => bail_never_supported!("COPY FROM {} not supported", target),
2011 };
2012
2013 // COPY FROM a URL or S3 bucket only supports CSV and Parquet. Unlike COPY
2014 // FROM STDIN there's no sensible default format, so one must be specified

Callers 2

describe_copy_from_tableFunction · 0.70
plan_copyFunction · 0.70

Calls 13

transformFunction · 0.85
plan_exprFunction · 0.85
only_available_with_csvFunction · 0.85
extract_byte_param_valueFunction · 0.85
TextClass · 0.85
type_asMethod · 0.80
is_someMethod · 0.80
full_name_strMethod · 0.80
PatternEnum · 0.50
cloneMethod · 0.45
typMethod · 0.45
connectionMethod · 0.45

Tested by

no test coverage detected