Skip to content

Commit

Permalink
Minor: use Expr::alias in a few places to make the code more concise (
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Nov 9, 2023
1 parent 965b318 commit a70369c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
7 changes: 3 additions & 4 deletions datafusion/optimizer/src/decorrelate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
)?;
if !expr_result_map_for_count_bug.is_empty() {
// has count bug
let un_matched_row = Expr::Alias(Alias::new(
Expr::Literal(ScalarValue::Boolean(Some(true))),
UN_MATCHED_ROW_INDICATOR.to_string(),
));
let un_matched_row =
Expr::Literal(ScalarValue::Boolean(Some(true)))
.alias(UN_MATCHED_ROW_INDICATOR);
// add the unmatched rows indicator to the Aggregation's group expressions
missing_exprs.push(un_matched_row);
}
Expand Down
20 changes: 9 additions & 11 deletions datafusion/optimizer/src/single_distinct_to_groupby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{OptimizerConfig, OptimizerRule};
use datafusion_common::Result;
use datafusion_expr::{
col,
expr::{AggregateFunction, Alias},
expr::AggregateFunction,
logical_plan::{Aggregate, LogicalPlan},
Expr,
};
Expand Down Expand Up @@ -168,16 +168,14 @@ impl OptimizerRule for SingleDistinctToGroupBy {
args[0].clone().alias(SINGLE_DISTINCT_ALIAS),
);
}
Ok(Expr::Alias(Alias::new(
Expr::AggregateFunction(AggregateFunction::new(
fun.clone(),
vec![col(SINGLE_DISTINCT_ALIAS)],
false, // intentional to remove distinct here
filter.clone(),
order_by.clone(),
)),
aggr_expr.display_name()?,
)))
Ok(Expr::AggregateFunction(AggregateFunction::new(
fun.clone(),
vec![col(SINGLE_DISTINCT_ALIAS)],
false, // intentional to remove distinct here
filter.clone(),
order_by.clone(),
))
.alias(aggr_expr.display_name()?))
}
_ => Ok(aggr_expr.clone()),
})
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sql/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
&[&[plan.schema()]],
&plan.using_columns()?,
)?;
let expr = Expr::Alias(Alias::new(col, self.normalizer.normalize(alias)));
let expr = col.alias(self.normalizer.normalize(alias));
Ok(vec![expr])
}
SelectItem::Wildcard(options) => {
Expand Down

0 comments on commit a70369c

Please sign in to comment.