Skip to content

Commit

Permalink
move to expr
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <jayzhan211@gmail.com>
  • Loading branch information
jayzhan211 committed Mar 2, 2024
1 parent b69b33f commit adcb2e2
Show file tree
Hide file tree
Showing 35 changed files with 70 additions and 61 deletions.
1 change: 1 addition & 0 deletions datafusion-cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions datafusion-examples/examples/expr_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ use arrow::record_batch::RecordBatch;
use datafusion::arrow::datatypes::{DataType, Field, Schema, TimeUnit};
use datafusion::common::{DFField, DFSchema};
use datafusion::error::Result;
use datafusion::optimizer::simplify_expressions::{ExprSimplifier, SimplifyContext};
use datafusion::physical_expr::execution_props::ExecutionProps;
use datafusion::optimizer::simplify_expressions::ExprSimplifier;
use datafusion::physical_expr::{
analyze, create_physical_expr, AnalysisContext, ExprBoundaries, PhysicalExpr,
};
use datafusion::prelude::*;
use datafusion_common::{ScalarValue, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::expr::BinaryExpr;
use datafusion_expr::interval_arithmetic::Interval;
use datafusion_expr::simplify::SimplifyContext;
use datafusion_expr::{ColumnarValue, ExprSchemable, Operator};
use std::collections::HashMap;
use std::sync::Arc;
Expand Down
3 changes: 2 additions & 1 deletion datafusion-examples/examples/simple_udtf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ use datafusion::physical_plan::memory::MemoryExec;
use datafusion::physical_plan::ExecutionPlan;
use datafusion::prelude::SessionContext;
use datafusion_common::{plan_err, DataFusionError, ScalarValue};
use datafusion_expr::simplify::SimplifyContext;
use datafusion_expr::{Expr, TableType};
use datafusion_optimizer::simplify_expressions::{ExprSimplifier, SimplifyContext};
use datafusion_optimizer::simplify_expressions::ExprSimplifier;
use std::fs::File;
use std::io::Seek;
use std::path::Path;
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/datasource/listing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use crate::datasource::listing::ListingTableUrl;
use crate::execution::context::SessionState;
use datafusion_common::tree_node::{TreeNode, VisitRecursion};
use datafusion_common::{internal_err, Column, DFField, DFSchema, DataFusionError};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::{Expr, ScalarFunctionDefinition, Volatility};
use datafusion_physical_expr::create_physical_expr;
use datafusion_physical_expr::execution_props::ExecutionProps;
use object_store::path::Path;
use object_store::{ObjectMeta, ObjectStore};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,9 @@ mod tests {
use chrono::{TimeZone, Utc};
use datafusion_common::{assert_contains, ToDFSchema};
use datafusion_common::{FileType, GetExt, ScalarValue};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::{col, lit, when, Expr};
use datafusion_physical_expr::create_physical_expr;
use datafusion_physical_expr::execution_props::ExecutionProps;
use futures::StreamExt;
use object_store::local::LocalFileSystem;
use object_store::path::Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ mod test {
use super::*;
use arrow::datatypes::Field;
use datafusion_common::ToDFSchema;
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::{cast, col, lit, Expr};
use datafusion_physical_expr::create_physical_expr;
use datafusion_physical_expr::execution_props::ExecutionProps;
use parquet::arrow::parquet_to_arrow_schema;
use parquet::file::reader::{FileReader, SerializedFileReader};
use rand::prelude::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ mod tests {
use arrow::datatypes::Schema;
use arrow::datatypes::{DataType, Field};
use datafusion_common::{Result, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::{cast, col, lit, Expr};
use datafusion_physical_expr::execution_props::ExecutionProps;
use datafusion_physical_expr::{create_physical_expr, PhysicalExpr};
use parquet::arrow::arrow_to_parquet_schema;
use parquet::arrow::async_reader::ParquetObjectReader;
Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ use datafusion_common::{
tree_node::{TreeNode, TreeNodeVisitor, VisitRecursion},
};
use datafusion_execution::registry::SerializerRegistry;
pub use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::var_provider::is_system_variables;
use datafusion_expr::{
logical_plan::{DdlStatement, Statement},
Expr, StringifiedPlan, UserDefinedLogicalNode, WindowUDF,
};
pub use datafusion_physical_expr::execution_props::ExecutionProps;
use datafusion_physical_expr::var_provider::is_system_variables;
use parking_lot::RwLock;
use std::collections::hash_map::Entry;
use std::string::String;
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/physical_optimizer/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,10 +1338,10 @@ mod tests {
datatypes::{DataType, TimeUnit},
};
use datafusion_common::{ScalarValue, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::expr::InList;
use datafusion_expr::{cast, is_null, try_cast, Expr};
use datafusion_physical_expr::create_physical_expr;
use datafusion_physical_expr::execution_props::ExecutionProps;
use std::collections::HashMap;
use std::ops::{Not, Rem};

Expand Down
5 changes: 3 additions & 2 deletions datafusion/core/src/test_util/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ use crate::datasource::listing::{ListingTableUrl, PartitionedFile};
use crate::datasource::object_store::ObjectStoreUrl;
use crate::datasource::physical_plan::{FileScanConfig, ParquetExec};
use crate::error::Result;
use crate::optimizer::simplify_expressions::{ExprSimplifier, SimplifyContext};
use crate::logical_expr::execution_props::ExecutionProps;
use crate::logical_expr::simplify::SimplifyContext;
use crate::optimizer::simplify_expressions::ExprSimplifier;
use crate::physical_expr::create_physical_expr;
use crate::physical_expr::execution_props::ExecutionProps;
use crate::physical_plan::filter::FilterExec;
use crate::physical_plan::metrics::MetricsSet;
use crate::physical_plan::ExecutionPlan;
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/src/variable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

//! Variable provider for `@name` and `@@name` style runtime values.

pub use datafusion_physical_expr::var_provider::{VarProvider, VarType};
pub use datafusion_expr::var_provider::{VarProvider, VarType};
2 changes: 1 addition & 1 deletion datafusion/core/tests/dataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ use datafusion_common::{assert_contains, DataFusionError, ScalarValue, UnnestOpt
use datafusion_execution::config::SessionConfig;
use datafusion_execution::runtime_env::RuntimeEnv;
use datafusion_expr::expr::{GroupingSet, Sort};
use datafusion_expr::var_provider::{VarProvider, VarType};
use datafusion_expr::{
array_agg, avg, cast, col, count, exists, expr, in_subquery, lit, max, out_ref_col,
placeholder, scalar_subquery, sum, when, wildcard, AggregateFunction, Expr,
ExprSchemable, WindowFrame, WindowFrameBound, WindowFrameUnits,
WindowFunctionDefinition,
};
use datafusion_physical_expr::var_provider::{VarProvider, VarType};

#[tokio::test]
async fn test_count_wildcard_on_sort() -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/parquet/page_pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use datafusion::physical_plan::metrics::MetricValue;
use datafusion::physical_plan::ExecutionPlan;
use datafusion::prelude::SessionContext;
use datafusion_common::{ScalarValue, Statistics, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::{col, lit, Expr};
use datafusion_physical_expr::create_physical_expr;
use datafusion_physical_expr::execution_props::ExecutionProps;

use futures::StreamExt;
use object_store::path::Path;
Expand Down
3 changes: 2 additions & 1 deletion datafusion/core/tests/simplification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
use arrow::datatypes::{DataType, Field, Schema};
use datafusion::{error::Result, execution::context::ExecutionProps, prelude::*};
use datafusion_common::{DFSchemaRef, ToDFSchema};
use datafusion_expr::simplify::SimplifyInfo;
use datafusion_expr::{Expr, ExprSchemable};
use datafusion_optimizer::simplify_expressions::{ExprSimplifier, SimplifyInfo};
use datafusion_optimizer::simplify_expressions::ExprSimplifier;

/// In order to simplify expressions, DataFusion must have information
/// about the expressions.
Expand Down
1 change: 1 addition & 0 deletions datafusion/expr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ahash = { version = "0.8", default-features = false, features = [
] }
arrow = { workspace = true }
arrow-array = { workspace = true }
chrono = { workspace = true }
datafusion-common = { workspace = true }
paste = "^1.0"
sqlparser = { workspace = true }
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions datafusion/expr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod udwf;

pub mod aggregate_function;
pub mod conditional_expressions;
pub mod execution_props;
pub mod expr;
pub mod expr_fn;
pub mod expr_rewriter;
Expand All @@ -49,9 +50,11 @@ pub mod function;
pub mod groups_accumulator;
pub mod interval_arithmetic;
pub mod logical_plan;
pub mod simplify;
pub mod tree_node;
pub mod type_coercion;
pub mod utils;
pub mod var_provider;
pub mod window_frame;
pub mod window_state;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

use arrow::datatypes::DataType;
use datafusion_common::{DFSchemaRef, DataFusionError, Result};
use datafusion_expr::{Expr, ExprSchemable};
use datafusion_physical_expr::execution_props::ExecutionProps;

use crate::{execution_props::ExecutionProps, Expr, ExprSchemable};

#[allow(rustdoc::private_intra_doc_links)]
/// The information necessary to apply algebraic simplification to an
Expand Down Expand Up @@ -54,8 +54,9 @@ pub trait SimplifyInfo {
/// use arrow::datatypes::{Schema, Field, DataType};
/// use datafusion_expr::{col, lit};
/// use datafusion_common::{DataFusionError, ToDFSchema};
/// use datafusion_physical_expr::execution_props::ExecutionProps;
/// use datafusion_optimizer::simplify_expressions::{SimplifyContext, ExprSimplifier};
/// use datafusion_expr::execution_props::ExecutionProps;
/// use datafusion_expr::simplify::SimplifyContext;
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
///
/// // Create the schema
/// let schema = Schema::new(vec![
Expand Down
1 change: 1 addition & 0 deletions datafusion/expr/src/udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use std::fmt::Debug;
use std::fmt::Formatter;
use std::sync::Arc;

// TODO(In this PR): Move to simplify.rs
/// Was the expression simplified?
pub enum Simplified {
/// The function call was simplified to an entirely new Expr
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions datafusion/optimizer/src/decorrelate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
// specific language governing permissions and limitations
// under the License.

use crate::simplify_expressions::{ExprSimplifier, SimplifyContext};
use crate::simplify_expressions::ExprSimplifier;
use crate::utils::collect_subquery_cols;
use datafusion_common::tree_node::{
RewriteRecursion, Transformed, TreeNode, TreeNodeRewriter,
};
use datafusion_common::{plan_err, Result};
use datafusion_common::{Column, DFSchemaRef, DataFusionError, ScalarValue};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::expr::{AggregateFunctionDefinition, Alias};
use datafusion_expr::simplify::SimplifyContext;
use datafusion_expr::utils::{conjunction, find_join_exprs, split_conjunction};
use datafusion_expr::{expr, EmptyRelation, Expr, LogicalPlan, LogicalPlanBuilder};
use datafusion_physical_expr::execution_props::ExecutionProps;
use std::collections::{BTreeSet, HashMap};
use std::ops::Deref;

Expand Down
30 changes: 16 additions & 14 deletions datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use super::utils::*;
use crate::analyzer::type_coercion::TypeCoercionRewriter;
use crate::simplify_expressions::guarantees::GuaranteeRewriter;
use crate::simplify_expressions::regex::simplify_regex_expr;
use crate::simplify_expressions::SimplifyInfo;

use arrow::{
array::{new_null_array, AsArray},
Expand All @@ -39,12 +38,14 @@ use datafusion_common::{
use datafusion_common::{
internal_err, DFSchema, DFSchemaRef, DataFusionError, Result, ScalarValue,
};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::simplify::SimplifyInfo;
use datafusion_expr::{
and, lit, or, BinaryExpr, BuiltinScalarFunction, Case, ColumnarValue, Expr, Like,
ScalarFunctionDefinition, Volatility,
};
use datafusion_expr::{expr::ScalarFunction, interval_arithmetic::NullableInterval};
use datafusion_physical_expr::{create_physical_expr, execution_props::ExecutionProps};
use datafusion_physical_expr::create_physical_expr;

/// This structure handles API for expression simplification
pub struct ExprSimplifier<S> {
Expand Down Expand Up @@ -92,8 +93,9 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
/// use arrow::datatypes::DataType;
/// use datafusion_expr::{col, lit, Expr};
/// use datafusion_common::Result;
/// use datafusion_physical_expr::execution_props::ExecutionProps;
/// use datafusion_optimizer::simplify_expressions::{ExprSimplifier, SimplifyInfo};
/// use datafusion_expr::execution_props::ExecutionProps;
/// use datafusion_expr::simplify::SimplifyContext;
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
/// use datafusion_common::DFSchema;
/// use std::sync::Arc;
///
Expand Down Expand Up @@ -193,9 +195,9 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
/// use datafusion_expr::{col, lit, Expr};
/// use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
/// use datafusion_common::{Result, ScalarValue, ToDFSchema};
/// use datafusion_physical_expr::execution_props::ExecutionProps;
/// use datafusion_optimizer::simplify_expressions::{
/// ExprSimplifier, SimplifyContext};
/// use datafusion_expr::execution_props::ExecutionProps;
/// use datafusion_expr::simplify::SimplifyContext;
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
///
/// let schema = Schema::new(vec![
/// Field::new("x", DataType::Int64, false),
Expand Down Expand Up @@ -252,9 +254,9 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
/// use datafusion_expr::{col, lit, Expr};
/// use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
/// use datafusion_common::{Result, ScalarValue, ToDFSchema};
/// use datafusion_physical_expr::execution_props::ExecutionProps;
/// use datafusion_optimizer::simplify_expressions::{
/// ExprSimplifier, SimplifyContext};
/// use datafusion_expr::execution_props::ExecutionProps;
/// use datafusion_expr::simplify::SimplifyContext;
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
///
/// let schema = Schema::new(vec![
/// Field::new("a", DataType::Int64, false),
Expand Down Expand Up @@ -1338,9 +1340,8 @@ mod tests {
};

use super::*;
use crate::simplify_expressions::{
utils::for_test::{cast_to_int64_expr, now_expr, to_timestamp_expr},
SimplifyContext,
use crate::simplify_expressions::utils::for_test::{
cast_to_int64_expr, now_expr, to_timestamp_expr,
};
use crate::test::test_table_scan_with_name;

Expand All @@ -1349,8 +1350,9 @@ mod tests {
datatypes::{DataType, Field, Schema},
};
use datafusion_common::{assert_contains, cast::as_int32_array, DFField, ToDFSchema};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::simplify::SimplifyContext;
use datafusion_expr::{interval_arithmetic::Interval, *};
use datafusion_physical_expr::execution_props::ExecutionProps;

use chrono::{DateTime, TimeZone, Utc};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@

use datafusion_common::tree_node::TreeNodeRewriter;
use datafusion_common::{DFSchema, Result};
use datafusion_expr::simplify::SimplifyInfo;
use datafusion_expr::Simplified;
use datafusion_expr::{expr::ScalarFunction, Expr, ScalarFunctionDefinition};

use super::SimplifyInfo;

pub(super) struct FunctionSimplifier<'a, S> {
info: &'a S,
}
Expand Down
2 changes: 0 additions & 2 deletions datafusion/optimizer/src/simplify_expressions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.

pub mod context;
pub mod expr_simplifier;
mod function_simplifier;
mod guarantees;
Expand All @@ -24,6 +23,5 @@ mod regex;
pub mod simplify_exprs;
mod utils;

pub use context::*;
pub use expr_simplifier::*;
pub use simplify_exprs::*;
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

use std::sync::Arc;

use super::{ExprSimplifier, SimplifyContext};
use super::ExprSimplifier;
use crate::{OptimizerConfig, OptimizerRule};
use datafusion_common::{DFSchema, DFSchemaRef, Result};
use datafusion_expr::execution_props::ExecutionProps;
use datafusion_expr::logical_plan::LogicalPlan;
use datafusion_expr::simplify::SimplifyContext;
use datafusion_expr::utils::merge_schema;
use datafusion_physical_expr::execution_props::ExecutionProps;

/// Optimizer Pass that simplifies [`LogicalPlan`]s by rewriting
/// [`Expr`]`s evaluating constants and applying algebraic
Expand Down
5 changes: 2 additions & 3 deletions datafusion/optimizer/src/simplify_expressions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

//! Utility functions for expression simplification

use crate::simplify_expressions::SimplifyInfo;
use datafusion_common::{internal_err, DataFusionError, Result, ScalarValue};
use datafusion_expr::expr::ScalarFunction;
use datafusion_expr::simplify::SimplifyInfo;
use datafusion_expr::{
expr::{Between, BinaryExpr, InList},
expr::{Between, BinaryExpr, InList, ScalarFunction},
expr_fn::{and, bitwise_and, bitwise_or, concat_ws, or},
lit, BuiltinScalarFunction, Expr, Like, Operator, ScalarFunctionDefinition,
};
Expand Down
Loading

0 comments on commit adcb2e2

Please sign in to comment.