EmilyMatt commented on code in PR #19419:
URL: https://github.com/apache/datafusion/pull/19419#discussion_r2653188838
##########
datafusion/physical-expr/src/projection.rs:
##########
@@ -587,6 +587,54 @@ impl ProjectionExprs {
let expr = &proj_expr.expr;
let col_stats = if let Some(col) =
expr.as_any().downcast_ref::<Column>() {
std::mem::take(&mut stats.column_statistics[col.index()])
+ } else if let Some(literal) =
expr.as_any().downcast_ref::<Literal>() {
+ // Handle literal expressions (constants) by calculating
proper statistics
+ let data_type = expr.data_type(output_schema)?;
+
+ if literal.value().is_null() {
+ let null_count = match stats.num_rows {
+ Precision::Exact(num_rows) =>
Precision::Exact(num_rows),
+ _ => Precision::Absent,
+ };
+
+ ColumnStatistics {
+ min_value: Precision::Absent,
+ max_value: Precision::Absent,
+ distinct_count: Precision::Exact(1),
+ null_count,
+ sum_value: Precision::Absent,
+ byte_size: Precision::Absent,
+ }
+ } else {
+ let value = literal.value();
+ let distinct_count = Precision::Exact(1);
+ let null_count = Precision::Exact(0);
+
+ let byte_size = if let Some(byte_width) =
data_type.primitive_width()
+ {
+ stats.num_rows.multiply(&Precision::Exact(byte_width))
+ } else {
+ // Complex types depend on array encoding, so set to
Absent
+ Precision::Absent
Review Comment:
I think this can be Estimated, but not very critical
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]