Skip to content

Commit 9693f66

Browse files
committed
test: compare full unparsed SQL for issue 23138
Update the unparser regression test to assert the complete DuckDB SQL output while keeping focused checks for the unqualified order_id invariant. Signed-off-by: Jiawei Zhao <[email protected]>
1 parent e88b7bd commit 9693f66

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎datafusion/core/tests/sql/unparser.rs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -374,25 +374,25 @@ async fn optimized_duckdb_unparse_qualifies_nested_passthrough_column() -> Resul
374374
// `order_id` must be unqualified there, not rebased to the subquery alias
375375
// `o` (which is only the base-table alias one level deeper). The bug emitted
376376
// `"o"."order_id"` inside that derived table; the fix emits a bare column.
377-
let discount_alias = r#" AS "discount_pct_2""#;
378-
let alias_pos = sql
379-
.find(discount_alias)
380-
.expect("unparsed SQL should contain discount_pct_2 alias");
381-
let select_start = sql[..alias_pos]
382-
.rfind("(SELECT ")
383-
.expect("discount_pct_2 should be in a derived SELECT");
384-
let from_start = alias_pos
385-
+ sql[alias_pos..]
386-
.find(" FROM ")
387-
.expect("discount_pct_2 SELECT should contain FROM");
388-
let derived_projection = &sql[select_start..from_start];
377+
let expected = concat!(
378+
r#"SELECT "o"."order_id", "o"."discount_pct_2" "#,
379+
r#"FROM "warehouse"."main"."order_items" AS "oi" "#,
380+
r#"INNER JOIN (SELECT "order_id", "#,
381+
r#"CASE WHEN "__common_expr_1" IS NOT NULL "#,
382+
r#"THEN "__common_expr_1" ELSE 0.00 END AS "discount_pct_2" "#,
383+
r#"FROM (SELECT CAST("o"."discount_pct" AS DECIMAL(22,2)) "#,
384+
r#"AS "__common_expr_1", "o"."order_id" "#,
385+
r#"FROM "warehouse"."main"."orders" AS "o")) AS "o" "#,
386+
r#"ON "oi"."order_id" = "o"."order_id""#,
387+
);
388+
assert_eq!(sql, expected);
389389

390390
assert!(
391-
derived_projection.contains(r#""order_id""#),
391+
sql.contains(r#"(SELECT "order_id", CASE WHEN"#),
392392
"pass-through order_id should be unqualified in derived table: {sql}"
393393
);
394394
assert!(
395-
!derived_projection.contains(r#""o"."order_id""#),
395+
!sql.contains(r#"(SELECT "o"."order_id", CASE WHEN"#),
396396
"derived table must not reference out-of-scope alias o: {sql}"
397397
);
398398

0 commit comments

Comments
 (0)