Skip to content

Apache DataFusion SQL Query Engine

ARROW-9792: [Rust] [DataFusion] Aggregate expression functions should not return result

Andy Groveae5be7614572
diff --git a/rust/datafusion/src/dataframe.rs b/rust/datafusion/src/dataframe.rs
index ee9ff6a392..532543d303 100644
--- a/rust/datafusion/src/dataframe.rs
+++ b/rust/datafusion/src/dataframe.rs
@@ -41,7 +41,7 @@ use std::sync::Arc;
/// let mut ctx = ExecutionContext::new();
/// let df = ctx.read_csv("tests/example.csv", CsvReadOptions::new())?;
/// let df = df.filter(col("a").lt_eq(col("b")))?
-/// .aggregate(vec![col("a")], vec![min(col("b"))?])?
+/// .aggregate(vec![col("a")], vec![min(col("b"))])?
/// .limit(100)?;
/// let results = df.collect();
/// # Ok(())
@@ -101,10 +101,10 @@ pub trait DataFrame {
/// let df = ctx.read_csv("tests/example.csv", CsvReadOptions::new())?;
///
/// // The following use is the equivalent of "SELECT MIN(b) GROUP BY a"
- /// let _ = df.aggregate(vec![col("a")], vec![min(col("b"))?])?;
+ /// let _ = df.aggregate(vec![col("a")], vec![min(col("b"))])?;
///
/// // The following use is the equivalent of "SELECT MIN(b)"
- /// let _ = df.aggregate(vec![], vec![min(col("b"))?])?;
+ /// let _ = df.aggregate(vec![], vec![min(col("b"))])?;
/// # Ok(())
/// # }
/// ```
diff --git a/rust/datafusion/src/execution/context.rs b/rust/datafusion/src/execution/context.rs
index 0f2ab667f2..aa6610b542 100644
--- a/rust/datafusion/src/execution/context.rs
+++ b/rust/datafusion/src/execution/context.rs
@@ -71,7 +71,7 @@ use crate::sql::{
/// let mut ctx = ExecutionContext::new();
/// let df = ctx.read_csv("tests/example.csv", CsvReadOptions::new())?;
/// let df = df.filter(col("a").lt_eq(col("b")))?
-/// .aggregate(vec![col("a")], vec![min(col("b"))?])?
+/// .aggregate(vec![col("a")], vec![min(col("b"))])?
/// .limit(100)?;
/// let results = df.collect();
/// # Ok(())
diff --git a/rust/datafusion/src/execution/dataframe_impl.rs b/rust/datafusion/src/execution/dataframe_impl.rs
index dab6fffd9f..3d50692e98 100644
--- a/rust/datafusion/src/execution/dataframe_impl.rs
+++ b/rust/datafusion/src/execution/dataframe_impl.rs
@@ -155,20 +155,20 @@ mod tests {
#[test]
fn aggregate() -> Result<()> {
- // build plan using Table API
- let t = test_table()?;
+ // build plan using DataFrame API
+ let df = test_table()?;
let group_expr = vec![col("c1")];
let aggr_expr = vec![
- min(col("c12"))?,
- max(col("c12"))?,
- avg(col("c12"))?,
- sum(col("c12"))?,
- count(col("c12"))?,
+ min(col("c12")),
+ max(col("c12")),
+ avg(col("c12")),
+ sum(col("c12")),
+ count(col("c12")),
];
- let t2 = t.aggregate(group_expr.clone(), aggr_expr.clone())?;
+ let df = df.aggregate(group_expr.clone(), aggr_expr.clone())?;
- let plan = t2.to_logical_plan();
+ let plan = df.to_logical_plan();
// build same plan using SQL API
let sql = "SELECT c1, MIN(c12), MAX(c12), AVG(c12), SUM(c12), COUNT(c12) \
diff --git a/rust/datafusion/src/lib.rs b/rust/datafusion/src/lib.rs
index f6cba3ef40..b276cf4c81 100644
--- a/rust/datafusion/src/lib.rs
+++ b/rust/datafusion/src/lib.rs
@@ -39,7 +39,7 @@
/// let mut ctx = ExecutionContext::new();
/// let df = ctx.read_csv("tests/example.csv", CsvReadOptions::new())?;
/// let df = df.filter(col("a").lt_eq(col("b")))?
-/// .aggregate(vec![col("a")], vec![min(col("b"))?])?
+/// .aggregate(vec![col("a")], vec![min(col("b"))])?
/// .limit(100)?;
/// let results = df.collect();
/// # Ok(())
diff --git a/rust/datafusion/src/logicalplan.rs b/rust/datafusion/src/logicalplan.rs
index 06b92f65f7..9aaa135e1b 100644
--- a/rust/datafusion/src/logicalplan.rs
+++ b/rust/datafusion/src/logicalplan.rs
@@ -559,28 +559,28 @@ pub fn col(name: &str) -> Expr {
}
/// Create an expression to represent the min() aggregate function
-pub fn min(expr: Expr) -> Result<Expr> {
- Ok(aggregate_expr("MIN", expr))
+pub fn min(expr: Expr) -> Expr {
+ aggregate_expr("MIN", expr)
}
/// Create an expression to represent the max() aggregate function
-pub fn max(expr: Expr) -> Result<Expr> {
- Ok(aggregate_expr("MAX", expr))
+pub fn max(expr: Expr) -> Expr {
+ aggregate_expr("MAX", expr)
}
/// Create an expression to represent the sum() aggregate function
-pub fn sum(expr: Expr) -> Result<Expr> {
- Ok(aggregate_expr("SUM", expr))
+pub fn sum(expr: Expr) -> Expr {
+ aggregate_expr("SUM", expr)
}
/// Create an expression to represent the avg() aggregate function
-pub fn avg(expr: Expr) -> Result<Expr> {
- Ok(aggregate_expr("AVG", expr))
+pub fn avg(expr: Expr) -> Expr {
+ aggregate_expr("AVG", expr)
}
/// Create an expression to represent the count() aggregate function
-pub fn count(expr: Expr) -> Result<Expr> {
- Ok(aggregate_expr("COUNT", expr))
+pub fn count(expr: Expr) -> Expr {
+ aggregate_expr("COUNT", expr)
}
/// Whether it can be represented as a literal expression