Skip to content
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

improve eliminate_outer_join rule #13249

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions datafusion/core/tests/expr_api/simplification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ fn schema() -> DFSchemaRef {
Schema::new(vec![
Field::new("a", DataType::Int32, true),
Field::new("b", DataType::Int32, false),
Field::new("c", DataType::Int32, false),
Field::new("s", DataType::Utf8, false),
])
.to_dfschema_ref()
Expand Down
28 changes: 24 additions & 4 deletions datafusion/expr/src/expr_rewriter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

//! Expression rewriter

use crate::expr::{Alias, Sort, Unnest};
use crate::logical_plan::Projection;
use crate::{Expr, ExprSchemable, LogicalPlan, LogicalPlanBuilder};
use arrow::datatypes::DataType;
use std::collections::HashMap;
use std::collections::HashSet;
use std::fmt::Debug;
use std::sync::Arc;

use crate::expr::{Alias, Sort, Unnest};
use crate::logical_plan::Projection;
use crate::{Expr, ExprSchemable, LogicalPlan, LogicalPlanBuilder};

use datafusion_common::config::ConfigOptions;
use datafusion_common::tree_node::{Transformed, TransformedResult, TreeNode};
use datafusion_common::TableReference;
Expand Down Expand Up @@ -148,6 +148,26 @@ pub fn replace_col(expr: Expr, replace_map: &HashMap<&Column, &Column>) -> Resul
.data()
}

pub fn replace_expr_with_null(
expr: Expr,
replace_columns: &HashMap<&Column, &DataType>,
) -> Result<Expr> {
expr.transform(|expr| {
Ok({
match &expr {
Expr::Column(c) => match replace_columns.get(c) {
Some(data_type) => {
Transformed::yes(Expr::Literal((*data_type).try_into()?))
}
None => Transformed::no(expr),
},
_ => Transformed::no(expr),
}
})
})
.data()
}

/// Recursively 'unnormalize' (remove all qualifiers) from an
/// expression tree.
///
Expand Down
Loading