Skip to content

dynamic filter refactor #15685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions datafusion/physical-expr-common/src/physical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::utils::scatter;

use arrow::array::BooleanArray;
use arrow::compute::filter_record_batch;
use arrow::datatypes::{DataType, Schema};
use arrow::datatypes::{DataType, Schema, SchemaRef};
use arrow::record_batch::RecordBatch;
use datafusion_common::tree_node::{Transformed, TransformedResult, TreeNode};
use datafusion_common::{internal_err, not_impl_err, Result, ScalarValue};
Expand Down Expand Up @@ -327,7 +327,10 @@ pub trait PhysicalExpr: Send + Sync + Display + Debug + DynEq + DynHash {
///
/// Note for implementers: this method should *not* handle recursion.
/// Recursion is handled in [`snapshot_physical_expr`].
fn snapshot(&self) -> Result<Option<Arc<dyn PhysicalExpr>>> {
fn snapshot(
&self,
remapped_schema: Option<SchemaRef>,
) -> Result<Option<Arc<dyn PhysicalExpr>>> {
// By default, we return None to indicate that this PhysicalExpr does not
// have any dynamic references or state.
// This is a safe default behavior.
Expand Down Expand Up @@ -513,9 +516,10 @@ pub fn fmt_sql(expr: &dyn PhysicalExpr) -> impl Display + '_ {
/// any dynamic references or state, it returns `None`.
pub fn snapshot_physical_expr(
expr: Arc<dyn PhysicalExpr>,
schema: Option<SchemaRef>,
) -> Result<Arc<dyn PhysicalExpr>> {
expr.transform_up(|e| {
if let Some(snapshot) = e.snapshot()? {
if let Some(snapshot) = e.snapshot(schema.clone())? {
Ok(Transformed::yes(snapshot))
} else {
Ok(Transformed::no(Arc::clone(&e)))
Expand Down
Loading
Loading