From e222bd627b6e7974133364fed4600d74b4da6811 Mon Sep 17 00:00:00 2001 From: jakevin Date: Tue, 7 Feb 2023 22:49:30 +0800 Subject: [PATCH] bugfix: fix `TableScan` may contain fields not included in `schema` (#5188) --- datafusion/optimizer/src/push_down_projection.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/datafusion/optimizer/src/push_down_projection.rs b/datafusion/optimizer/src/push_down_projection.rs index 6d9d342ecbba..85bdca1737c1 100644 --- a/datafusion/optimizer/src/push_down_projection.rs +++ b/datafusion/optimizer/src/push_down_projection.rs @@ -291,6 +291,10 @@ fn optimize_plan( // scans: // * remove un-used columns from the scan projection LogicalPlan::TableScan(scan) => { + // filter expr may not exist in expr in projection. + // like: TableScan: t1 projection=[bool_col, int_col], full_filters=[t1.id = Int32(1)] + // projection=[bool_col, int_col] don't contain `ti.id`. + exprlist_to_columns(&scan.filters, &mut new_required_columns)?; push_down_scan(scan, &new_required_columns, has_projection) } LogicalPlan::Explain { .. } => Err(DataFusionError::Internal(