jayzhan211 commented on code in PR #14824:
URL: https://github.com/apache/datafusion/pull/14824#discussion_r1966519181


##########
datafusion/physical-plan/src/aggregates/mod.rs:
##########
@@ -1231,6 +1233,13 @@ fn evaluate(
     expr: &[Arc<dyn PhysicalExpr>],
     batch: &RecordBatch,
 ) -> Result<Vec<ArrayRef>> {
+    // handle count() case
+    if expr.is_empty() {
+        return Ok(vec![
+            Arc::new(Int64Array::from(vec![1; batch.num_rows()])) as ArrayRef

Review Comment:
   This is equivalent to `count(1)` case



##########
datafusion/physical-plan/src/aggregates/no_grouping.rs:
##########
@@ -219,23 +220,26 @@ fn aggregate_batch(
                 None => Cow::Borrowed(&batch),
             };
 
+            let n_rows = batch.num_rows();
+
             // 1.3
-            let values = &expr
-                .iter()
-                .map(|e| {
-                    e.evaluate(&batch)
-                        .and_then(|v| v.into_array(batch.num_rows()))
-                })
-                .collect::<Result<Vec<_>>>()?;
+            // Handle count(*) case
+            let values = if expr.is_empty() {
+                vec![Arc::new(Int64Array::from(vec![1; n_rows])) as ArrayRef]

Review Comment:
   This is equivalent to count(1) case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to