(
scx: &StatementContext,
target: &CopyTarget<Aug>,
table_name: ResolvedItemName,
columns: Vec<Ident>,
format: Option<CopyFormat>,
options: CopyOptionExtracted,
)
| 1955 | } |
| 1956 | |
| 1957 | fn 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 |
no test coverage detected