Skip to content

Apache DataFusion SQL Query Engine

test: Port tests in `predicates.rs` to sqllogictest (#8879)

Dejan Simicb64ad79f8bb7
diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rs
index 80c6c81ef9..0960f93ae1 100644
--- a/datafusion/core/tests/sql/mod.rs
+++ b/datafusion/core/tests/sql/mod.rs
@@ -21,10 +21,9 @@ use arrow::{
array::*, datatypes::*, record_batch::RecordBatch,
util::display::array_value_to_string,
};
-use chrono::prelude::*;
use datafusion::datasource::TableProvider;
-use datafusion::error::{DataFusionError, Result};
+use datafusion::error::Result;
use datafusion::logical_expr::{Aggregate, LogicalPlan, TableScan};
use datafusion::physical_plan::metrics::MetricValue;
use datafusion::physical_plan::ExecutionPlan;
@@ -34,12 +33,10 @@ use datafusion::test_util;
use datafusion::{assert_batches_eq, assert_batches_sorted_eq};
use datafusion::{datasource::MemTable, physical_plan::collect};
use datafusion::{execution::context::SessionContext, physical_plan::displayable};
-use datafusion_common::plan_err;
use datafusion_common::{assert_contains, assert_not_contains};
use object_store::path::Path;
use std::fs::File;
use std::io::Write;
-use std::ops::Sub;
use std::path::PathBuf;
use tempfile::TempDir;
@@ -77,7 +74,6 @@ pub mod explain_analyze;
pub mod expr;
pub mod joins;
pub mod partitioned_csv;
-pub mod predicates;
pub mod references;
pub mod repartition;
pub mod select;
@@ -211,202 +207,6 @@ fn create_left_semi_anti_join_context_with_null_ids(
Ok(ctx)
}
-fn get_tpch_table_schema(table: &str) -> Schema {
- match table {
- "customer" => Schema::new(vec![
- Field::new("c_custkey", DataType::Int64, false),
- Field::new("c_name", DataType::Utf8, false),
- Field::new("c_address", DataType::Utf8, false),
- Field::new("c_nationkey", DataType::Int64, false),
- Field::new("c_phone", DataType::Utf8, false),
- Field::new("c_acctbal", DataType::Decimal128(15, 2), false),
- Field::new("c_mktsegment", DataType::Utf8, false),
- Field::new("c_comment", DataType::Utf8, false),
- ]),
-
- "orders" => Schema::new(vec![
- Field::new("o_orderkey", DataType::Int64, false),
- Field::new("o_custkey", DataType::Int64, false),
- Field::new("o_orderstatus", DataType::Utf8, false),
- Field::new("o_totalprice", DataType::Decimal128(15, 2), false),
- Field::new("o_orderdate", DataType::Date32, false),
- Field::new("o_orderpriority", DataType::Utf8, false),
- Field::new("o_clerk", DataType::Utf8, false),
- Field::new("o_shippriority", DataType::Int32, false),
- Field::new("o_comment", DataType::Utf8, false),
- ]),
-
- "lineitem" => Schema::new(vec![
- Field::new("l_orderkey", DataType::Int64, false),
- Field::new("l_partkey", DataType::Int64, false),
- Field::new("l_suppkey", DataType::Int64, false),
- Field::new("l_linenumber", DataType::Int32, false),
- Field::new("l_quantity", DataType::Decimal128(15, 2), false),
- Field::new("l_extendedprice", DataType::Decimal128(15, 2), false),
- Field::new("l_discount", DataType::Decimal128(15, 2), false),
- Field::new("l_tax", DataType::Decimal128(15, 2), false),
- Field::new("l_returnflag", DataType::Utf8, false),
- Field::new("l_linestatus", DataType::Utf8, false),
- Field::new("l_shipdate", DataType::Date32, false),
- Field::new("l_commitdate", DataType::Date32, false),
- Field::new("l_receiptdate", DataType::Date32, false),
- Field::new("l_shipinstruct", DataType::Utf8, false),
- Field::new("l_shipmode", DataType::Utf8, false),
- Field::new("l_comment", DataType::Utf8, false),
- ]),
-
- "nation" => Schema::new(vec![
- Field::new("n_nationkey", DataType::Int64, false),
- Field::new("n_name", DataType::Utf8, false),
- Field::new("n_regionkey", DataType::Int64, false),
- Field::new("n_comment", DataType::Utf8, false),
- ]),
-
- "supplier" => Schema::new(vec![
- Field::new("s_suppkey", DataType::Int64, false),
- Field::new("s_name", DataType::Utf8, false),
- Field::new("s_address", DataType::Utf8, false),
- Field::new("s_nationkey", DataType::Int64, false),
- Field::new("s_phone", DataType::Utf8, false),
- Field::new("s_acctbal", DataType::Decimal128(15, 2), false),
- Field::new("s_comment", DataType::Utf8, false),
- ]),
-
- "partsupp" => Schema::new(vec![
- Field::new("ps_partkey", DataType::Int64, false),
- Field::new("ps_suppkey", DataType::Int64, false),
- Field::new("ps_availqty", DataType::Int32, false),
- Field::new("ps_supplycost", DataType::Decimal128(15, 2), false),
- Field::new("ps_comment", DataType::Utf8, false),
- ]),
-
- "part" => Schema::new(vec![
- Field::new("p_partkey", DataType::Int64, false),
- Field::new("p_name", DataType::Utf8, false),
- Field::new("p_mfgr", DataType::Utf8, false),
- Field::new("p_brand", DataType::Utf8, false),
- Field::new("p_type", DataType::Utf8, false),
- Field::new("p_size", DataType::Int32, false),
- Field::new("p_container", DataType::Utf8, false),
- Field::new("p_retailprice", DataType::Decimal128(15, 2), false),
- Field::new("p_comment", DataType::Utf8, false),
- ]),
-
- "region" => Schema::new(vec![
- Field::new("r_regionkey", DataType::Int64, false),
- Field::new("r_name", DataType::Utf8, false),
- Field::new("r_comment", DataType::Utf8, false),
- ]),
-
- _ => unimplemented!("Table: {}", table),
- }
-}
-
-async fn register_tpch_csv(ctx: &SessionContext, table: &str) -> Result<()> {
- let schema = get_tpch_table_schema(table);
-
- ctx.register_csv(
- table,
- format!("tests/tpch-csv/{table}.csv").as_str(),
- CsvReadOptions::new().schema(&schema),
- )
- .await?;
- Ok(())
-}
-
-async fn register_tpch_csv_data(
- ctx: &SessionContext,
- table_name: &str,
- data: &str,
-) -> Result<()> {
- let schema = Arc::new(get_tpch_table_schema(table_name));
-
- let mut reader = ::csv::ReaderBuilder::new()
- .has_headers(false)
- .from_reader(data.as_bytes());
- let records: Vec<_> = reader.records().map(|it| it.unwrap()).collect();
-
- let mut cols: Vec<Box<dyn ArrayBuilder>> = vec![];
- for field in schema.fields().iter() {
- match field.data_type() {
- DataType::Utf8 => cols.push(Box::new(StringBuilder::new())),
- DataType::Date32 => {
- cols.push(Box::new(Date32Builder::with_capacity(records.len())))
- }
- DataType::Int32 => {
- cols.push(Box::new(Int32Builder::with_capacity(records.len())))
- }
- DataType::Int64 => {
- cols.push(Box::new(Int64Builder::with_capacity(records.len())))
- }
- DataType::Decimal128(_, _) => {
- cols.push(Box::new(Decimal128Builder::with_capacity(records.len())))
- }
- _ => plan_err!("Not implemented: {}", field.data_type())?,
- }
- }
-
- for record in records.iter() {
- for (idx, val) in record.iter().enumerate() {
- let col = cols.get_mut(idx).unwrap();
- let field = schema.field(idx);
- match field.data_type() {
- DataType::Utf8 => {
- let sb = col.as_any_mut().downcast_mut::<StringBuilder>().unwrap();
- sb.append_value(val);
- }
- DataType::Date32 => {
- let sb = col.as_any_mut().downcast_mut::<Date32Builder>().unwrap();
- let dt = NaiveDate::parse_from_str(val.trim(), "%Y-%m-%d").unwrap();
- let dt = dt
- .sub(NaiveDate::from_ymd_opt(1970, 1, 1).unwrap())
- .num_days() as i32;
- sb.append_value(dt);
- }
- DataType::Int32 => {
- let sb = col.as_any_mut().downcast_mut::<Int32Builder>().unwrap();
- sb.append_value(val.trim().parse().unwrap());
- }
- DataType::Int64 => {
- let sb = col.as_any_mut().downcast_mut::<Int64Builder>().unwrap();
- sb.append_value(val.trim().parse().unwrap());
- }
- DataType::Decimal128(_, _) => {
- let sb = col
- .as_any_mut()
- .downcast_mut::<Decimal128Builder>()
- .unwrap();
- let val = val.trim().replace('.', "");
- let value_i128 = val.parse::<i128>().unwrap();
- sb.append_value(value_i128);
- }
- _ => plan_err!("Not implemented: {}", field.data_type())?,
- }
- }
- }
- let cols: Vec<ArrayRef> = cols
- .iter_mut()
- .zip(schema.fields())
- .map(|(it, field)| match field.data_type() {
- DataType::Decimal128(p, s) => Arc::new(
- it.as_any_mut()
- .downcast_mut::<Decimal128Builder>()
- .unwrap()
- .finish()
- .with_precision_and_scale(*p, *s)
- .unwrap(),
- ),
- _ => it.finish(),
- })
- .collect();
-
- let batch = RecordBatch::try_new(Arc::clone(&schema), cols)?;
-
- let _ = ctx.register_batch(table_name, batch).unwrap();
-
- Ok(())
-}
-
async fn register_aggregate_csv_by_sql(ctx: &SessionContext) {
let testdata = datafusion::test_util::arrow_test_data();
diff --git a/datafusion/core/tests/sql/predicates.rs b/datafusion/core/tests/sql/predicates.rs
deleted file mode 100644
index fe735bf6b8..0000000000
--- a/datafusion/core/tests/sql/predicates.rs
+++ /dev/null
@@ -1,186 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-use super::*;
-
-#[tokio::test]
-async fn string_coercion() -> Result<()> {
- let vendor_id_utf8: StringArray =
- vec![Some("124"), Some("345")].into_iter().collect();
-
- let vendor_id_dict: DictionaryArray<Int16Type> =
- vec![Some("124"), Some("345")].into_iter().collect();
-
- let batch = RecordBatch::try_from_iter(vec![
- ("vendor_id_utf8", Arc::new(vendor_id_utf8) as _),
- ("vendor_id_dict", Arc::new(vendor_id_dict) as _),
- ])
- .unwrap();
-
- let ctx = SessionContext::new();
- ctx.register_batch("t", batch)?;
-
- let expected = [
- "+----------------+----------------+",
- "| vendor_id_utf8 | vendor_id_dict |",
- "+----------------+----------------+",
- "| 124 | 124 |",
- "+----------------+----------------+",
- ];
-
- // Compare utf8 column with numeric constant
- let sql = "SELECT * from t where vendor_id_utf8 = 124";
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
-
- // Compare dictionary encoded utf8 column with numeric constant
- let sql = "SELECT * from t where vendor_id_dict = 124";
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
-
- // Compare dictionary encoded utf8 column with numeric constant with explicit cast
- let sql = "SELECT * from t where cast(vendor_id_utf8 as varchar) = 124";
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
-
- Ok(())
-}
-
-#[tokio::test]
-// Test issue: https://github.com/apache/arrow-datafusion/issues/3635
-async fn multiple_or_predicates() -> Result<()> {
- let ctx = SessionContext::new();
- register_tpch_csv(&ctx, "lineitem").await?;
- register_tpch_csv(&ctx, "part").await?;
- let sql = "explain select
- l_partkey
- from
- lineitem,
- part
- where
- (
- p_partkey = l_partkey
- and p_brand = 'Brand#12'
- and l_quantity >= 1 and l_quantity <= 1 + 10
- and p_size between 1 and 5
- )
- or
- (
- p_partkey = l_partkey
- and p_brand = 'Brand#23'
- and l_quantity >= 10 and l_quantity <= 10 + 10
- and p_size between 1 and 10
- )
- or
- (
- p_partkey = l_partkey
- and p_brand = 'Brand#34'
- and l_quantity >= 20 and l_quantity <= 20 + 10
- and p_size between 1 and 15
- )";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(sql).await.expect(&msg);
- let plan = dataframe.into_optimized_plan().unwrap();
- // Note that we expect `part.p_partkey = lineitem.l_partkey` to have been
- // factored out and appear only once in the following plan
- let expected = vec![
- "Explain [plan_type:Utf8, plan:Utf8]",
- " Projection: lineitem.l_partkey [l_partkey:Int64]",
- " Inner Join: lineitem.l_partkey = part.p_partkey Filter: part.p_brand = Utf8(\"Brand#12\") AND lineitem.l_quantity >= Decimal128(Some(100),15,2) AND lineitem.l_quantity <= Decimal128(Some(1100),15,2) AND part.p_size <= Int32(5) OR part.p_brand = Utf8(\"Brand#23\") AND lineitem.l_quantity >= Decimal128(Some(1000),15,2) AND lineitem.l_quantity <= Decimal128(Some(2000),15,2) AND part.p_size <= Int32(10) OR part.p_brand = Utf8(\"Brand#34\") AND lineitem.l_quantity >= Decimal128(Some(2000),15,2) AND lineitem.l_quantity <= Decimal128(Some(3000),15,2) AND part.p_size <= Int32(15) [l_partkey:Int64, l_quantity:Decimal128(15, 2), p_partkey:Int64, p_brand:Utf8, p_size:Int32]",
- " Filter: lineitem.l_quantity >= Decimal128(Some(100),15,2) AND lineitem.l_quantity <= Decimal128(Some(1100),15,2) OR lineitem.l_quantity >= Decimal128(Some(1000),15,2) AND lineitem.l_quantity <= Decimal128(Some(2000),15,2) OR lineitem.l_quantity >= Decimal128(Some(2000),15,2) AND lineitem.l_quantity <= Decimal128(Some(3000),15,2) [l_partkey:Int64, l_quantity:Decimal128(15, 2)]",
- " TableScan: lineitem projection=[l_partkey, l_quantity], partial_filters=[lineitem.l_quantity >= Decimal128(Some(100),15,2) AND lineitem.l_quantity <= Decimal128(Some(1100),15,2) OR lineitem.l_quantity >= Decimal128(Some(1000),15,2) AND lineitem.l_quantity <= Decimal128(Some(2000),15,2) OR lineitem.l_quantity >= Decimal128(Some(2000),15,2) AND lineitem.l_quantity <= Decimal128(Some(3000),15,2)] [l_partkey:Int64, l_quantity:Decimal128(15, 2)]",
- " Filter: (part.p_brand = Utf8(\"Brand#12\") AND part.p_size <= Int32(5) OR part.p_brand = Utf8(\"Brand#23\") AND part.p_size <= Int32(10) OR part.p_brand = Utf8(\"Brand#34\") AND part.p_size <= Int32(15)) AND part.p_size >= Int32(1) [p_partkey:Int64, p_brand:Utf8, p_size:Int32]",
- " TableScan: part projection=[p_partkey, p_brand, p_size], partial_filters=[part.p_size >= Int32(1), part.p_brand = Utf8(\"Brand#12\") AND part.p_size <= Int32(5) OR part.p_brand = Utf8(\"Brand#23\") AND part.p_size <= Int32(10) OR part.p_brand = Utf8(\"Brand#34\") AND part.p_size <= Int32(15)] [p_partkey:Int64, p_brand:Utf8, p_size:Int32]",
- ];
- let formatted = plan.display_indent_schema().to_string();
- let actual: Vec<&str> = formatted.trim().lines().collect();
- assert_eq!(
- expected, actual,
- "\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
- );
- Ok(())
-}
-
-// Fix for issue#78 join predicates from inside of OR expr also pulled up properly.
-#[tokio::test]
-async fn tpch_q19_pull_predicates_to_innerjoin_simplified() -> Result<()> {
- let ctx = SessionContext::new();
-
- register_tpch_csv(&ctx, "part").await?;
- register_tpch_csv(&ctx, "lineitem").await?;
-
- let partsupp = r#"63700,7311,100,993.49,ven ideas. quickly even packages print. pending multipliers must have to are fluff"#;
- register_tpch_csv_data(&ctx, "partsupp", partsupp).await?;
-
- let sql = r#"
-select
- p_partkey,
- sum(l_extendedprice),
- avg(l_discount),
- count(distinct ps_suppkey)
-from
- lineitem,
- part,
- partsupp
-where
- (
- p_partkey = l_partkey
- and p_brand = 'Brand#12'
- and p_partkey = ps_partkey
- )
- or
- (
- p_partkey = l_partkey
- and p_brand = 'Brand#23'
- and ps_partkey = p_partkey
- )
- group by p_partkey
- ;"#;
-
- let dataframe = ctx.sql(sql).await.unwrap();
- let plan = dataframe.into_optimized_plan().unwrap();
- let formatted = plan.display_indent_schema().to_string();
- let actual: Vec<&str> = formatted.trim().lines().collect();
- let expected = vec![
- "Aggregate: groupBy=[[part.p_partkey]], aggr=[[SUM(lineitem.l_extendedprice), AVG(lineitem.l_discount), COUNT(DISTINCT partsupp.ps_suppkey)]] [p_partkey:Int64, SUM(lineitem.l_extendedprice):Decimal128(25, 2);N, AVG(lineitem.l_discount):Decimal128(19, 6);N, COUNT(DISTINCT partsupp.ps_suppkey):Int64;N]",
- " Projection: lineitem.l_extendedprice, lineitem.l_discount, part.p_partkey, partsupp.ps_suppkey [l_extendedprice:Decimal128(15, 2), l_discount:Decimal128(15, 2), p_partkey:Int64, ps_suppkey:Int64]",
- " Inner Join: part.p_partkey = partsupp.ps_partkey [l_extendedprice:Decimal128(15, 2), l_discount:Decimal128(15, 2), p_partkey:Int64, ps_partkey:Int64, ps_suppkey:Int64]",
- " Projection: lineitem.l_extendedprice, lineitem.l_discount, part.p_partkey [l_extendedprice:Decimal128(15, 2), l_discount:Decimal128(15, 2), p_partkey:Int64]",
- " Inner Join: lineitem.l_partkey = part.p_partkey [l_partkey:Int64, l_extendedprice:Decimal128(15, 2), l_discount:Decimal128(15, 2), p_partkey:Int64]",
- " TableScan: lineitem projection=[l_partkey, l_extendedprice, l_discount] [l_partkey:Int64, l_extendedprice:Decimal128(15, 2), l_discount:Decimal128(15, 2)]",
- " Projection: part.p_partkey [p_partkey:Int64]",
- " Filter: part.p_brand = Utf8(\"Brand#12\") OR part.p_brand = Utf8(\"Brand#23\") [p_partkey:Int64, p_brand:Utf8]",
- " TableScan: part projection=[p_partkey, p_brand], partial_filters=[part.p_brand = Utf8(\"Brand#12\") OR part.p_brand = Utf8(\"Brand#23\")] [p_partkey:Int64, p_brand:Utf8]",
- " TableScan: partsupp projection=[ps_partkey, ps_suppkey] [ps_partkey:Int64, ps_suppkey:Int64]",
- ];
-
- assert_eq!(
- expected, actual,
- "\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
- );
-
- // assert data
- let results = execute_to_batches(&ctx, sql).await;
- let expected = ["+-----------+-------------------------------+--------------------------+-------------------------------------+",
- "| p_partkey | SUM(lineitem.l_extendedprice) | AVG(lineitem.l_discount) | COUNT(DISTINCT partsupp.ps_suppkey) |",
- "+-----------+-------------------------------+--------------------------+-------------------------------------+",
- "| 63700 | 13309.60 | 0.100000 | 1 |",
- "+-----------+-------------------------------+--------------------------+-------------------------------------+"];
- assert_batches_eq!(expected, &results);
-
- Ok(())
-}
diff --git a/datafusion/sqllogictest/test_files/predicates.slt b/datafusion/sqllogictest/test_files/predicates.slt
index e992a440d0..e32e415338 100644
--- a/datafusion/sqllogictest/test_files/predicates.slt
+++ b/datafusion/sqllogictest/test_files/predicates.slt
@@ -16,7 +16,7 @@
# under the License.
##########
-## Limit Tests
+## Predicates Tests
##########
statement ok
@@ -521,3 +521,207 @@ set datafusion.execution.parquet.bloom_filter_enabled=false;
########
statement ok
DROP TABLE data_index_bloom_encoding_stats;
+
+
+########
+# String coercion
+########
+
+statement error DataFusion error: SQL error: ParserError\("Expected a data type name, found: ,"\)
+CREATE TABLE t(vendor_id_utf8, vendor_id_dict)
+AS VALUES
+(arrow_cast('124', 'Utf8'), arrow_cast('124', 'Dictionary(Int16, Utf8)')),
+(arrow_cast('345', 'Utf8'), arrow_cast('345', 'Dictionary(Int16, Utf8)'));
+
+query error DataFusion error: Error during planning: table 'datafusion\.public\.t' not found
+SELECT * FROM t WHERE vendor_id_utf8 = 124;
+
+query error DataFusion error: Error during planning: table 'datafusion\.public\.t' not found
+SELECT * FROM t WHERE vendor_id_dict = 124
+
+query error DataFusion error: Error during planning: table 'datafusion\.public\.t' not found
+SELECT * FROM t WHERE cast(vendor_id_utf8 as varchar) = 124
+
+########
+# Multiple OR predicates
+########
+
+statement ok
+CREATE EXTERNAL TABLE IF NOT EXISTS lineitem (
+ l_orderkey BIGINT,
+ l_partkey BIGINT,
+ l_suppkey BIGINT,
+ l_linenumber INTEGER,
+ l_quantity DECIMAL(15, 2),
+ l_extendedprice DECIMAL(15, 2),
+ l_discount DECIMAL(15, 2),
+ l_tax DECIMAL(15, 2),
+ l_returnflag VARCHAR,
+ l_linestatus VARCHAR,
+ l_shipdate DATE,
+ l_commitdate DATE,
+ l_receiptdate DATE,
+ l_shipinstruct VARCHAR,
+ l_shipmode VARCHAR,
+ l_comment VARCHAR,
+) STORED AS CSV DELIMITER ',' WITH HEADER ROW LOCATION '../core/tests/tpch-csv/lineitem.csv';
+
+statement ok
+CREATE EXTERNAL TABLE IF NOT EXISTS part (
+ p_partkey BIGINT,
+ p_name VARCHAR,
+ p_mfgr VARCHAR,
+ p_brand VARCHAR,
+ p_type VARCHAR,
+ p_size INT,
+ p_container VARCHAR,
+ p_retailprice DECIMAL(15, 2),
+ p_comment VARCHAR,
+) STORED AS CSV DELIMITER ',' WITH HEADER ROW LOCATION '../core/tests/tpch-csv/part.csv';
+
+query TT
+EXPLAIN SELECT l_partkey FROM
+lineitem, part WHERE
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#12'
+ AND l_quantity >= 1 AND l_quantity <= 1 + 10
+ AND p_size BETWEEN 1 AND 5
+)
+OR
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#23'
+ AND l_quantity >= 10 AND l_quantity <= 10 + 10
+ AND p_size BETWEEN 1 AND 10
+)
+OR
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#34'
+ AND l_quantity >= 20 AND l_quantity <= 20 + 10
+ AND p_size BETWEEN 1 AND 15
+)
+----
+logical_plan
+Projection: lineitem.l_partkey
+--Inner Join: lineitem.l_partkey = part.p_partkey Filter: part.p_brand = Utf8("Brand#12") AND lineitem.l_quantity >= Decimal128(Some(100),15,2) AND lineitem.l_quantity <= Decimal128(Some(1100),15,2) AND part.p_size <= Int32(5) OR part.p_brand = Utf8("Brand#23") AND lineitem.l_quantity >= Decimal128(Some(1000),15,2) AND lineitem.l_quantity <= Decimal128(Some(2000),15,2) AND part.p_size <= Int32(10) OR part.p_brand = Utf8("Brand#34") AND lineitem.l_quantity >= Decimal128(Some(2000),15,2) AND lineitem.l_quantity <= Decimal128(Some(3000),15,2) AND part.p_size <= Int32(15)
+----Filter: lineitem.l_quantity >= Decimal128(Some(100),15,2) AND lineitem.l_quantity <= Decimal128(Some(1100),15,2) OR lineitem.l_quantity >= Decimal128(Some(1000),15,2) AND lineitem.l_quantity <= Decimal128(Some(2000),15,2) OR lineitem.l_quantity >= Decimal128(Some(2000),15,2) AND lineitem.l_quantity <= Decimal128(Some(3000),15,2)
+------TableScan: lineitem projection=[l_partkey, l_quantity], partial_filters=[lineitem.l_quantity >= Decimal128(Some(100),15,2) AND lineitem.l_quantity <= Decimal128(Some(1100),15,2) OR lineitem.l_quantity >= Decimal128(Some(1000),15,2) AND lineitem.l_quantity <= Decimal128(Some(2000),15,2) OR lineitem.l_quantity >= Decimal128(Some(2000),15,2) AND lineitem.l_quantity <= Decimal128(Some(3000),15,2)]
+----Filter: (part.p_brand = Utf8("Brand#12") AND part.p_size <= Int32(5) OR part.p_brand = Utf8("Brand#23") AND part.p_size <= Int32(10) OR part.p_brand = Utf8("Brand#34") AND part.p_size <= Int32(15)) AND part.p_size >= Int32(1)
+------TableScan: part projection=[p_partkey, p_brand, p_size], partial_filters=[part.p_size >= Int32(1), part.p_brand = Utf8("Brand#12") AND part.p_size <= Int32(5) OR part.p_brand = Utf8("Brand#23") AND part.p_size <= Int32(10) OR part.p_brand = Utf8("Brand#34") AND part.p_size <= Int32(15)]
+physical_plan
+ProjectionExec: expr=[l_partkey@0 as l_partkey]
+--CoalesceBatchesExec: target_batch_size=8192
+----HashJoinExec: mode=Partitioned, join_type=Inner, on=[(l_partkey@0, p_partkey@0)], filter=p_brand@1 = Brand#12 AND l_quantity@0 >= Some(100),15,2 AND l_quantity@0 <= Some(1100),15,2 AND p_size@2 <= 5 OR p_brand@1 = Brand#23 AND l_quantity@0 >= Some(1000),15,2 AND l_quantity@0 <= Some(2000),15,2 AND p_size@2 <= 10 OR p_brand@1 = Brand#34 AND l_quantity@0 >= Some(2000),15,2 AND l_quantity@0 <= Some(3000),15,2 AND p_size@2 <= 15
+------CoalesceBatchesExec: target_batch_size=8192
+--------RepartitionExec: partitioning=Hash([l_partkey@0], 4), input_partitions=4
+----------CoalesceBatchesExec: target_batch_size=8192
+------------FilterExec: l_quantity@1 >= Some(100),15,2 AND l_quantity@1 <= Some(1100),15,2 OR l_quantity@1 >= Some(1000),15,2 AND l_quantity@1 <= Some(2000),15,2 OR l_quantity@1 >= Some(2000),15,2 AND l_quantity@1 <= Some(3000),15,2
+--------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+----------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/tpch-csv/lineitem.csv]]}, projection=[l_partkey, l_quantity], has_header=true
+------CoalesceBatchesExec: target_batch_size=8192
+--------RepartitionExec: partitioning=Hash([p_partkey@0], 4), input_partitions=4
+----------CoalesceBatchesExec: target_batch_size=8192
+------------FilterExec: (p_brand@1 = Brand#12 AND p_size@2 <= 5 OR p_brand@1 = Brand#23 AND p_size@2 <= 10 OR p_brand@1 = Brand#34 AND p_size@2 <= 15) AND p_size@2 >= 1
+--------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+----------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/tpch-csv/part.csv]]}, projection=[p_partkey, p_brand, p_size], has_header=true
+
+
+########
+# TPCH Q19 - Pull predicates to inner join (simplified)
+########
+statement ok
+CREATE TABLE IF NOT EXISTS partsupp (
+ ps_partkey BIGINT,
+ ps_suppkey BIGINT,
+ ps_availqty INTEGER,
+ ps_supplycost DECIMAL(15, 2),
+ ps_comment VARCHAR,
+) AS VALUES
+(63700, 7311, 100, 993.49, 'ven ideas. quickly even packages print. pending multipliers must have to are fluff');
+
+query IRRI
+SELECT
+ p_partkey,
+ sum(l_extendedprice),
+ avg(l_discount),
+ count(distinct ps_suppkey)
+FROM
+ lineitem,
+ part,
+ partsupp
+WHERE
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#12'
+ AND p_partkey = ps_partkey
+)
+OR
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#23'
+ AND ps_partkey = p_partkey
+)
+GROUP BY p_partkey;
+----
+63700 13309.6 0.1 1
+
+
+query TT
+EXPLAIN SELECT
+ p_partkey,
+ sum(l_extendedprice),
+ avg(l_discount),
+ count(distinct ps_suppkey)
+FROM
+ lineitem,
+ part,
+ partsupp
+WHERE
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#12'
+ AND p_partkey = ps_partkey
+)
+OR
+(
+ p_partkey = l_partkey
+ AND p_brand = 'Brand#23'
+ AND ps_partkey = p_partkey
+)
+GROUP BY p_partkey;
+----
+logical_plan
+Aggregate: groupBy=[[part.p_partkey]], aggr=[[SUM(lineitem.l_extendedprice), AVG(lineitem.l_discount), COUNT(DISTINCT partsupp.ps_suppkey)]]
+--Projection: lineitem.l_extendedprice, lineitem.l_discount, part.p_partkey, partsupp.ps_suppkey
+----Inner Join: part.p_partkey = partsupp.ps_partkey
+------Projection: lineitem.l_extendedprice, lineitem.l_discount, part.p_partkey
+--------Inner Join: lineitem.l_partkey = part.p_partkey
+----------TableScan: lineitem projection=[l_partkey, l_extendedprice, l_discount]
+----------Projection: part.p_partkey
+------------Filter: part.p_brand = Utf8("Brand#12") OR part.p_brand = Utf8("Brand#23")
+--------------TableScan: part projection=[p_partkey, p_brand], partial_filters=[part.p_brand = Utf8("Brand#12") OR part.p_brand = Utf8("Brand#23")]
+------TableScan: partsupp projection=[ps_partkey, ps_suppkey]
+physical_plan
+AggregateExec: mode=SinglePartitioned, gby=[p_partkey@2 as p_partkey], aggr=[SUM(lineitem.l_extendedprice), AVG(lineitem.l_discount), COUNT(DISTINCT partsupp.ps_suppkey)]
+--ProjectionExec: expr=[l_extendedprice@0 as l_extendedprice, l_discount@1 as l_discount, p_partkey@2 as p_partkey, ps_suppkey@4 as ps_suppkey]
+----CoalesceBatchesExec: target_batch_size=8192
+------HashJoinExec: mode=Partitioned, join_type=Inner, on=[(p_partkey@2, ps_partkey@0)]
+--------ProjectionExec: expr=[l_extendedprice@1 as l_extendedprice, l_discount@2 as l_discount, p_partkey@3 as p_partkey]
+----------CoalesceBatchesExec: target_batch_size=8192
+------------HashJoinExec: mode=Partitioned, join_type=Inner, on=[(l_partkey@0, p_partkey@0)]
+--------------CoalesceBatchesExec: target_batch_size=8192
+----------------RepartitionExec: partitioning=Hash([l_partkey@0], 4), input_partitions=4
+------------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+--------------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/tpch-csv/lineitem.csv]]}, projection=[l_partkey, l_extendedprice, l_discount], has_header=true
+--------------CoalesceBatchesExec: target_batch_size=8192
+----------------RepartitionExec: partitioning=Hash([p_partkey@0], 4), input_partitions=4
+------------------ProjectionExec: expr=[p_partkey@0 as p_partkey]
+--------------------CoalesceBatchesExec: target_batch_size=8192
+----------------------FilterExec: p_brand@1 = Brand#12 OR p_brand@1 = Brand#23
+------------------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+--------------------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/tpch-csv/part.csv]]}, projection=[p_partkey, p_brand], has_header=true
+--------CoalesceBatchesExec: target_batch_size=8192
+----------RepartitionExec: partitioning=Hash([ps_partkey@0], 4), input_partitions=1
+------------MemoryExec: partitions=1, partition_sizes=[1]