@@ -31,7 +31,7 @@ use datafusion_common::tree_node::{
3131use datafusion_common:: utils:: has_float_leaf;
3232use datafusion_common:: {
3333 Column , DFSchema , DFSchemaRef , HashMap , Result , ScalarValue , assert_or_internal_err,
34- plan_err,
34+ internal_err , plan_err,
3535} ;
3636use datafusion_expr:: expr:: { Alias , GroupingSet } ;
3737use datafusion_expr:: expr_rewriter:: strip_outer_reference;
@@ -55,10 +55,12 @@ pub struct PullUpCorrelatedExpr {
5555 /// Correlated inner columns collected across the subquery, including their
5656 /// re-qualified names after passing through [`LogicalPlan::SubqueryAlias`].
5757 pub correlated_subquery_cols : BTreeSet < Column > ,
58- /// Deprecated: use [`Self::correlated_subquery_cols`] instead.
59- ///
6058 /// Kept for SemVer compatibility; populated with the root plan's
6159 /// correlated columns when the rewrite finishes.
60+ #[ deprecated(
61+ since = "56.0.0" ,
62+ note = "use `PullUpCorrelatedExpr::correlated_subquery_cols` instead"
63+ ) ]
6264 pub correlated_subquery_cols_map : HashMap < LogicalPlan , BTreeSet < Column > > ,
6365 pub in_predicate_opt : Option < Expr > ,
6466 /// Is this an Exists(Not Exists) SubQuery. Defaults to **FALSE**
@@ -83,7 +85,12 @@ pub struct PullUpCorrelatedExpr {
8385 ///
8486 /// [the count bug]: https://github.com/apache/datafusion/issues/10553
8587 pub need_handle_count_bug : bool ,
86- /// mapping from the plan to its expressions' evaluation result on empty batch
88+ /// Kept for SemVer compatibility; holds only the root plan's expressions'
89+ /// evaluation result on an empty batch when the rewrite finishes.
90+ #[ deprecated(
91+ since = "56.0.0" ,
92+ note = "use `PullUpCorrelatedExpr::root_count_expr_map` instead"
93+ ) ]
8794 pub collected_count_expr_map : HashMap < LogicalPlan , ExprResultMap > ,
8895 /// The root plan's expressions' evaluation result on an empty batch.
8996 pub root_count_expr_map : Option < ExprResultMap > ,
@@ -139,6 +146,7 @@ impl Default for PullUpCorrelatedExpr {
139146}
140147
141148impl PullUpCorrelatedExpr {
149+ #[ expect( deprecated) ]
142150 pub fn new ( ) -> Self {
143151 Self {
144152 join_filters : vec ! [ ] ,
@@ -412,10 +420,15 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
412420 // `column_refs_above` holds only the nodes strictly above `plan` and
413421 // `frame` holds the state pulled up from `plan`'s children.
414422 self . column_refs_above . pop ( ) ;
415- let PullUpFrame {
423+ let Some ( PullUpFrame {
416424 correlated_cols : local_correlated_cols,
417425 count_expr_map : input_count_expr_map,
418- } = self . pulled_up_frames . pop ( ) . unwrap_or_default ( ) ;
426+ } ) = self . pulled_up_frames . pop ( )
427+ else {
428+ return internal_err ! (
429+ "PullUpCorrelatedExpr: f_up without a matching f_down frame"
430+ ) ;
431+ } ;
419432
420433 // A node that null-extends or regroups rows can put a NULL back into
421434 // a column that a correlated filter below it rejected, so the filters
@@ -753,6 +766,12 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
753766 . pass_through_pulled_up_cols ( plan, input_count_expr_map. is_some ( ) ) ?;
754767 ( transformed, local_correlated_cols, None )
755768 }
769+ LogicalPlan :: Join ( _) | LogicalPlan :: AsOfJoin ( _)
770+ if self . pulled_up_scalar_agg =>
771+ {
772+ self . can_pull_up = false ;
773+ return Ok ( Transformed :: new ( plan, false , TreeNodeRecursion :: Stop ) ) ;
774+ }
756775 // `f_down` checked that the pulled up filters do not read an
757776 // unnested column.
758777 LogicalPlan :: Unnest ( _)
@@ -773,11 +792,13 @@ impl TreeNodeRewriter for PullUpCorrelatedExpr {
773792 parent. count_expr_map = out_count_expr_map;
774793 }
775794 } else {
795+ #[ expect( deprecated) ]
776796 self . correlated_subquery_cols_map . insert (
777797 transformed. data . clone ( ) ,
778798 self . correlated_subquery_cols . clone ( ) ,
779799 ) ;
780800 if let Some ( ref map) = out_count_expr_map {
801+ #[ expect( deprecated) ]
781802 self . collected_count_expr_map
782803 . insert ( transformed. data . clone ( ) , map. clone ( ) ) ;
783804 }
0 commit comments