gruuya commented on code in PR #9944:
URL: https://github.com/apache/arrow-datafusion/pull/9944#discussion_r1551563337
##########
datafusion/expr/src/utils.rs:
##########
@@ -42,7 +42,7 @@ use sqlparser::ast::{ExceptSelectItem, ExcludeSelectItem,
WildcardAdditionalOpti
/// The value to which `COUNT(*)` is expanded to in
/// `COUNT(<constant>)` expressions
-pub const COUNT_STAR_EXPANSION: ScalarValue = ScalarValue::UInt8(Some(1));
+pub const COUNT_STAR_EXPANSION: ScalarValue = ScalarValue::Int64(Some(1));
Review Comment:
This does however result in `count(1)` being auto-named to `count(*)` now.
```bash
❯ explain select count(1) from hits;
+---------------+---------------------------------------------------+
| plan_type | plan |
+---------------+---------------------------------------------------+
| logical_plan | Aggregate: groupBy=[[]], aggr=[[COUNT(Int64(1))]] |
| | TableScan: hits projection=[] |
| physical_plan | ProjectionExec: expr=[99997497 as COUNT(*)] |
| | PlaceholderRowExec |
| | |
+---------------+---------------------------------------------------+
2 row(s) fetched.
Elapsed 0.263 seconds.
❯ select count(1) from hits;
+----------+
| COUNT(*) |
+----------+
| 99997497 |
+----------+
1 row(s) fetched.
Elapsed 0.015 seconds.
```
That might be fine as it reduces ambiguity.
Otherwise it could be resolved by e.g.:
```diff
diff --git a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
b/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
index df5422227..0e35b6a2b 100644
--- a/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
+++ b/datafusion/core/src/physical_optimizer/aggregate_statistics.rs
@@ -160,6 +160,11 @@ fn take_optimizable_table_count(
ScalarValue::Int64(Some(num_rows as i64)),
COUNT_STAR_NAME,
));
+ } else if lit_expr.value() == &ScalarValue::Int64(Some(1)) {
+ return Some((
+ ScalarValue::Int64(Some(num_rows as i64)),
+ "COUNT(1)",
+ ));
}
}
}
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]