jackwener commented on code in PR #7428:
URL: https://github.com/apache/arrow-datafusion/pull/7428#discussion_r1307271741
##########
datafusion/core/src/physical_plan/projection.rs:
##########
@@ -410,12 +415,39 @@ fn stats_projection(
.collect()
});
- Statistics {
- is_exact: stats.is_exact,
- num_rows: stats.num_rows,
- column_statistics,
- // TODO stats: knowing the type of the new columns we can guess the
output size
- total_byte_size: None,
+ let primitive_row_size = inner_exprs
+ .clone()
+ .into_iter()
+ .map(|e| match e.data_type(schema.as_ref()) {
+ Ok(data_type) => data_type.primitive_width(),
+ Err(_) => None,
+ })
+ .fold(Some(0usize), |init, v| match (init, v) {
+ (Some(l), Some(r)) => Some(l + r),
+ _ => None,
+ });
+
+ match (primitive_row_size, stats.num_rows) {
+ (Some(row_size), Some(row_count)) => {
+ Statistics {
+ is_exact: stats.is_exact,
+ num_rows: stats.num_rows,
+ column_statistics,
+ // Use the row_size * row_count as the total byte size
+ total_byte_size: Some(row_size * row_count),
+ }
+ }
+ _ => {
+ Statistics {
+ is_exact: stats.is_exact,
+ num_rows: stats.num_rows,
+ column_statistics,
+ // TODO stats: knowing the type of the new columns we can
guess the output size
+ // If we can't get the exact statistics for the project
+ // Before we get the exact result, we just use the child status
+ total_byte_size: stats.total_byte_size,
Review Comment:
I think they are different things.
`stats.is_exact` is for the whole statistic. Current `num_rows` is exact.
Maybe we need add Unknow status for `total_byte_size`.
such as Presto:
```
PlanNodeStatsEstimate UNKNOWN. It's present `Unknown` for whole statistic.
SymbolStatsEstimate UNKNOWN. It's present `Unknown` for single expr
statistic.
```
--
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]