findepi commented on code in PR #12177:
URL: https://github.com/apache/datafusion/pull/12177#discussion_r1734129474
##########
datafusion/expr/src/tree_node.rs:
##########
@@ -386,3 +379,48 @@ fn transform_vec<F: FnMut(Expr) ->
Result<Transformed<Expr>>>(
) -> Result<Transformed<Vec<Expr>>> {
ve.into_iter().map_until_stop_and_collect(f)
}
+
+pub fn transform_sort_option_vec<F: FnMut(Expr) -> Result<Transformed<Expr>>>(
+ sorts_option: Option<Vec<Sort>>,
+ f: &mut F,
+) -> Result<Transformed<Option<Vec<Sort>>>> {
+ sorts_option.map_or(Ok(Transformed::no(None)), |sorts| {
+ Ok(transform_sort_vec(sorts, f)?.update_data(Some))
+ })
+}
+
+pub fn transform_sort_vec<F: FnMut(Expr) -> Result<Transformed<Expr>>>(
+ sorts: Vec<Sort>,
+ mut f: &mut F,
+) -> Result<Transformed<Vec<Sort>>> {
+ Ok(sorts
+ .iter()
+ .map(|sort| sort.expr.clone())
+ .map_until_stop_and_collect(&mut f)?
+ .update_data(|transformed_exprs| {
+ replace_sort_expressions(sorts, transformed_exprs)
+ }))
+}
+
+pub fn replace_sort_expressions(sorts: Vec<Sort>, new_expr: Vec<Expr>) ->
Vec<Sort> {
+ if sorts.len() != new_expr.len() {
+ panic!(
+ "Incorrect number of new_expr, expected {}, got {}",
+ sorts.len(),
+ new_expr.len()
+ );
+ }
+
+ let mut new_sorts = Vec::with_capacity(sorts.len());
+ for (i, expr) in new_expr.into_iter().enumerate() {
+ new_sorts.push(replace_sort_expression(sorts[i].clone(), expr));
Review Comment:
thanks, done!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]