I'm generating and expression from a string.
Let us suppose to have a data frame with a close column ant I'm trying to compute all in parallel through expressions.
If the function receives a string "rolling_mean" I need to compute close - close.rolling_mean(of some window).
I defined an expression for the close column to be used in match (don't repeat yourself):
let close_column = Expr::Column(Arc::from("close"));
After that I have a match to get the computation on close column:
close_column
- close_column.rolling_mean(RollingOptions {
window_size: Duration::new(window as i64),
min_periods: 1 as usize,
weights: None,
center: true,
by: None,
closed_window: None,
}))
The problem is that match statement moved the value of close_column inside the brace of match in the first value, so it is impossible to use for the second term (where I need rolling).
If I clone close_column the problem disappear (of course) but I'm not sure it is the best strategy.
Here my function:
pub fn generate_expr_from_str(function_name: &str, window: usize) -> Expr {
let close_column = Expr::Column(Arc::from("close"));
let expression = match function_name {
"rolling" => (close_column
- close_column.rolling_mean(RollingOptions {
window_size: Duration::new(window as i64),
min_periods: 1 as usize,
weights: None,
center: true,
by: None,
closed_window: None,
}))
.alias(format!("rolling_{window}").as_str()),
_ => panic!("function not implemented"),
};
expression
}
In case I clone even just the first close, the value is moved on the second and there is no problem for the compiler. Suggestions?