Skip to content

Apache DataFusion SQL Query Engine

Migrate optimizer tests to insta (#15446)

Tommy shu615fba51de0b
diff --git a/Cargo.lock b/Cargo.lock
index aa4ffeb17c..828559409e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2394,6 +2394,7 @@ dependencies = [
"datafusion-sql",
"env_logger",
"indexmap 2.8.0",
+ "insta",
"itertools 0.14.0",
"log",
"recursive",
diff --git a/datafusion/optimizer/Cargo.toml b/datafusion/optimizer/Cargo.toml
index 3413b365f6..61d101aab3 100644
--- a/datafusion/optimizer/Cargo.toml
+++ b/datafusion/optimizer/Cargo.toml
@@ -61,3 +61,4 @@ datafusion-functions-window = { workspace = true }
datafusion-functions-window-common = { workspace = true }
datafusion-sql = { workspace = true }
env_logger = { workspace = true }
+insta = { workspace = true }
diff --git a/datafusion/optimizer/tests/optimizer_integration.rs b/datafusion/optimizer/tests/optimizer_integration.rs
index 098027dd06..941e5bd7b4 100644
--- a/datafusion/optimizer/tests/optimizer_integration.rs
+++ b/datafusion/optimizer/tests/optimizer_integration.rs
@@ -37,6 +37,7 @@ use datafusion_sql::planner::{ContextProvider, SqlToRel};
use datafusion_sql::sqlparser::ast::Statement;
use datafusion_sql::sqlparser::dialect::GenericDialect;
use datafusion_sql::sqlparser::parser::Parser;
+use insta::assert_snapshot;
#[cfg(test)]
#[ctor::ctor]
@@ -49,16 +50,25 @@ fn init() {
fn case_when() -> Result<()> {
let sql = "SELECT CASE WHEN col_int32 > 0 THEN 1 ELSE 0 END FROM test";
let plan = test_sql(sql)?;
- let expected =
- "Projection: CASE WHEN test.col_int32 > Int32(0) THEN Int64(1) ELSE Int64(0) END AS CASE WHEN test.col_int32 > Int64(0) THEN Int64(1) ELSE Int64(0) END\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+Projection: CASE WHEN test.col_int32 > Int32(0) THEN Int64(1) ELSE Int64(0) END AS CASE WHEN test.col_int32 > Int64(0) THEN Int64(1) ELSE Int64(0) END
+ TableScan: test projection=[col_int32]
+"#
+ );
let sql = "SELECT CASE WHEN col_uint32 > 0 THEN 1 ELSE 0 END FROM test";
let plan = test_sql(sql)?;
- let expected = "Projection: CASE WHEN test.col_uint32 > UInt32(0) THEN Int64(1) ELSE Int64(0) END AS CASE WHEN test.col_uint32 > Int64(0) THEN Int64(1) ELSE Int64(0) END\
- \n TableScan: test projection=[col_uint32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: CASE WHEN test.col_uint32 > UInt32(0) THEN Int64(1) ELSE Int64(0) END AS CASE WHEN test.col_uint32 > Int64(0) THEN Int64(1) ELSE Int64(0) END
+ TableScan: test projection=[col_uint32]
+ "#
+ );
Ok(())
}
@@ -72,16 +82,21 @@ fn subquery_filter_with_cast() -> Result<()> {
AND (cast('2002-05-08' as date) + interval '5 days')\
)";
let plan = test_sql(sql)?;
- let expected = "Projection: test.col_int32\
- \n Inner Join: Filter: CAST(test.col_int32 AS Float64) > __scalar_sq_1.avg(test.col_int32)\
- \n TableScan: test projection=[col_int32]\
- \n SubqueryAlias: __scalar_sq_1\
- \n Aggregate: groupBy=[[]], aggr=[[avg(CAST(test.col_int32 AS Float64))]]\
- \n Projection: test.col_int32\
- \n Filter: __common_expr_4 >= Date32(\"2002-05-08\") AND __common_expr_4 <= Date32(\"2002-05-13\")\
- \n Projection: CAST(test.col_utf8 AS Date32) AS __common_expr_4, test.col_int32\
- \n TableScan: test projection=[col_int32, col_utf8]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_int32
+ Inner Join: Filter: CAST(test.col_int32 AS Float64) > __scalar_sq_1.avg(test.col_int32)
+ TableScan: test projection=[col_int32]
+ SubqueryAlias: __scalar_sq_1
+ Aggregate: groupBy=[[]], aggr=[[avg(CAST(test.col_int32 AS Float64))]]
+ Projection: test.col_int32
+ Filter: __common_expr_4 >= Date32("2002-05-08") AND __common_expr_4 <= Date32("2002-05-13")
+ Projection: CAST(test.col_utf8 AS Date32) AS __common_expr_4, test.col_int32
+ TableScan: test projection=[col_int32, col_utf8]
+ "#
+ );
Ok(())
}
@@ -89,10 +104,15 @@ fn subquery_filter_with_cast() -> Result<()> {
fn case_when_aggregate() -> Result<()> {
let sql = "SELECT col_utf8, sum(CASE WHEN col_int32 > 0 THEN 1 ELSE 0 END) AS n FROM test GROUP BY col_utf8";
let plan = test_sql(sql)?;
- let expected = "Projection: test.col_utf8, sum(CASE WHEN test.col_int32 > Int64(0) THEN Int64(1) ELSE Int64(0) END) AS n\
- \n Aggregate: groupBy=[[test.col_utf8]], aggr=[[sum(CASE WHEN test.col_int32 > Int32(0) THEN Int64(1) ELSE Int64(0) END) AS sum(CASE WHEN test.col_int32 > Int64(0) THEN Int64(1) ELSE Int64(0) END)]]\
- \n TableScan: test projection=[col_int32, col_utf8]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_utf8, sum(CASE WHEN test.col_int32 > Int64(0) THEN Int64(1) ELSE Int64(0) END) AS n
+ Aggregate: groupBy=[[test.col_utf8]], aggr=[[sum(CASE WHEN test.col_int32 > Int32(0) THEN Int64(1) ELSE Int64(0) END) AS sum(CASE WHEN test.col_int32 > Int64(0) THEN Int64(1) ELSE Int64(0) END)]]
+ TableScan: test projection=[col_int32, col_utf8]
+ "#
+ );
Ok(())
}
@@ -100,10 +120,15 @@ fn case_when_aggregate() -> Result<()> {
fn unsigned_target_type() -> Result<()> {
let sql = "SELECT col_utf8 FROM test WHERE col_uint32 > 0";
let plan = test_sql(sql)?;
- let expected = "Projection: test.col_utf8\
- \n Filter: test.col_uint32 > UInt32(0)\
- \n TableScan: test projection=[col_uint32, col_utf8]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_utf8
+ Filter: test.col_uint32 > UInt32(0)
+ TableScan: test projection=[col_uint32, col_utf8]
+ "#
+ );
Ok(())
}
@@ -112,9 +137,14 @@ fn distribute_by() -> Result<()> {
// regression test for https://github.com/apache/datafusion/issues/3234
let sql = "SELECT col_int32, col_utf8 FROM test DISTRIBUTE BY (col_utf8)";
let plan = test_sql(sql)?;
- let expected = "Repartition: DistributeBy(test.col_utf8)\
- \n TableScan: test projection=[col_int32, col_utf8]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Repartition: DistributeBy(test.col_utf8)
+ TableScan: test projection=[col_int32, col_utf8]
+ "#
+ );
Ok(())
}
@@ -125,15 +155,20 @@ fn semi_join_with_join_filter() -> Result<()> {
SELECT col_utf8 FROM test t2 WHERE test.col_int32 = t2.col_int32 \
AND test.col_uint32 != t2.col_uint32)";
let plan = test_sql(sql)?;
- let expected = "Projection: test.col_utf8\
- \n LeftSemi Join: test.col_int32 = __correlated_sq_1.col_int32 Filter: test.col_uint32 != __correlated_sq_1.col_uint32\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32, col_uint32, col_utf8]\
- \n SubqueryAlias: __correlated_sq_1\
- \n SubqueryAlias: t2\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32, col_uint32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_utf8
+ LeftSemi Join: test.col_int32 = __correlated_sq_1.col_int32 Filter: test.col_uint32 != __correlated_sq_1.col_uint32
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32, col_uint32, col_utf8]
+ SubqueryAlias: __correlated_sq_1
+ SubqueryAlias: t2
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32, col_uint32]
+ "#
+ );
Ok(())
}
@@ -144,14 +179,19 @@ fn anti_join_with_join_filter() -> Result<()> {
SELECT col_utf8 FROM test t2 WHERE test.col_int32 = t2.col_int32 \
AND test.col_uint32 != t2.col_uint32)";
let plan = test_sql(sql)?;
- let expected = "Projection: test.col_utf8\
- \n LeftAnti Join: test.col_int32 = __correlated_sq_1.col_int32 Filter: test.col_uint32 != __correlated_sq_1.col_uint32\
- \n TableScan: test projection=[col_int32, col_uint32, col_utf8]\
- \n SubqueryAlias: __correlated_sq_1\
- \n SubqueryAlias: t2\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32, col_uint32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+Projection: test.col_utf8
+ LeftAnti Join: test.col_int32 = __correlated_sq_1.col_int32 Filter: test.col_uint32 != __correlated_sq_1.col_uint32
+ TableScan: test projection=[col_int32, col_uint32, col_utf8]
+ SubqueryAlias: __correlated_sq_1
+ SubqueryAlias: t2
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32, col_uint32]
+"#
+ );
Ok(())
}
@@ -160,15 +200,21 @@ fn where_exists_distinct() -> Result<()> {
let sql = "SELECT col_int32 FROM test WHERE EXISTS (\
SELECT DISTINCT col_int32 FROM test t2 WHERE test.col_int32 = t2.col_int32)";
let plan = test_sql(sql)?;
- let expected = "LeftSemi Join: test.col_int32 = __correlated_sq_1.col_int32\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32]\
- \n SubqueryAlias: __correlated_sq_1\
- \n Aggregate: groupBy=[[t2.col_int32]], aggr=[[]]\
- \n SubqueryAlias: t2\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+LeftSemi Join: test.col_int32 = __correlated_sq_1.col_int32
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32]
+ SubqueryAlias: __correlated_sq_1
+ Aggregate: groupBy=[[t2.col_int32]], aggr=[[]]
+ SubqueryAlias: t2
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32]
+"#
+
+ );
Ok(())
}
@@ -178,15 +224,19 @@ fn intersect() -> Result<()> {
INTERSECT SELECT col_int32, col_utf8 FROM test \
INTERSECT SELECT col_int32, col_utf8 FROM test";
let plan = test_sql(sql)?;
- let expected =
- "LeftSemi Join: test.col_int32 = test.col_int32, test.col_utf8 = test.col_utf8\
- \n Aggregate: groupBy=[[test.col_int32, test.col_utf8]], aggr=[[]]\
- \n LeftSemi Join: test.col_int32 = test.col_int32, test.col_utf8 = test.col_utf8\
- \n Aggregate: groupBy=[[test.col_int32, test.col_utf8]], aggr=[[]]\
- \n TableScan: test projection=[col_int32, col_utf8]\
- \n TableScan: test projection=[col_int32, col_utf8]\
- \n TableScan: test projection=[col_int32, col_utf8]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+LeftSemi Join: test.col_int32 = test.col_int32, test.col_utf8 = test.col_utf8
+ Aggregate: groupBy=[[test.col_int32, test.col_utf8]], aggr=[[]]
+ LeftSemi Join: test.col_int32 = test.col_int32, test.col_utf8 = test.col_utf8
+ Aggregate: groupBy=[[test.col_int32, test.col_utf8]], aggr=[[]]
+ TableScan: test projection=[col_int32, col_utf8]
+ TableScan: test projection=[col_int32, col_utf8]
+ TableScan: test projection=[col_int32, col_utf8]
+"#
+ );
Ok(())
}
@@ -195,12 +245,16 @@ fn between_date32_plus_interval() -> Result<()> {
let sql = "SELECT count(1) FROM test \
WHERE col_date32 between '1998-03-18' AND cast('1998-03-18' as date) + INTERVAL '90 days'";
let plan = test_sql(sql)?;
- let expected =
- "Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]\
- \n Projection: \
- \n Filter: test.col_date32 >= Date32(\"1998-03-18\") AND test.col_date32 <= Date32(\"1998-06-16\")\
- \n TableScan: test projection=[col_date32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]
+ Projection:
+ Filter: test.col_date32 >= Date32("1998-03-18") AND test.col_date32 <= Date32("1998-06-16")
+ TableScan: test projection=[col_date32]
+"#
+ );
Ok(())
}
@@ -209,12 +263,16 @@ fn between_date64_plus_interval() -> Result<()> {
let sql = "SELECT count(1) FROM test \
WHERE col_date64 between '1998-03-18T00:00:00' AND cast('1998-03-18' as date) + INTERVAL '90 days'";
let plan = test_sql(sql)?;
- let expected =
- "Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]\
- \n Projection: \
- \n Filter: test.col_date64 >= Date64(\"1998-03-18\") AND test.col_date64 <= Date64(\"1998-06-16\")\
- \n TableScan: test projection=[col_date64]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Aggregate: groupBy=[[]], aggr=[[count(Int64(1))]]
+ Projection:
+ Filter: test.col_date64 >= Date64("1998-03-18") AND test.col_date64 <= Date64("1998-06-16")
+ TableScan: test projection=[col_date64]
+ "#
+ );
Ok(())
}
@@ -223,54 +281,73 @@ fn propagate_empty_relation() {
let sql = "SELECT test.col_int32 FROM test JOIN ( SELECT col_int32 FROM test WHERE false ) AS ta1 ON test.col_int32 = ta1.col_int32;";
let plan = test_sql(sql).unwrap();
// when children exist EmptyRelation, it will bottom-up propagate.
- let expected = "EmptyRelation";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ EmptyRelation
+ "#
+ );
}
#[test]
fn join_keys_in_subquery_alias() {
let sql = "SELECT * FROM test AS A, ( SELECT col_int32 as key FROM test ) AS B where A.col_int32 = B.key;";
let plan = test_sql(sql).unwrap();
- let expected = "Inner Join: a.col_int32 = b.key\
- \n SubqueryAlias: a\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]\
- \n SubqueryAlias: b\
- \n Projection: test.col_int32 AS key\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32]";
-
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Inner Join: a.col_int32 = b.key
+ SubqueryAlias: a
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]
+ SubqueryAlias: b
+ Projection: test.col_int32 AS key
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32]
+ "#
+ );
}
#[test]
fn join_keys_in_subquery_alias_1() {
let sql = "SELECT * FROM test AS A, ( SELECT test.col_int32 AS key FROM test JOIN test AS C on test.col_int32 = C.col_int32 ) AS B where A.col_int32 = B.key;";
let plan = test_sql(sql).unwrap();
- let expected = "Inner Join: a.col_int32 = b.key\
- \n SubqueryAlias: a\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]\
- \n SubqueryAlias: b\
- \n Projection: test.col_int32 AS key\
- \n Inner Join: test.col_int32 = c.col_int32\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32]\
- \n SubqueryAlias: c\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Inner Join: a.col_int32 = b.key
+ SubqueryAlias: a
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]
+ SubqueryAlias: b
+ Projection: test.col_int32 AS key
+ Inner Join: test.col_int32 = c.col_int32
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32]
+ SubqueryAlias: c
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32]
+ "#
+ );
}
#[test]
fn push_down_filter_groupby_expr_contains_alias() {
let sql = "SELECT * FROM (SELECT (col_int32 + col_uint32) AS c, count(*) FROM test GROUP BY 1) where c > 3";
let plan = test_sql(sql).unwrap();
- let expected = "Projection: test.col_int32 + test.col_uint32 AS c, count(Int64(1)) AS count(*)\
- \n Aggregate: groupBy=[[CAST(test.col_int32 AS Int64) + CAST(test.col_uint32 AS Int64)]], aggr=[[count(Int64(1))]]\
- \n Filter: CAST(test.col_int32 AS Int64) + CAST(test.col_uint32 AS Int64) > Int64(3)\
- \n TableScan: test projection=[col_int32, col_uint32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_int32 + test.col_uint32 AS c, count(Int64(1)) AS count(*)
+ Aggregate: groupBy=[[CAST(test.col_int32 AS Int64) + CAST(test.col_uint32 AS Int64)]], aggr=[[count(Int64(1))]]
+ Filter: CAST(test.col_int32 AS Int64) + CAST(test.col_uint32 AS Int64) > Int64(3)
+ TableScan: test projection=[col_int32, col_uint32]
+ "#
+ );
}
#[test]
@@ -278,13 +355,18 @@ fn push_down_filter_groupby_expr_contains_alias() {
fn test_same_name_but_not_ambiguous() {
let sql = "SELECT t1.col_int32 AS col_int32 FROM test t1 intersect SELECT col_int32 FROM test t2";
let plan = test_sql(sql).unwrap();
- let expected = "LeftSemi Join: t1.col_int32 = t2.col_int32\
- \n Aggregate: groupBy=[[t1.col_int32]], aggr=[[]]\
- \n SubqueryAlias: t1\
- \n TableScan: test projection=[col_int32]\
- \n SubqueryAlias: t2\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ LeftSemi Join: t1.col_int32 = t2.col_int32
+ Aggregate: groupBy=[[t1.col_int32]], aggr=[[]]
+ SubqueryAlias: t1
+ TableScan: test projection=[col_int32]
+ SubqueryAlias: t2
+ TableScan: test projection=[col_int32]
+ "#
+ );
}
#[test]
@@ -295,11 +377,14 @@ fn eliminate_nested_filters() {
AND (1=1) AND (1=0 OR 1=1)";
let plan = test_sql(sql).unwrap();
- let expected = "\
- Filter: test.col_int32 > Int32(0)\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+Filter: test.col_int32 > Int32(0)
+ TableScan: test projection=[col_int32]
+ "#
+ );
}
#[test]
@@ -310,10 +395,15 @@ fn eliminate_redundant_null_check_on_count() {
GROUP BY col_int32
HAVING c IS NOT NULL";
let plan = test_sql(sql).unwrap();
- let expected = "Projection: test.col_int32, count(Int64(1)) AS count(*) AS c\
- \n Aggregate: groupBy=[[test.col_int32]], aggr=[[count(Int64(1))]]\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_int32, count(Int64(1)) AS count(*) AS c
+ Aggregate: groupBy=[[test.col_int32]], aggr=[[count(Int64(1))]]
+ TableScan: test projection=[col_int32]
+ "#
+ );
}
#[test]
@@ -333,13 +423,16 @@ fn test_propagate_empty_relation_inner_join_and_unions() {
SELECT test.col_int32 FROM test WHERE 1 = 0";
let plan = test_sql(sql).unwrap();
- let expected = "\
- Union\
- \n TableScan: test projection=[col_int32]\
- \n TableScan: test projection=[col_int32]\
- \n Filter: test.col_int32 < Int32(0)\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+Union
+ TableScan: test projection=[col_int32]
+ TableScan: test projection=[col_int32]
+ Filter: test.col_int32 < Int32(0)
+ TableScan: test projection=[col_int32]
+ "#);
}
#[test]
@@ -347,10 +440,14 @@ fn select_wildcard_with_repeated_column_but_is_aliased() {
let sql = "SELECT *, col_int32 as col_32 FROM test";
let plan = test_sql(sql).unwrap();
- let expected = "Projection: test.col_int32, test.col_uint32, test.col_utf8, test.col_date32, test.col_date64, test.col_ts_nano_none, test.col_ts_nano_utc, test.col_int32 AS col_32\
- \n TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]";
- assert_eq!(expected, format!("{plan}"));
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ Projection: test.col_int32, test.col_uint32, test.col_utf8, test.col_date32, test.col_date64, test.col_ts_nano_none, test.col_ts_nano_utc, test.col_int32 AS col_32
+ TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]
+ "#
+ );
}
#[test]
@@ -367,15 +464,20 @@ fn select_correlated_predicate_subquery_with_uppercase_ident() {
)
"#;
let plan = test_sql(sql).unwrap();
- let expected = "LeftSemi Join: test.col_int32 = __correlated_sq_1.COL_INT32\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]\
- \n SubqueryAlias: __correlated_sq_1\
- \n SubqueryAlias: T1\
- \n Projection: test.col_int32 AS COL_INT32\
- \n Filter: test.col_int32 IS NOT NULL\
- \n TableScan: test projection=[col_int32]";
- assert_eq!(expected, format!("{plan}"));
+
+ assert_snapshot!(
+ format!("{plan}"),
+ @r#"
+ LeftSemi Join: test.col_int32 = __correlated_sq_1.COL_INT32
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32, col_uint32, col_utf8, col_date32, col_date64, col_ts_nano_none, col_ts_nano_utc]
+ SubqueryAlias: __correlated_sq_1
+ SubqueryAlias: T1
+ Projection: test.col_int32 AS COL_INT32
+ Filter: test.col_int32 IS NOT NULL
+ TableScan: test projection=[col_int32]
+ "#
+ );
}
fn test_sql(sql: &str) -> Result<LogicalPlan> {