Skip to content

Commit a70369c

Browse files
authored
Minor: use Expr::alias in a few places to make the code more concise (#8097)
1 parent 965b318 commit a70369c

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

datafusion/optimizer/src/decorrelate.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,9 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
227227
)?;
228228
if !expr_result_map_for_count_bug.is_empty() {
229229
// has count bug
230-
let un_matched_row = Expr::Alias(Alias::new(
231-
Expr::Literal(ScalarValue::Boolean(Some(true))),
232-
UN_MATCHED_ROW_INDICATOR.to_string(),
233-
));
230+
let un_matched_row =
231+
Expr::Literal(ScalarValue::Boolean(Some(true)))
232+
.alias(UN_MATCHED_ROW_INDICATOR);
234233
// add the unmatched rows indicator to the Aggregation's group expressions
235234
missing_exprs.push(un_matched_row);
236235
}

datafusion/optimizer/src/single_distinct_to_groupby.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{OptimizerConfig, OptimizerRule};
2525
use datafusion_common::Result;
2626
use datafusion_expr::{
2727
col,
28-
expr::{AggregateFunction, Alias},
28+
expr::AggregateFunction,
2929
logical_plan::{Aggregate, LogicalPlan},
3030
Expr,
3131
};
@@ -168,16 +168,14 @@ impl OptimizerRule for SingleDistinctToGroupBy {
168168
args[0].clone().alias(SINGLE_DISTINCT_ALIAS),
169169
);
170170
}
171-
Ok(Expr::Alias(Alias::new(
172-
Expr::AggregateFunction(AggregateFunction::new(
173-
fun.clone(),
174-
vec![col(SINGLE_DISTINCT_ALIAS)],
175-
false, // intentional to remove distinct here
176-
filter.clone(),
177-
order_by.clone(),
178-
)),
179-
aggr_expr.display_name()?,
180-
)))
171+
Ok(Expr::AggregateFunction(AggregateFunction::new(
172+
fun.clone(),
173+
vec![col(SINGLE_DISTINCT_ALIAS)],
174+
false, // intentional to remove distinct here
175+
filter.clone(),
176+
order_by.clone(),
177+
))
178+
.alias(aggr_expr.display_name()?))
181179
}
182180
_ => Ok(aggr_expr.clone()),
183181
})

datafusion/sql/src/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
373373
&[&[plan.schema()]],
374374
&plan.using_columns()?,
375375
)?;
376-
let expr = Expr::Alias(Alias::new(col, self.normalizer.normalize(alias)));
376+
let expr = col.alias(self.normalizer.normalize(alias));
377377
Ok(vec![expr])
378378
}
379379
SelectItem::Wildcard(options) => {

0 commit comments

Comments
 (0)