Skip to content

Commit 7e38714

Browse files
authored
Refactor: Do not silently ignore errors in stats_projection (#17154)
1 parent e3d3257 commit 7e38714

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

datafusion/physical-plan/src/projection.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ impl ExecutionPlan for ProjectionExec {
246246

247247
fn partition_statistics(&self, partition: Option<usize>) -> Result<Statistics> {
248248
let input_stats = self.input.partition_statistics(partition)?;
249-
Ok(stats_projection(
249+
stats_projection(
250250
input_stats,
251251
self.expr.iter().map(|(e, _)| Arc::clone(e)),
252252
Arc::clone(&self.input.schema()),
253-
))
253+
)
254254
}
255255

256256
fn supports_limit_pushdown(&self) -> bool {
@@ -279,7 +279,7 @@ fn stats_projection(
279279
mut stats: Statistics,
280280
exprs: impl Iterator<Item = Arc<dyn PhysicalExpr>>,
281281
schema: SchemaRef,
282-
) -> Statistics {
282+
) -> Result<Statistics> {
283283
let mut primitive_row_size = 0;
284284
let mut primitive_row_size_possible = true;
285285
let mut column_statistics = vec![];
@@ -292,11 +292,10 @@ fn stats_projection(
292292
ColumnStatistics::new_unknown()
293293
};
294294
column_statistics.push(col_stats);
295-
if let Ok(data_type) = expr.data_type(&schema) {
296-
if let Some(value) = data_type.primitive_width() {
297-
primitive_row_size += value;
298-
continue;
299-
}
295+
let data_type = expr.data_type(&schema)?;
296+
if let Some(value) = data_type.primitive_width() {
297+
primitive_row_size += value;
298+
continue;
300299
}
301300
primitive_row_size_possible = false;
302301
}
@@ -306,7 +305,7 @@ fn stats_projection(
306305
Precision::Exact(primitive_row_size).multiply(&stats.num_rows);
307306
}
308307
stats.column_statistics = column_statistics;
309-
stats
308+
Ok(stats)
310309
}
311310

312311
impl ProjectionStream {
@@ -1171,7 +1170,8 @@ mod tests {
11711170
Arc::new(Column::new("col0", 0)),
11721171
];
11731172

1174-
let result = stats_projection(source, exprs.into_iter(), Arc::new(schema));
1173+
let result =
1174+
stats_projection(source, exprs.into_iter(), Arc::new(schema)).unwrap();
11751175

11761176
let expected = Statistics {
11771177
num_rows: Precision::Exact(5),
@@ -1207,7 +1207,8 @@ mod tests {
12071207
Arc::new(Column::new("col0", 0)),
12081208
];
12091209

1210-
let result = stats_projection(source, exprs.into_iter(), Arc::new(schema));
1210+
let result =
1211+
stats_projection(source, exprs.into_iter(), Arc::new(schema)).unwrap();
12111212

12121213
let expected = Statistics {
12131214
num_rows: Precision::Exact(5),

0 commit comments

Comments
 (0)