forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jayzhan211 <[email protected]>
- Loading branch information
1 parent
d2fb05e
commit fbb87c6
Showing
7 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use std::sync::Arc; | ||
|
||
use datafusion_expr::{expr::AggregateFunction, Expr}; | ||
use sqlparser::ast::NullTreatment; | ||
|
||
pub struct ExprBuilder { | ||
udf: Arc<crate::AggregateUDF>, | ||
/// List of expressions to feed to the functions as arguments | ||
args: Vec<Expr>, | ||
/// Whether this is a DISTINCT aggregation or not | ||
distinct: bool, | ||
/// Optional filter | ||
filter: Option<Box<Expr>>, | ||
/// Optional ordering | ||
order_by: Option<Vec<Expr>>, | ||
null_treatment: Option<NullTreatment>, | ||
} | ||
|
||
impl ExprBuilder { | ||
pub fn new(udf: Arc<crate::AggregateUDF>, args: Vec<Expr>) -> Self { | ||
Self { | ||
udf, | ||
args, | ||
distinct: false, | ||
filter: None, | ||
order_by: None, | ||
null_treatment: None, | ||
} | ||
} | ||
|
||
pub fn new_distinct(udf: Arc<crate::AggregateUDF>, args: Vec<Expr>) -> Self { | ||
Self { | ||
udf, | ||
args, | ||
distinct: true, | ||
filter: None, | ||
order_by: None, | ||
null_treatment: None, | ||
} | ||
} | ||
} | ||
|
||
impl ExprBuilder { | ||
pub fn build(self) -> Expr { | ||
Expr::AggregateFunction(AggregateFunction::new_udf( | ||
self.udf, | ||
self.args, | ||
self.distinct, | ||
self.filter, | ||
self.order_by, | ||
self.null_treatment, | ||
)) | ||
} | ||
|
||
pub fn order_by(mut self, order_by: Vec<Expr>) -> Self { | ||
self.order_by = Some(order_by); | ||
self | ||
} | ||
|
||
pub fn filter(mut self, filter: Box<Expr>) -> Self { | ||
self.filter = Some(filter); | ||
self | ||
} | ||
|
||
pub fn null_treatment(mut self, null_treatment: NullTreatment) -> Self { | ||
self.null_treatment = Some(null_treatment); | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters