Skip to content

Commit 26e5c46

Browse files
Deprecate FilterExec with_* methods in favor of FilterExecBuilder
As suggested in PR review, deprecate with_projection(), with_default_selectivity(), and with_batch_size() methods on FilterExec. These methods now use FilterExecBuilder internally for backward compatibility while guiding users toward the builder pattern. - Marked methods as deprecated since 51.0.0 - Re-implemented using FilterExecBuilder to maintain functionality - All 114 filter tests passing - Provides gentle migration path for users
1 parent 5273fe8 commit 26e5c46

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

datafusion/physical-plan/src/filter.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,28 @@ impl FilterExec {
194194
FilterExecBuilder::new(predicate, input).build()
195195
}
196196

197+
/// Set the default selectivity
198+
///
199+
/// # Deprecated
200+
/// Use [`FilterExecBuilder::with_default_selectivity`] instead
201+
#[deprecated(since = "51.0.0", note = "Use FilterExecBuilder::with_default_selectivity instead")]
197202
pub fn with_default_selectivity(
198-
mut self,
203+
self,
199204
default_selectivity: u8,
200205
) -> Result<Self, DataFusionError> {
201-
if default_selectivity > 100 {
202-
return plan_err!(
203-
"Default filter selectivity value needs to be less than or equal to 100"
204-
);
205-
}
206-
self.default_selectivity = default_selectivity;
207-
Ok(self)
206+
FilterExecBuilder::new(self.predicate.clone(), self.input.clone())
207+
.with_projection(self.projection.clone())
208+
.with_default_selectivity(default_selectivity)
209+
.with_batch_size(self.batch_size)
210+
.with_fetch(self.fetch)
211+
.build()
208212
}
209213

210214
/// Return new instance of [FilterExec] with the given projection.
215+
///
216+
/// # Deprecated
217+
/// Use [`FilterExecBuilder::with_projection`] instead
218+
#[deprecated(since = "51.0.0", note = "Use FilterExecBuilder::with_projection instead")]
211219
pub fn with_projection(&self, projection: Option<Vec<usize>>) -> Result<Self> {
212220
// Check if the projection is valid
213221
can_project(&self.schema(), projection.as_ref())?;
@@ -220,35 +228,26 @@ impl FilterExec {
220228
None => None,
221229
};
222230

223-
let cache = Self::compute_properties(
224-
&self.input,
225-
&self.predicate,
226-
self.default_selectivity,
227-
projection.as_ref(),
228-
)?;
229-
Ok(Self {
230-
predicate: Arc::clone(&self.predicate),
231-
input: Arc::clone(&self.input),
232-
metrics: self.metrics.clone(),
233-
default_selectivity: self.default_selectivity,
234-
cache,
235-
projection,
236-
batch_size: self.batch_size,
237-
fetch: self.fetch,
238-
})
231+
FilterExecBuilder::new(self.predicate.clone(), self.input.clone())
232+
.with_projection(projection)
233+
.with_default_selectivity(self.default_selectivity)
234+
.with_batch_size(self.batch_size)
235+
.with_fetch(self.fetch)
236+
.build()
239237
}
240238

239+
/// Set the batch size
240+
///
241+
/// # Deprecated
242+
/// Use [`FilterExecBuilder::with_batch_size`] instead
243+
#[deprecated(since = "51.0.0", note = "Use FilterExecBuilder::with_batch_size instead")]
241244
pub fn with_batch_size(&self, batch_size: usize) -> Result<Self> {
242-
Ok(Self {
243-
predicate: Arc::clone(&self.predicate),
244-
input: Arc::clone(&self.input),
245-
metrics: self.metrics.clone(),
246-
default_selectivity: self.default_selectivity,
247-
cache: self.cache.clone(),
248-
projection: self.projection.clone(),
249-
batch_size,
250-
fetch: self.fetch,
251-
})
245+
FilterExecBuilder::new(self.predicate.clone(), self.input.clone())
246+
.with_projection(self.projection.clone())
247+
.with_default_selectivity(self.default_selectivity)
248+
.with_batch_size(batch_size)
249+
.with_fetch(self.fetch)
250+
.build()
252251
}
253252

254253
/// The expression to filter on. This expression must evaluate to a boolean value.

0 commit comments

Comments
 (0)