Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions datafusion/execution/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ impl Default for SessionConfig {
}

/// A type map for storing extensions.
///
///
/// Extensions are indexed by their type `T`. If multiple values of the same type are provided, only the last one
/// will be kept.
///
///
/// Extensions are opaque objects that are unknown to DataFusion itself but can be downcast by optimizer rules,
/// execution plans, or other components that have access to the session config.
/// They provide a flexible way to attach extra data or behavior to the session config.
Expand Down
15 changes: 13 additions & 2 deletions datafusion/physical-expr/src/simplifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ use datafusion_common::{
};
use std::sync::Arc;

use crate::PhysicalExpr;
use crate::{simplifier::not::simplify_not_expr_recursive, PhysicalExpr};

pub mod not;
pub mod unwrap_cast;

/// Simplifies physical expressions by applying various optimizations
Expand Down Expand Up @@ -56,6 +57,11 @@ impl<'a> TreeNodeRewriter for PhysicalExprSimplifier<'a> {
type Node = Arc<dyn PhysicalExpr>;

fn f_up(&mut self, node: Self::Node) -> Result<Transformed<Self::Node>> {
// Apply NOT expression simplification first
let not_simplified = simplify_not_expr_recursive(&node, self.schema)?;
Comment thread
xudong963 marked this conversation as resolved.
Outdated
let node = not_simplified.data;
let transformed = not_simplified.transformed;

// Apply unwrap cast optimization
#[cfg(test)]
let original_type = node.data_type(self.schema).unwrap();
Comment thread
alamb marked this conversation as resolved.
Expand All @@ -66,7 +72,12 @@ impl<'a> TreeNodeRewriter for PhysicalExprSimplifier<'a> {
original_type,
"Simplified expression should have the same data type as the original"
);
Ok(unwrapped)
// Combine transformation results
let final_transformed = transformed || unwrapped.transformed;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use transform_data here instead: https://docs.rs/datafusion/latest/datafusion/common/tree_node/struct.Transformed.html#method.transform_data

So something like

        // Apply NOT expression simplification first
        let rewritten =
            simplify_not_expr(&node, self.schema)?.transform_data(|node| {
                unwrap_cast::unwrap_cast_in_comparison(node, self.schema)
            })?;

That handles combining the transformed flag for you

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat, done in be077db.

Need to catch up on the tree node APIs, haha

Ok(Transformed::new_transformed(
unwrapped.data,
final_transformed,
))
}
}

Expand Down
Loading