File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -380,6 +380,11 @@ impl DFSchema {
380380 let finished_with_metadata = finished. with_metadata ( metadata) ;
381381 self . inner = finished_with_metadata. into ( ) ;
382382 self . field_qualifiers . extend ( qualifiers) ;
383+ // Propagate ambiguous names from the other schema so that names marked
384+ // as ambiguous (e.g. by a JOIN) are not silently dropped when schemas
385+ // are merged for ORDER BY / HAVING resolution.
386+ self . ambiguous_names
387+ . extend ( other_schema. ambiguous_names . iter ( ) . cloned ( ) ) ;
383388 }
384389
385390 /// Get a list of fields for this schema
Original file line number Diff line number Diff line change @@ -3938,6 +3938,19 @@ fn order_by_ambiguous_name() {
39383938 ) ;
39393939}
39403940
3941+ #[ test]
3942+ fn order_by_ambiguous_name_via_subquery ( ) {
3943+ // `age` is not in the SELECT list; ORDER BY falls back to the FROM schema,
3944+ // which is a subquery over a JOIN — `age` must still be flagged ambiguous.
3945+ let sql = "SELECT id FROM (SELECT * FROM person a JOIN person b USING (id)) sub ORDER BY age" ;
3946+ let err = logical_plan ( sql) . unwrap_err ( ) . strip_backtrace ( ) ;
3947+
3948+ assert_snapshot ! (
3949+ err,
3950+ @"Schema error: Ambiguous reference to unqualified field age"
3951+ ) ;
3952+ }
3953+
39413954#[ test]
39423955fn group_by_ambiguous_name ( ) {
39433956 let sql = "select max(id) from person a join person b using (id) group by age" ;
You can’t perform that action at this time.
0 commit comments