alamb commented on code in PR #16019: URL: https://github.com/apache/datafusion/pull/16019#discussion_r2085180878
########## datafusion/sql/src/statement.rs: ########## @@ -710,6 +710,15 @@ impl<S: ContextProvider> SqlToRel<'_, S> { *statement, &mut planner_context, )?; + + if data_types.is_empty() { + for dt in plan.get_parameter_types()?.into_values().flatten() { + data_types.push(dt); + } + data_types.sort(); + planner_context.with_prepare_param_data_types(data_types.clone()); + } + Ok(LogicalPlan::Statement(PlanStatement::Prepare(Prepare { Review Comment: Another thing I suggest we do (as a follow on PR) is move the type checking / construction into a `LogicalPlanBuilder` method rather than entirely in the SQL planner, so that other frontends can use it too ########## datafusion/sql/src/statement.rs: ########## @@ -710,6 +710,17 @@ impl<S: ContextProvider> SqlToRel<'_, S> { *statement, &mut planner_context, )?; + + if data_types.is_empty() { + for dt in plan.get_parameter_types()?.into_values().into_iter() { + if let Some(dt) = dt { + data_types.push(dt); + } + } + data_types.sort(); Review Comment: 🤔 it seems like `get_parameter_types` returns a hash map of id to value but the prepare statement wants the parameters in the order of definition So I think if there are three parameter types, it is expected they have ids `$1`, `$2`, and `$3` for the prepare statement However, if the query mentions parameters in the opposite order that So TLDR I suggest you change this code to explicitly look for `$1`, `$2`, etc rather than trying to sort the types It sounds like there should probably be some tests like ```sql SELECT ... FROM string_col = $1 AND int_col = $2 SELECT ... FROM string_col = $2 AND int_col = $1 ``` To make sure the parameter types match up -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org