brayanjuls commented on code in PR #16019: URL: https://github.com/apache/datafusion/pull/16019#discussion_r2083769931
########## 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: yes, `plan.get_parameter_types()` returns a HashMap which does not preserve insertion order additionally I use `into_values` function which visits all the values in arbitrary order, so if I don't include the sort here the order of the types provided in the plan will not be deterministic and it will randomly successfully assert the test of plans. In example the assert below will randomly succeed and fail because of the type order: https://github.com/brayanjuls/arrow-datafusion/blob/6ffc6a20a211a8ca413e3631cc18adff6c1ea705/datafusion/sql/tests/sql_integration.rs#L4796-L4806 If we wanted to remove the use of sorting here and preserve insertion order which may be better we would need to change the following function to use `IndexMap` instead of `HashMap`, and tweak the loop of the infer type changes like below. Let me know what you think of this solution. https://github.com/apache/datafusion/blob/967384e16257bab4deb48bbeff38507ea13c4abd/datafusion/expr/src/logical_plan/plan.rs#L1490-L1520 small tweak to avoid modifying insertion order after using IndexMap: ```rust for (_key,value) in plan.get_parameter_types()? { if let Some(dt) = value { data_types.push(dt); } } ``` -- 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