timsaucer commented on code in PR #12431:
URL: https://github.com/apache/datafusion/pull/12431#discussion_r1755048316
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -1452,28 +1452,34 @@ impl DataFrame {
pub fn with_column(self, name: &str, expr: Expr) -> Result<DataFrame> {
let window_func_exprs = find_window_exprs(&[expr.clone()]);
- let (plan, mut col_exists, window_func) = if
window_func_exprs.is_empty() {
- (self.plan, false, false)
+ let (window_fn_str, plan) = if window_func_exprs.is_empty() {
+ (None, self.plan)
} else {
(
+ Some(window_func_exprs[0].to_string()),
LogicalPlanBuilder::window_plan(self.plan, window_func_exprs)?,
- true,
- true,
)
};
+ let mut col_exists = false;
let new_column = expr.alias(name);
let mut fields: Vec<Expr> = plan
.schema()
.iter()
- .map(|(qualifier, field)| {
+ .filter_map(|(qualifier, field)| {
if field.name() == name {
col_exists = true;
- new_column.clone()
- } else if window_func && qualifier.is_none() {
- col(Column::from((qualifier, field))).alias(name)
+ Some(new_column.clone())
} else {
- col(Column::from((qualifier, field)))
+ let e = col(Column::from((qualifier, field)));
+ let match_window_fn = window_fn_str
+ .as_ref()
Review Comment:
That's a nice suggestion. Thank you. Pushed with the included change.
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -2984,19 +2990,25 @@ mod tests {
let df_impl = DataFrame::new(ctx.state(), df.plan.clone());
let func = row_number().alias("row_num");
+ // This first `with_column` results in a column without a `qualifier`
+ let df_impl = df_impl.with_column("s", col("c2") + col("c3"))?;
+
+ // This second `with_column` then assigns `"r"` alias to the above
column and the window function
Review Comment:
Added
--
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]