Skip to content

Apache DataFusion SQL Query Engine

minor: port some join tests to sqllogictests (#5567)

ygf1137138a53b425
diff --git a/datafusion/core/tests/sql/joins.rs b/datafusion/core/tests/sql/joins.rs
index b9b4c5cf31..dc6f741c5b 100644
--- a/datafusion/core/tests/sql/joins.rs
+++ b/datafusion/core/tests/sql/joins.rs
@@ -20,240 +20,21 @@ use datafusion::from_slice::FromSlice;
#[tokio::test]
async fn equijoin() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t2_id = t1_id ORDER BY t1_id",
- ];
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
-
- let ctx = create_join_context_qualified("t1", "t2")?;
- let equivalent_sql = [
- "SELECT t1.a, t2.b FROM t1 INNER JOIN t2 ON t1.a = t2.a ORDER BY t1.a",
- "SELECT t1.a, t2.b FROM t1 INNER JOIN t2 ON t2.a = t1.a ORDER BY t1.a",
- ];
- let expected = vec![
- "+---+-----+",
- "| a | b |",
- "+---+-----+",
- "| 1 | 100 |",
- "| 2 | 200 |",
- "| 4 | 400 |",
- "+---+-----+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_multiple_condition_ordering() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id AND t1_name <> t2_name ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id AND t2_name <> t1_name ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t2_id = t1_id AND t1_name <> t2_name ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t2_id = t1_id AND t2_name <> t1_name ORDER BY t1_id",
- ];
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_and_other_condition() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id AND t2_name >= 'y' ORDER BY t1_id";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_left_and_condition_from_right() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t2_name >= 'y' ORDER BY t1_id";
- let dataframe = ctx.sql(sql).await.unwrap();
- let actual = dataframe.collect().await.unwrap();
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 33 | c | |",
- "| 44 | d | |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
-
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_left_and_not_null_condition_from_right() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t2_name is not null ORDER BY t1_id";
- let dataframe = ctx.sql(sql).await.unwrap();
- let actual = dataframe.collect().await.unwrap();
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 33 | c | |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
-
- Ok(())
-}
-
-#[tokio::test]
-async fn full_join_sub_query() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql = "
- SELECT t1_id, t1_name, t2_name FROM (SELECT * from (t1) AS t1) FULL JOIN (SELECT * from (t2) AS t2) ON t1_id = t2_id AND t2_name >= 'y'
- ORDER BY t1_id, t2_name";
- let dataframe = ctx.sql(sql).await.unwrap();
- let actual = dataframe.collect().await.unwrap();
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 33 | c | |",
- "| 44 | d | |",
- "| | | w |",
- "| | | x |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
-
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_right_and_condition_from_left() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t1_id = t2_id AND t1_id >= 22 ORDER BY t2_name";
- let dataframe = ctx.sql(sql).await.unwrap();
- let actual = dataframe.collect().await.unwrap();
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| | | w |",
- "| 44 | d | x |",
- "| 22 | b | y |",
- "| | | z |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_left_and_condition_from_left() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t1_id >= 44 ORDER BY t1_id";
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | |",
- "| 22 | b | |",
- "| 33 | c | |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_left_and_condition_from_both() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_int, t2_int FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t1_int >= t2_int ORDER BY t1_id";
- let expected = vec![
- "+-------+--------+--------+",
- "| t1_id | t1_int | t2_int |",
- "+-------+--------+--------+",
- "| 11 | 1 | |",
- "| 22 | 2 | 1 |",
- "| 33 | 3 | |",
- "| 44 | 4 | 3 |",
- "+-------+--------+--------+",
- ];
+ let ctx = create_join_context_qualified("t1", "t2")?;
+ let equivalent_sql = [
+ "SELECT t1.a, t2.b FROM t1 INNER JOIN t2 ON t1.a = t2.a ORDER BY t1.a",
+ "SELECT t1.a, t2.b FROM t1 INNER JOIN t2 ON t2.a = t1.a ORDER BY t1.a",
+ ];
+ let expected = vec![
+ "+---+-----+",
+ "| a | b |",
+ "+---+-----+",
+ "| 1 | 100 |",
+ "| 2 | 200 |",
+ "| 4 | 400 |",
+ "+---+-----+",
+ ];
+ for sql in equivalent_sql.iter() {
let actual = execute_to_batches(&ctx, sql).await;
assert_batches_eq!(expected, &actual);
}
@@ -261,81 +42,6 @@ async fn equijoin_left_and_condition_from_both() -> Result<()> {
Ok(())
}
-#[tokio::test]
-async fn equijoin_right_and_condition_from_right() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t1_id = t2_id AND t2_id >= 22 ORDER BY t2_name";
- let dataframe = ctx.sql(sql).await.unwrap();
- let actual = dataframe.collect().await.unwrap();
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| | | w |",
- "| 44 | d | x |",
- "| 22 | b | y |",
- "| | | z |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_right_and_condition_from_both() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_int, t2_int, t2_id FROM t1 RIGHT JOIN t2 ON t1_id = t2_id AND t2_int <= t1_int ORDER BY t2_id";
- let dataframe = ctx.sql(sql).await.unwrap();
- let actual = dataframe.collect().await.unwrap();
- let expected = vec![
- "+--------+--------+-------+",
- "| t1_int | t2_int | t2_id |",
- "+--------+--------+-------+",
- "| | 3 | 11 |",
- "| 2 | 1 | 22 |",
- "| 4 | 3 | 44 |",
- "| | 3 | 55 |",
- "+--------+--------+-------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn left_join() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t2_id = t1_id ORDER BY t1_id",
- ];
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 33 | c | |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- }
- Ok(())
-}
-
#[tokio::test]
async fn left_join_unbalanced() -> Result<()> {
// the t1_id is larger than t2_id so the join_selection optimizer should kick in
@@ -576,71 +282,6 @@ async fn full_join_not_null_filter() -> Result<()> {
Ok(())
}
-#[tokio::test]
-async fn right_join() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t1_id = t2_id ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t2_id = t1_id ORDER BY t1_id"
- ];
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 44 | d | x |",
- "| | | w |",
- "+-------+---------+---------+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn full_join() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1 FULL JOIN t2 ON t1_id = t2_id ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 FULL JOIN t2 ON t2_id = t1_id ORDER BY t1_id",
- ];
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 33 | c | |",
- "| 44 | d | x |",
- "| | | w |",
- "+-------+---------+---------+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
-
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1 FULL OUTER JOIN t2 ON t1_id = t2_id ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1 FULL OUTER JOIN t2 ON t2_id = t1_id ORDER BY t1_id",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- }
-
- Ok(())
-}
-
#[tokio::test]
async fn left_join_using() -> Result<()> {
let test_repartition_joins = vec![true, false];
@@ -664,80 +305,6 @@ async fn left_join_using() -> Result<()> {
Ok(())
}
-#[tokio::test]
-async fn equijoin_implicit_syntax() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let equivalent_sql = [
- "SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t1_id = t2_id ORDER BY t1_id",
- "SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t2_id = t1_id ORDER BY t1_id",
- ];
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- for sql in equivalent_sql.iter() {
- let actual = execute_to_batches(&ctx, sql).await;
- assert_batches_eq!(expected, &actual);
- }
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_implicit_syntax_with_filter() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql = "SELECT t1_id, t1_name, t2_name \
- FROM t1, t2 \
- WHERE t1_id > 0 \
- AND t1_id = t2_id \
- AND t2_id < 99 \
- ORDER BY t1_id";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
-#[tokio::test]
-async fn equijoin_implicit_syntax_reversed() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
- let sql =
- "SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t2_id = t1_id ORDER BY t1_id";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | z |",
- "| 22 | b | y |",
- "| 44 | d | x |",
- "+-------+---------+---------+",
- ];
- assert_batches_eq!(expected, &actual);
- }
- Ok(())
-}
-
#[tokio::test]
async fn cross_join() {
let test_repartition_joins = vec![true, false];
@@ -1496,17 +1063,14 @@ async fn hash_join_with_dictionary() -> Result<()> {
#[tokio::test]
async fn reduce_left_join_1() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to inner join
- let sql =
- "select * from t1 left join t2 on t1.t1_id = t2.t2_id where t2.t2_id < 100";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce to inner join
+ let sql = "select * from t1 left join t2 on t1.t1_id = t2.t2_id where t2.t2_id < 100";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Filter: t1.t1_id < UInt32(100) [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
@@ -1514,46 +1078,31 @@ async fn reduce_left_join_1() -> Result<()> {
" Filter: t2.t2_id < UInt32(100) [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 11 | z | 3 |",
- "| 22 | b | 2 | 22 | y | 1 |",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_left_join_2() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to inner join
- let sql = "select * from t1 left join t2 on t1.t1_id = t2.t2_id where t2.t2_int < 10 or (t1.t1_int > 2 and t2.t2_name != 'w')";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
+ // reduce to inner join
+ let sql = "select * from t1 left join t2 on t1.t1_id = t2.t2_id where t2.t2_int < 10 or (t1.t1_int > 2 and t2.t2_name != 'w')";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
- // filter expr: `t2.t2_int < 10 or (t1.t1_int > 2 and t2.t2_name != 'w')`
- // could be write to: `(t1.t1_int > 2 or t2.t2_int < 10) and (t2.t2_name != 'w' or t2.t2_int < 10)`
- // the right part `(t2.t2_name != 'w' or t2.t2_int < 10)` could be push down left join side and remove in filter.
+ // filter expr: `t2.t2_int < 10 or (t1.t1_int > 2 and t2.t2_name != 'w')`
+ // could be write to: `(t1.t1_int > 2 or t2.t2_int < 10) and (t2.t2_name != 'w' or t2.t2_int < 10)`
+ // the right part `(t2.t2_name != 'w' or t2.t2_int < 10)` could be push down left join side and remove in filter.
- let expected = vec![
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Filter: t2.t2_int < UInt32(10) OR t1.t1_int > UInt32(2) AND t2.t2_name != Utf8(\"w\") [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
@@ -1561,41 +1110,26 @@ async fn reduce_left_join_2() -> Result<()> {
" Filter: t2.t2_int < UInt32(10) OR t2.t2_name != Utf8(\"w\") [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 11 | z | 3 |",
- "| 22 | b | 2 | 22 | y | 1 |",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_left_join_3() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce subquery to inner join
- let sql = "select * from (select t1.* from t1 left join t2 on t1.t1_id = t2.t2_id where t2.t2_int < 3) t3 left join t2 on t3.t1_int = t2.t2_int where t3.t1_id < 100";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce subquery to inner join
+ let sql = "select * from (select t1.* from t1 left join t2 on t1.t1_id = t2.t2_id where t2.t2_int < 3) t3 left join t2 on t3.t1_int = t2.t2_int where t3.t1_id < 100";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Left Join: t3.t1_int = t2.t2_int [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" SubqueryAlias: t3 [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
@@ -1608,204 +1142,131 @@ async fn reduce_left_join_3() -> Result<()> {
" TableScan: t2 projection=[t2_id, t2_int] [t2_id:UInt32;N, t2_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 22 | b | 2 | | | |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_right_join_1() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to inner join
- let sql = "select * from t1 right join t2 on t1.t1_id = t2.t2_id where t1.t1_int is not null";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce to inner join
+ let sql = "select * from t1 right join t2 on t1.t1_id = t2.t2_id where t1.t1_int is not null";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Filter: t1.t1_int IS NOT NULL [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" TableScan: t1 projection=[t1_id, t1_name, t1_int] [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 11 | z | 3 |",
- "| 22 | b | 2 | 22 | y | 1 |",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_right_join_2() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
-
- // reduce to inner join
- let sql = "select * from t1 right join t2 on t1.t1_id = t2.t2_id where not(t1.t1_int = t2.t2_int)";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
+
+ // reduce to inner join
+ let sql = "select * from t1 right join t2 on t1.t1_id = t2.t2_id where not(t1.t1_int = t2.t2_int)";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Filter: t1.t1_int != t2.t2_int [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t1 projection=[t1_id, t1_name, t1_int] [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 11 | z | 3 |",
- "| 22 | b | 2 | 22 | y | 1 |",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_full_join_to_right_join() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to right join
- let sql = "select * from t1 full join t2 on t1.t1_id = t2.t2_id where t2.t2_name is not null";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce to right join
+ let sql = "select * from t1 full join t2 on t1.t1_id = t2.t2_id where t2.t2_name is not null";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Right Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t1 projection=[t1_id, t1_name, t1_int] [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" Filter: t2.t2_name IS NOT NULL [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| | | | 55 | w | 3 |",
- "| 11 | a | 1 | 11 | z | 3 |",
- "| 22 | b | 2 | 22 | y | 1 |",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_full_join_to_left_join() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to left join
- let sql =
- "select * from t1 full join t2 on t1.t1_id = t2.t2_id where t1.t1_name != 'b'";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce to left join
+ let sql =
+ "select * from t1 full join t2 on t1.t1_id = t2.t2_id where t1.t1_name != 'b'";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Left Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Filter: t1.t1_name != Utf8(\"b\") [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" TableScan: t1 projection=[t1_id, t1_name, t1_int] [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 11 | z | 3 |",
- "| 33 | c | 3 | | | |",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
+ 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"
+ );
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
Ok(())
}
#[tokio::test]
async fn reduce_full_join_to_inner_join() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to inner join
- let sql = "select * from t1 full join t2 on t1.t1_id = t2.t2_id where t1.t1_name != 'b' and t2.t2_name = 'x'";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce to inner join
+ let sql = "select * from t1 full join t2 on t1.t1_id = t2.t2_id where t1.t1_name != 'b' and t2.t2_name = 'x'";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Inner Join: t1.t1_id = t2.t2_id [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" Filter: t1.t1_name != Utf8(\"b\") [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
@@ -1813,23 +1274,12 @@ async fn reduce_full_join_to_inner_join() -> Result<()> {
" Filter: t2.t2_name = Utf8(\"x\") [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 44 | d | 4 | 44 | x | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
@@ -2324,84 +1774,42 @@ async fn right_semi_join() -> Result<()> {
Ok(())
}
-#[tokio::test]
-async fn left_join_with_nonequal_condition() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins).unwrap();
-
- let sql = "SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON (t1_id != t2_id and t2_id >= 100) ORDER BY t1_id";
- let actual = execute_to_batches(&ctx, sql).await;
- let expected = vec![
- "+-------+---------+---------+",
- "| t1_id | t1_name | t2_name |",
- "+-------+---------+---------+",
- "| 11 | a | |",
- "| 22 | b | |",
- "| 33 | c | |",
- "| 44 | d | |",
- "+-------+---------+---------+",
- ];
-
- assert_batches_eq!(expected, &actual);
- }
-
- Ok(())
-}
-
#[tokio::test]
async fn reduce_cross_join_with_expr_join_key_all() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- // reduce to inner join
- let sql = "select * from t1 cross join t2 where t1.t1_id + 12 = t2.t2_id + 1";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ // reduce to inner join
+ let sql = "select * from t1 cross join t2 where t1.t1_id + 12 = t2.t2_id + 1";
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Inner Join: CAST(t1.t1_id AS Int64) + Int64(12) = CAST(t2.t2_id AS Int64) + Int64(1) [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N, t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
" TableScan: t1 projection=[t1_id, t1_name, t1_int] [t1_id:UInt32;N, t1_name:Utf8;N, t1_int:UInt32;N]",
" TableScan: t2 projection=[t2_id, t2_name, t2_int] [t2_id:UInt32;N, t2_name:Utf8;N, t2_int:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 22 | y | 1 |",
- "| 33 | c | 3 | 44 | x | 3 |",
- "| 44 | d | 4 | 55 | w | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
#[tokio::test]
async fn reduce_cross_join_with_cast_expr_join_key() -> Result<()> {
- let test_repartition_joins = vec![true, false];
- for repartition_joins in test_repartition_joins {
- let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+ let ctx = create_join_context("t1_id", "t2_id", false)?;
- let sql =
+ let sql =
"select t1.t1_id, t2.t2_id, t1.t1_name from t1 cross join t2 where t1.t1_id + 11 = cast(t2.t2_id as BIGINT)";
- let msg = format!("Creating logical plan for '{sql}'");
- let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
- let plan = dataframe.into_optimized_plan()?;
- let expected = vec![
+ let msg = format!("Creating logical plan for '{sql}'");
+ let dataframe = ctx.sql(&("explain ".to_owned() + sql)).await.expect(&msg);
+ let plan = dataframe.into_optimized_plan()?;
+ let expected = vec![
"Explain [plan_type:Utf8, plan:Utf8]",
" Projection: t1.t1_id, t2.t2_id, t1.t1_name [t1_id:UInt32;N, t2_id:UInt32;N, t1_name:Utf8;N]",
" Inner Join: CAST(t1.t1_id AS Int64) + Int64(11) = CAST(t2.t2_id AS Int64) [t1_id:UInt32;N, t1_name:Utf8;N, t2_id:UInt32;N]",
@@ -2409,25 +1817,12 @@ async fn reduce_cross_join_with_cast_expr_join_key() -> Result<()> {
" TableScan: t2 projection=[t2_id] [t2_id:UInt32;N]",
];
- 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"
- );
- let expected = vec![
- "+-------+-------+---------+",
- "| t1_id | t2_id | t1_name |",
- "+-------+-------+---------+",
- "| 11 | 22 | a |",
- "| 33 | 44 | c |",
- "| 44 | 55 | d |",
- "+-------+-------+---------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
- }
+ 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(())
}
@@ -2502,20 +1897,6 @@ async fn reduce_cross_join_with_wildcard_and_expr() -> Result<()> {
expected, actual,
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
-
- // assert execution result
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+----------------------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int | t1.t1_id + Int64(11) |",
- "+-------+---------+--------+-------+---------+--------+----------------------+",
- "| 11 | a | 1 | 22 | y | 1 | 22 |",
- "| 33 | c | 3 | 44 | x | 3 | 44 |",
- "| 44 | d | 4 | 55 | w | 3 | 55 |",
- "+-------+---------+--------+-------+---------+--------+----------------------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
}
Ok(())
@@ -2574,19 +1955,6 @@ async fn both_side_expr_key_inner_join() -> Result<()> {
expected, actual,
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
-
- let expected = vec![
- "+-------+-------+---------+",
- "| t1_id | t2_id | t1_name |",
- "+-------+-------+---------+",
- "| 11 | 22 | a |",
- "| 33 | 44 | c |",
- "| 44 | 55 | d |",
- "+-------+-------+---------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
}
Ok(())
@@ -2642,19 +2010,6 @@ async fn left_side_expr_key_inner_join() -> Result<()> {
expected, actual,
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
-
- let expected = vec![
- "+-------+-------+---------+",
- "| t1_id | t2_id | t1_name |",
- "+-------+-------+---------+",
- "| 11 | 22 | a |",
- "| 33 | 44 | c |",
- "| 44 | 55 | d |",
- "+-------+-------+---------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
}
Ok(())
@@ -2709,19 +2064,6 @@ async fn right_side_expr_key_inner_join() -> Result<()> {
expected, actual,
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
-
- let expected = vec![
- "+-------+-------+---------+",
- "| t1_id | t2_id | t1_name |",
- "+-------+-------+---------+",
- "| 11 | 22 | a |",
- "| 33 | 44 | c |",
- "| 44 | 55 | d |",
- "+-------+-------+---------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
}
Ok(())
@@ -2774,19 +2116,6 @@ async fn select_wildcard_with_expr_key_inner_join() -> Result<()> {
expected, actual,
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
-
- let expected = vec![
- "+-------+---------+--------+-------+---------+--------+",
- "| t1_id | t1_name | t1_int | t2_id | t2_name | t2_int |",
- "+-------+---------+--------+-------+---------+--------+",
- "| 11 | a | 1 | 22 | y | 1 |",
- "| 33 | c | 3 | 44 | x | 3 |",
- "| 44 | d | 4 | 55 | w | 3 |",
- "+-------+---------+--------+-------+---------+--------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
}
Ok(())
@@ -2817,19 +2146,6 @@ async fn join_with_type_coercion_for_equi_expr() -> Result<()> {
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
- let expected = vec![
- "+-------+---------+-------+",
- "| t1_id | t1_name | t2_id |",
- "+-------+---------+-------+",
- "| 11 | a | 22 |",
- "| 33 | c | 44 |",
- "| 44 | d | 55 |",
- "+-------+---------+-------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
-
Ok(())
}
@@ -2858,17 +2174,6 @@ async fn join_only_with_filter() -> Result<()> {
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
- let expected = vec![
- "+-------+---------+-------+",
- "| t1_id | t1_name | t2_id |",
- "+-------+---------+-------+",
- "| 11 | a | 55 |",
- "+-------+---------+-------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
-
Ok(())
}
@@ -2900,17 +2205,6 @@ async fn type_coercion_join_with_filter_and_equi_expr() -> Result<()> {
"\n\nexpected:\n\n{expected:#?}\nactual:\n\n{actual:#?}\n\n"
);
- let expected = vec![
- "+-------+---------+-------+",
- "| t1_id | t1_name | t2_id |",
- "+-------+---------+-------+",
- "| 11 | a | 55 |",
- "+-------+---------+-------+",
- ];
-
- let results = execute_to_batches(&ctx, sql).await;
- assert_batches_sorted_eq!(expected, &results);
-
Ok(())
}
diff --git a/datafusion/core/tests/sqllogictests/test_files/join.slt b/datafusion/core/tests/sqllogictests/test_files/join.slt
index 49f7cf49bc..f7c291f909 100644
--- a/datafusion/core/tests/sqllogictests/test_files/join.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/join.slt
@@ -19,8 +19,9 @@
## Join Tests
##########
+# Regression test: https://github.com/apache/arrow-datafusion/issues/4844
statement ok
-CREATE TABLE students(name TEXT, mark INT) AS VALUES
+CREATE TABLE IF NOT EXISTS students(name TEXT, mark INT) AS VALUES
('Stuart', 28),
('Amina', 89),
('Christen', 50),
@@ -28,20 +29,13 @@ CREATE TABLE students(name TEXT, mark INT) AS VALUES
('Samantha', 21);
statement ok
-CREATE TABLE grades(grade INT, min INT, max INT) AS VALUES
+CREATE TABLE IF NOT EXISTS grades(grade INT, min INT, max INT) AS VALUES
(1, 0, 14),
(2, 15, 35),
(3, 36, 55),
(4, 56, 79),
(5, 80, 100);
-statement ok
-CREATE TABLE test1(a int, b int) as select 1 as a, 2 as b;
-
-statement ok
-CREATE TABLE test2(a int, b int) as select 1 as a, 2 as b;
-
-# Regression test: https://github.com/apache/arrow-datafusion/issues/4844
query TII
SELECT s.*, g.grade FROM students s join grades g on s.mark between g.min and g.max WHERE grade > 2 ORDER BY s.mark DESC
----
@@ -49,47 +43,499 @@ Amina 89 5
Salma 77 4
Christen 50 3
+statement ok
+drop table IF EXISTS students;
+
+statement ok
+drop table IF EXISTS grades;
+
+# issue: https://github.com/apache/arrow-datafusion/issues/5382
+statement ok
+CREATE TABLE IF NOT EXISTS test1(a int, b int) as select 1 as a, 2 as b;
+
+statement ok
+CREATE TABLE IF NOT EXISTS test2(a int, b int) as select 1 as a, 2 as b;
+
+query IIII rowsort
+SELECT * FROM test2 FULL JOIN test1 ON true;
+----
+1 2 1 2
+
+statement ok
+drop table IF EXISTS test1;
+
+statement ok
+drop table IF EXISTS test2;
+
# two tables for join
statement ok
-CREATE TABLE t1(t1_id INT, t1_name TEXT, t1_int INT) AS VALUES
+CREATE TABLE IF NOT EXISTS t1(t1_id INT, t1_name TEXT, t1_int INT) AS VALUES
(11, 'a', 1),
(22, 'b', 2),
(33, 'c', 3),
(44, 'd', 4);
statement ok
-CREATE TABLE t2(t2_id INT, t2_name TEXT, t2_int INT) AS VALUES
+CREATE TABLE IF NOT EXISTS t2(t2_id INT, t2_name TEXT, t2_int INT) AS VALUES
(11, 'z', 3),
(22, 'y', 1),
(44, 'x', 3),
(55, 'w', 3);
+# batch size
+statement ok
+set datafusion.execution.batch_size = 4096;
+
# left semi with wrong where clause
query error DataFusion error: Schema error: No field named "t2"."t2_id". Valid fields are "t1"."t1_id", "t1"."t1_name", "t1"."t1_int".
-SELECT t1.t1_id,
- t1.t1_name,
- t1.t1_int
-FROM t1 LEFT SEMI
-JOIN t2
-ON (
- t1.t1_id = t2.t2_id)
-WHERE t2.t2_id > 1
+SELECT t1.t1_id, t1.t1_name, t1.t1_int
+FROM t1
+ LEFT SEMI JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t2.t2_id > 1
# left semi join with on-filter
query ITI rowsort
-SELECT t1.t1_id,
- t1.t1_name,
- t1.t1_int
-FROM t1 LEFT SEMI
-JOIN t2
-ON (
- t1.t1_id = t2.t2_id and t2.t2_int > 1)
+SELECT t1.t1_id, t1.t1_name, t1.t1_int
+FROM t1
+ LEFT SEMI JOIN t2
+ ON t1.t1_id = t2.t2_id
+ AND t2.t2_int > 1
----
11 a 1
44 d 4
-# issue: https://github.com/apache/arrow-datafusion/issues/5382
-query IIII rowsort
-SELECT * FROM test2 FULL JOIN test1 ON true;
+# equijoin
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id
----
-1 2 1 2
+11 a z
+22 b y
+44 d x
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t2_id = t1_id
+----
+11 a z
+22 b y
+44 d x
+
+# equijoin_multiple_condition_ordering
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id AND t1_name <> t2_name
+----
+11 a z
+22 b y
+44 d x
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id AND t2_name <> t1_name
+----
+11 a z
+22 b y
+44 d x
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t2_id = t1_id AND t1_name <> t2_name
+----
+11 a z
+22 b y
+44 d x
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t2_id = t1_id AND t2_name <> t1_name
+----
+11 a z
+22 b y
+44 d x
+
+# equijoin_and_other_condition
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 JOIN t2 ON t1_id = t2_id AND t2_name >= 'y'
+----
+11 a z
+22 b y
+
+# equijoin_left_and_condition_from_right
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t2_name >= 'y'
+----
+11 a z
+22 b y
+33 c NULL
+44 d NULL
+
+# equijoin_left_and_not_null_condition_from_right
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t2_name is not null
+----
+11 a z
+22 b y
+33 c NULL
+44 d x
+
+# full_join_sub_query
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name
+FROM (
+ SELECT *
+ FROM (t1) AS t1
+)
+ FULL JOIN (
+ SELECT *
+ FROM (t2) AS t2
+ )
+ ON t1_id = t2_id AND t2_name >= 'y'
+----
+11 a z
+22 b y
+33 c NULL
+44 d NULL
+NULL NULL w
+NULL NULL x
+
+# equijoin_right_and_condition_from_left
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t1_id = t2_id AND t1_id >= 22
+----
+22 b y
+44 d x
+NULL NULL w
+NULL NULL z
+
+# equijoin_left_and_condition_from_left
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t1_id >= 44
+----
+11 a NULL
+22 b NULL
+33 c NULL
+44 d x
+
+# equijoin_left_and_condition_from_both
+query III rowsort
+SELECT t1_id, t1_int, t2_int FROM t1 LEFT JOIN t2 ON t1_id = t2_id AND t1_int >= t2_int
+----
+11 1 NULL
+22 2 1
+33 3 NULL
+44 4 3
+
+# equijoin_right_and_condition_from_right
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t1_id = t2_id AND t2_id >= 22
+----
+22 b y
+44 d x
+NULL NULL w
+NULL NULL z
+
+# equijoin_right_and_condition_from_both
+query III rowsort
+SELECT t1_int, t2_int, t2_id FROM t1 RIGHT JOIN t2 ON t1_id = t2_id AND t2_int <= t1_int
+----
+2 1 22
+4 3 44
+NULL 3 11
+NULL 3 55
+
+# left_join
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t1_id = t2_id
+----
+11 a z
+22 b y
+33 c NULL
+44 d x
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 LEFT JOIN t2 ON t2_id = t1_id
+----
+11 a z
+22 b y
+33 c NULL
+44 d x
+
+# right_join
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t1_id = t2_id
+----
+11 a z
+22 b y
+44 d x
+NULL NULL w
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 RIGHT JOIN t2 ON t2_id = t1_id
+----
+11 a z
+22 b y
+44 d x
+NULL NULL w
+
+# full_join
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 FULL JOIN t2 ON t1_id = t2_id
+----
+11 a z
+22 b y
+33 c NULL
+44 d x
+NULL NULL w
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1 FULL JOIN t2 ON t2_id = t1_id
+----
+11 a z
+22 b y
+33 c NULL
+44 d x
+NULL NULL w
+
+# equijoin_implicit_syntax
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t1_id = t2_id
+----
+11 a z
+22 b y
+44 d x
+
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t2_id = t1_id
+----
+11 a z
+22 b y
+44 d x
+
+# equijoin_implicit_syntax_with_filter
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t1_id > 0 AND t1_id = t2_id AND t2_id < 99
+----
+11 a z
+22 b y
+44 d x
+
+# equijoin_implicit_syntax_reversed
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name FROM t1, t2 WHERE t2_id = t1_id
+----
+11 a z
+22 b y
+44 d x
+
+# reduce_left_join_1
+query ITIITI rowsort
+SELECT t1_id, t1_name, t1_int, t2_id, t2_name, t2_int
+FROM t1
+ LEFT JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t2.t2_id < 100
+----
+11 a 1 11 z 3
+22 b 2 22 y 1
+44 d 4 44 x 3
+
+# reduce_left_join_2
+# filter expr: `t2.t2_int < 10 or (t1.t1_int > 2 and t2.t2_name != 'w')`
+# could be write to: `(t1.t1_int > 2 or t2.t2_int < 10) and (t2.t2_name != 'w' or t2.t2_int < 10)`
+# the right part `(t2.t2_name != 'w' or t2.t2_int < 10)` could be push down left join side and remove in filter.
+query ITIITI rowsort
+SELECT t1_id, t1_name, t1_int, t2_id, t2_name, t2_int
+FROM t1
+ LEFT JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t2.t2_int < 10
+ OR (t1.t1_int > 2
+ AND t2.t2_name != 'w')
+----
+11 a 1 11 z 3
+22 b 2 22 y 1
+44 d 4 44 x 3
+
+# reduce_left_join_3
+query ITIITI
+SELECT *
+FROM (
+ SELECT t1.*
+ FROM t1
+ LEFT JOIN t2 ON t1.t1_id = t2.t2_id
+ WHERE t2.t2_int < 3
+) t3
+ LEFT JOIN t2 ON t3.t1_int = t2.t2_int
+WHERE t3.t1_id < 100
+----
+22 b 2 NULL NULL NULL
+
+# reduce_right_join_1
+query ITIITI rowsort
+SELECT t1_id, t1_name, t1_int, t2_id, t2_name, t2_int
+FROM t1
+ RIGHT JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t1.t1_int IS NOT NULL
+----
+11 a 1 11 z 3
+22 b 2 22 y 1
+44 d 4 44 x 3
+
+# reduce_right_join_2
+query ITIITI rowsort
+SELECT *
+FROM t1
+ RIGHT JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE NOT t1.t1_int = t2.t2_int
+----
+11 a 1 11 z 3
+22 b 2 22 y 1
+44 d 4 44 x 3
+
+# reduce_full_join_to_right_join
+query ITIITI rowsort
+SELECT *
+FROM t1
+ FULL JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t2.t2_name IS NOT NULL
+----
+11 a 1 11 z 3
+22 b 2 22 y 1
+44 d 4 44 x 3
+NULL NULL NULL 55 w 3
+
+# reduce_full_join_to_left_join
+query ITIITI rowsort
+SELECT *
+FROM t1
+ FULL JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t1.t1_name != 'b'
+----
+11 a 1 11 z 3
+33 c 3 NULL NULL NULL
+44 d 4 44 x 3
+
+# reduce_full_join_to_inner_join
+query ITIITI rowsort
+SELECT *
+FROM t1
+ FULL JOIN t2 ON t1.t1_id = t2.t2_id
+WHERE t1.t1_name != 'b'
+ AND t2.t2_name = 'x'
+----
+44 d 4 44 x 3
+
+# left_join_with_nonequal_condition
+query ITT rowsort
+SELECT t1_id, t1_name, t2_name
+FROM t1
+ LEFT JOIN t2
+ ON t1_id != t2_id
+ AND t2_id >= 100
+----
+11 a NULL
+22 b NULL
+33 c NULL
+44 d NULL
+
+# reduce_cross_join_with_expr_join_key_all
+query ITIITI rowsort
+SELECT *
+FROM t1
+ CROSS JOIN t2
+WHERE t1.t1_id + 12 = t2.t2_id + 1
+----
+11 a 1 22 y 1
+33 c 3 44 x 3
+44 d 4 55 w 3
+
+# reduce_cross_join_with_cast_expr_join_key
+query IIT rowsort
+SELECT t1.t1_id, t2.t2_id, t1.t1_name
+FROM t1
+ CROSS JOIN t2
+WHERE t1.t1_id + 11 = CAST(t2.t2_id AS BIGINT)
+----
+11 22 a
+33 44 c
+44 55 d
+
+# reduce_cross_join_with_wildcard_and_expr
+query ITIITII rowsort
+SELECT *, t1.t1_id + 11
+FROM t1, t2
+WHERE t1.t1_id + 11 = t2.t2_id
+----
+11 a 1 22 y 1 22
+33 c 3 44 x 3 44
+44 d 4 55 w 3 55
+
+# both_side_expr_key_inner_join
+query IIT rowsort
+SELECT t1.t1_id, t2.t2_id, t1.t1_name
+FROM t1
+ INNER JOIN t2 ON
+ t1.t1_id + cast(12 as INT UNSIGNED) = t2.t2_id + cast(1 as INT UNSIGNED)
+----
+11 22 a
+33 44 c
+44 55 d
+
+# left_side_expr_key_inner_join
+query IIT rowsort
+SELECT t1_id, t2_id, t1_name
+FROM t1
+ INNER JOIN t2 ON
+ t1.t1_id + cast(11 as INT UNSIGNED) = t2.t2_id
+----
+11 22 a
+33 44 c
+44 55 d
+
+# right_side_expr_key_inner_join
+query IIT rowsort
+SELECT t1.t1_id, t2.t2_id, t1.t1_name
+FROM t1
+ INNER JOIN t2 ON
+ t1.t1_id + cast(11 as INT UNSIGNED) = t2.t2_id
+----
+11 22 a
+33 44 c
+44 55 d
+
+# select_wildcard_with_expr_key_inner_join
+query ITIITI rowsort
+SELECT * FROM t1 INNER JOIN t2 ON t1.t1_id = t2.t2_id - cast(11 as INT UNSIGNED)
+----
+11 a 1 22 y 1
+33 c 3 44 x 3
+44 d 4 55 w 3
+
+# join_with_type_coercion_for_equi_expr
+query ITI rowsort
+SELECT t1.t1_id, t1.t1_name, t2.t2_id
+FROM t1
+ INNER JOIN t2 ON t1.t1_id + 11 = t2.t2_id
+----
+11 a 22
+33 c 44
+44 d 55
+
+# join_only_with_filter
+query ITI rowsort
+select t1.t1_id, t1.t1_name, t2.t2_id from t1 inner join t2 on t1.t1_id * 4 < t2.t2_id
+----
+11 a 55
+
+# type_coercion_join_with_filter_and_equi_expr
+query ITI rowsort
+SELECT t1.t1_id, t1.t1_name, t2.t2_id
+FROM t1
+ INNER JOIN t2
+ ON t1.t1_id * 5 = t2.t2_id
+ AND t1.t1_id * 4 < t2.t2_id
+----
+11 a 55
+
+statement ok
+drop table IF EXISTS t1;
+
+statement ok
+drop table IF EXISTS t2;
+
+# batch size
+statement ok
+set datafusion.execution.batch_size = 8192;
diff --git a/datafusion/core/tests/sqllogictests/test_files/join_disable_repartition_joins.slt b/datafusion/core/tests/sqllogictests/test_files/join_disable_repartition_joins.slt
new file mode 100644
index 0000000000..5f680fcae7
--- /dev/null
+++ b/datafusion/core/tests/sqllogictests/test_files/join_disable_repartition_joins.slt
@@ -0,0 +1,30 @@
+# 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.
+
+##########
+## Join Tests
+##########
+
+# turn off repartition_joins
+statement ok
+set datafusion.optimizer.repartition_joins = false;
+
+include ./join.slt
+
+# turn on repartition_joins
+statement ok
+set datafusion.optimizer.repartition_joins = true;