@@ -122,7 +122,6 @@ struct ExpressionLookupTable {
122122 lookup : Box < dyn WhenLiteralIndexMap > ,
123123 num_branches : usize ,
124124 else_index : u32 ,
125- projection : Vec < usize > ,
126125}
127126
128127impl Hash for ExpressionLookupTable {
@@ -175,13 +174,11 @@ impl ExpressionLookupTable {
175174 }
176175
177176 let lookup = try_creating_lookup_table ( unique_when_literals) . ok ( ) ?;
178- let projection = build_projection ( body) ;
179177
180178 Some ( Self {
181179 lookup,
182180 num_branches : body. when_then_expr . len ( ) ,
183181 else_index : body. when_then_expr . len ( ) as u32 ,
184- projection,
185182 } )
186183 }
187184
@@ -191,32 +188,6 @@ impl ExpressionLookupTable {
191188 }
192189}
193190
194- fn build_projection ( body : & CaseBody ) -> Vec < usize > {
195- let mut used_column_indices = IndexSet :: < usize > :: new ( ) ;
196- let mut collect = |expr : & Arc < dyn PhysicalExpr > | {
197- expr. apply ( |e| {
198- if let Some ( col) = e. as_any ( ) . downcast_ref :: < Column > ( ) {
199- used_column_indices. insert ( col. index ( ) ) ;
200- }
201- Ok ( TreeNodeRecursion :: Continue )
202- } )
203- . expect ( "Closure cannot fail" ) ;
204- } ;
205-
206- if let Some ( e) = & body. expr {
207- collect ( e) ;
208- }
209- body. when_then_expr . iter ( ) . for_each ( |( w, t) | {
210- collect ( w) ;
211- collect ( t) ;
212- } ) ;
213- if let Some ( e) = & body. else_expr {
214- collect ( e) ;
215- }
216-
217- used_column_indices. into_iter ( ) . collect ( )
218- }
219-
220191/// The body of a CASE expression which consists of an optional base expression, the "when/then"
221192/// branches and an optional "else" branch.
222193#[ derive( Debug , Hash , PartialEq , Eq ) ]
@@ -1323,12 +1294,6 @@ impl CaseExpr {
13231294 }
13241295 }
13251296
1326- let working_batch = if lookup_table. projection . len ( ) < batch. num_columns ( ) {
1327- Cow :: Owned ( batch. project ( & lookup_table. projection ) ?)
1328- } else {
1329- Cow :: Borrowed ( batch)
1330- } ;
1331-
13321297 let mut result_builder = ResultBuilder :: new ( & return_type, row_count) ;
13331298
13341299 for ( branch_idx, rows) in branch_rows
@@ -1342,7 +1307,7 @@ impl CaseExpr {
13421307
13431308 let row_indices = Arc :: new ( UInt32Array :: from ( rows. clone ( ) ) ) as ArrayRef ;
13441309 let filter_predicate = create_filter_from_indices ( rows, row_count) ;
1345- let filtered_batch = filter_record_batch ( & working_batch , & filter_predicate) ?;
1310+ let filtered_batch = filter_record_batch ( batch , & filter_predicate) ?;
13461311
13471312 let then_expr = & self . body . when_then_expr [ branch_idx] . 1 ;
13481313 let then_value = then_expr. evaluate ( & filtered_batch) ?;
@@ -1356,7 +1321,7 @@ impl CaseExpr {
13561321 {
13571322 let row_indices = Arc :: new ( UInt32Array :: from ( else_rows. clone ( ) ) ) as ArrayRef ;
13581323 let filter_predicate = create_filter_from_indices ( else_rows, row_count) ;
1359- let filtered_batch = filter_record_batch ( & working_batch , & filter_predicate) ?;
1324+ let filtered_batch = filter_record_batch ( batch , & filter_predicate) ?;
13601325 let else_value = else_expr. evaluate ( & filtered_batch) ?;
13611326 result_builder. add_branch_result ( & row_indices, else_value) ?;
13621327 }
0 commit comments