(&self, execute: Execute)
| 1532 | } |
| 1533 | |
| 1534 | fn execute_prepared(&self, execute: Execute) -> Result<DataFrame> { |
| 1535 | let Execute { |
| 1536 | name, parameters, .. |
| 1537 | } = execute; |
| 1538 | let prepared = self.state.read().get_prepared(&name).ok_or_else(|| { |
| 1539 | exec_datafusion_err!("Prepared statement '{}' does not exist", name) |
| 1540 | })?; |
| 1541 | |
| 1542 | let state = self.state.read(); |
| 1543 | let context = SimplifyContext::builder() |
| 1544 | .with_schema(Arc::clone(prepared.plan.schema())) |
| 1545 | .with_config_options(Arc::clone(state.config_options())) |
| 1546 | .with_query_execution_start_time( |
| 1547 | state.execution_props().query_execution_start_time, |
| 1548 | ) |
| 1549 | .build(); |
| 1550 | let simplifier = ExprSimplifier::new(context); |
| 1551 | |
| 1552 | // Only allow literals as parameters for now. |
| 1553 | let mut params: Vec<ScalarAndMetadata> = parameters |
| 1554 | .into_iter() |
| 1555 | .map(|e| match simplifier.simplify(e)? { |
| 1556 | Expr::Literal(scalar, metadata) => { |
| 1557 | Ok(ScalarAndMetadata::new(scalar, metadata)) |
| 1558 | } |
| 1559 | e => not_impl_err!("Unsupported parameter type: {e}"), |
| 1560 | }) |
| 1561 | .collect::<Result<_>>()?; |
| 1562 | |
| 1563 | // If the prepared statement provides data types, cast the params to those types. |
| 1564 | if !prepared.fields.is_empty() { |
| 1565 | if params.len() != prepared.fields.len() { |
| 1566 | return exec_err!( |
| 1567 | "Prepared statement '{}' expects {} parameters, but {} provided", |
| 1568 | name, |
| 1569 | prepared.fields.len(), |
| 1570 | params.len() |
| 1571 | ); |
| 1572 | } |
| 1573 | params = params |
| 1574 | .into_iter() |
| 1575 | .zip(prepared.fields.iter()) |
| 1576 | .map(|(e, dt)| -> Result<_> { e.cast_storage_to(dt.data_type()) }) |
| 1577 | .collect::<Result<_>>()?; |
| 1578 | } |
| 1579 | |
| 1580 | let params = ParamValues::List(params); |
| 1581 | let plan = prepared |
| 1582 | .plan |
| 1583 | .as_ref() |
| 1584 | .clone() |
| 1585 | .replace_params_with_values(¶ms)?; |
| 1586 | Ok(DataFrame::new(self.state(), plan)) |
| 1587 | } |
| 1588 | |
| 1589 | /// Registers a variable provider within this context. |
| 1590 | pub fn register_variable( |
no test coverage detected