You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test: add tests for aggregate over subquery unparsing
Add roundtrip_aggregate_over_subquery and
test_unparse_aggregate_over_subquery_no_inner_proj to cover aggregate
expressions over subquery aliases. The latter demonstrates a bug where
the outer projection resolves aggregate expressions instead of column
references when the Projection between Limit and Aggregate is absent.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
let sql = r#"SELECT __agg_0 AS "min(j1_id)", __agg_1 AS "max(j1_id)" FROM (SELECT min(j1_rename) AS __agg_0, max(j1_rename) AS __agg_1 FROM (SELECT j1_id AS j1_rename FROM j1) AS bla LIMIT 20)"#;
.unwrap_or_else(|e| panic!("Failed to parse sql: {sql}\n{e}"));
2943
+
2944
+
println!("Logical plan:\n{plan}");
2945
+
println!("\nLogical plan (verbose):\n{}", plan.display_indent_schema());
2946
+
2947
+
let unparser = Unparser::new(&UnparserDefaultDialect{});
2948
+
let roundtrip_statement = unparser.plan_to_sql(&plan)?;
2949
+
let actual = &roundtrip_statement.to_string();
2950
+
2951
+
insta::assert_snapshot!(actual, @r#"SELECT __agg_0 AS "min(j1_id)", __agg_1 AS "max(j1_id)" FROM (SELECT min(bla.j1_rename) AS __agg_0, max(bla.j1_rename) AS __agg_1 FROM (SELECT j1.j1_id AS j1_rename FROM j1) AS bla LIMIT 20)"#);
2952
+
Ok(())
2953
+
}
2954
+
2955
+
/// Same as roundtrip_aggregate_over_subquery but with the Projection between
2956
+
/// Limit and Aggregate removed — the aliases are inlined into the Aggregate.
2957
+
///
2958
+
/// Plan shape:
2959
+
/// Projection: __agg_0 AS "max1(j1_id)", __agg_1 AS "max2(j1_id)"
2960
+
/// Limit: fetch=20
2961
+
/// Aggregate: aggr=[[max(bla.j1_rename) AS __agg_0, max(bla.j1_rename) AS __agg_1]]
0 commit comments