MCPcopy Create free account
hub / github.com/apache/datafusion / test_unparse_left_mark_join

Function test_unparse_left_mark_join

datafusion/sql/tests/cases/plan_to_sql.rs:2575–2607  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2573
2574#[test]
2575fn test_unparse_left_mark_join() -> Result<()> {
2576 // select t1.d from t1 where t1.d < 0 OR exists (select 1 from t2 where t1.c = t2.c)
2577 let schema = Schema::new(vec![
2578 Field::new("c", DataType::Int32, false),
2579 Field::new("d", DataType::Int32, false),
2580 ]);
2581 // Filter: __correlated_sq_1.mark OR t1.d < Int32(0)
2582 // Projection: t1.d
2583 // LeftMark Join: Filter: t1.c = __correlated_sq_1.c
2584 // TableScan: t1 projection=[c, d]
2585 // SubqueryAlias: __correlated_sq_1
2586 // TableScan: t2 projection=[c]
2587 let table_scan1 = table_scan(Some("t1"), &schema, Some(vec![0, 1]))?.build()?;
2588 let table_scan2 = table_scan(Some("t2"), &schema, Some(vec![0]))?.build()?;
2589 let subquery = subquery_alias(table_scan2, "__correlated_sq_1")?;
2590 let plan = LogicalPlanBuilder::from(table_scan1)
2591 .join_on(
2592 subquery,
2593 datafusion_expr::JoinType::LeftMark,
2594 vec![col("t1.c").eq(col("__correlated_sq_1.c"))],
2595 )?
2596 .project(vec![col("t1.d")])?
2597 .filter(col("mark").or(col("t1.d").lt(lit(0))))?
2598 .build()?;
2599
2600 let unparser = Unparser::new(&UnparserPostgreSqlDialect {});
2601 let sql = unparser.plan_to_sql(&plan)?;
2602 assert_snapshot!(
2603 sql,
2604 @r#"SELECT "t1"."d" FROM "t1" WHERE (EXISTS (SELECT 1 FROM "t2" AS "__correlated_sq_1" WHERE ("t1"."c" = "__correlated_sq_1"."c")) OR ("t1"."d" < 0))"#
2605 );
2606 Ok(())
2607}
2608
2609#[test]
2610fn test_unparse_right_semi_join() -> Result<()> {

Callers

nothing calls this directly

Calls 12

newFunction · 0.85
table_scanFunction · 0.85
subquery_aliasFunction · 0.85
plan_to_sqlMethod · 0.80
colFunction · 0.50
litFunction · 0.50
buildMethod · 0.45
filterMethod · 0.45
projectMethod · 0.45
join_onMethod · 0.45
orMethod · 0.45
ltMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…