Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: Stop ignoring AggregateFunction::distinct in protobuf serde code #3250

Merged
merged 3 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/single_distinct_to_groupby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn optimize(plan: &LogicalPlan) -> Result<LogicalPlan> {
Expr::AggregateFunction {
fun: fun.clone(),
args: vec![col(SINGLE_DISTINCT_ALIAS)],
distinct: false,
distinct: false, // intentional to remove distict here
}
}
_ => agg_expr.clone(),
Expand Down
1 change: 1 addition & 0 deletions datafusion/proto/proto/datafusion.proto
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ enum AggregateFunction {
message AggregateExprNode {
AggregateFunction aggr_function = 1;
repeated LogicalExprNode expr = 2;
bool distinct = 3;
}

message AggregateUDFExprNode {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/proto/src/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ pub fn parse_expr(
.iter()
.map(|e| parse_expr(e, registry))
.collect::<Result<Vec<_>, _>>()?,
distinct: false, // TODO
distinct: expr.distinct,
})
}
ExprType::Alias(alias) => Ok(Expr::Alias(
Expand Down
22 changes: 22 additions & 0 deletions datafusion/proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,28 @@ mod roundtrip_tests {
roundtrip_expr_test(test_expr, ctx);
}

#[test]
fn roundtrip_count() {
let test_expr = Expr::AggregateFunction {
fun: AggregateFunction::Count,
args: vec![col("bananas")],
distinct: false,
};
let ctx = SessionContext::new();
roundtrip_expr_test(test_expr, ctx);
}

#[test]
fn roundtrip_count_distinct() {
let test_expr = Expr::AggregateFunction {
fun: AggregateFunction::Count,
args: vec![col("bananas")],
distinct: true,
};
let ctx = SessionContext::new();
roundtrip_expr_test(test_expr, ctx);
}

#[test]
fn roundtrip_approx_percentile_cont() {
let test_expr = Expr::AggregateFunction {
Expand Down
5 changes: 4 additions & 1 deletion datafusion/proto/src/to_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode {
}
}
Expr::AggregateFunction {
ref fun, ref args, ..
ref fun,
ref args,
ref distinct,
} => {
let aggr_function = match fun {
AggregateFunction::ApproxDistinct => {
Expand Down Expand Up @@ -550,6 +552,7 @@ impl TryFrom<&Expr> for protobuf::LogicalExprNode {
.iter()
.map(|v| v.try_into())
.collect::<Result<Vec<_>, _>>()?,
distinct: *distinct,
};
Self {
expr_type: Some(ExprType::AggregateExpr(aggregate_expr)),
Expand Down