Skip to content

Commit 61a5139

Browse files
committed
Refactor: Do not silently ignore errors in stats_projection
1 parent 00c2191 commit 61a5139

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.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 {
@@ -1169,7 +1168,8 @@ mod tests {
11691168
Arc::new(Column::new("col0", 0)),
11701169
];
11711170

1172-
let result = stats_projection(source, exprs.into_iter(), Arc::new(schema));
1171+
let result =
1172+
stats_projection(source, exprs.into_iter(), Arc::new(schema)).unwrap();
11731173

11741174
let expected = Statistics {
11751175
num_rows: Precision::Exact(5),
@@ -1205,7 +1205,8 @@ mod tests {
12051205
Arc::new(Column::new("col0", 0)),
12061206
];
12071207

1208-
let result = stats_projection(source, exprs.into_iter(), Arc::new(schema));
1208+
let result =
1209+
stats_projection(source, exprs.into_iter(), Arc::new(schema)).unwrap();
12091210

12101211
let expected = Statistics {
12111212
num_rows: Precision::Exact(5),

0 commit comments

Comments
 (0)