File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7193,7 +7193,7 @@ async fn test_copy_to_preserves_order() -> Result<()> {
71937193 DataSinkExec: sink=CsvSink(file_groups=[])
71947194 SortExec: expr=[column1@0 DESC], preserve_partitioning=[false]
71957195 DataSourceExec: partitions=1, partition_sizes=[1]
7196- ProjectionExec: expr=[CAST( column1@0 AS UInt64) as count]
7196+ ProjectionExec: expr=[column1@0 as count]
71977197 DataSourceExec: partitions=1, partition_sizes=[1]
71987198 "
71997199 ) ;
Original file line number Diff line number Diff line change @@ -315,7 +315,29 @@ impl<'a> TypeCoercionRewriter<'a> {
315315 Arc :: clone ( & union_schema) ,
316316 ) ?) )
317317 }
318- other_plan => Ok ( Arc :: new ( other_plan) ) ,
318+ other_plan => {
319+ let needs_rename = other_plan
320+ . schema ( )
321+ . fields ( )
322+ . iter ( )
323+ . zip ( union_schema. fields ( ) )
324+ . any ( |( input, output) | input. name ( ) != output. name ( ) ) ;
325+ if needs_rename {
326+ let expr = other_plan
327+ . schema ( )
328+ . columns ( )
329+ . into_iter ( )
330+ . map ( Expr :: Column )
331+ . collect ( ) ;
332+ Ok ( Arc :: new ( project_with_column_index (
333+ expr,
334+ Arc :: new ( other_plan) ,
335+ Arc :: clone ( & union_schema) ,
336+ ) ?) )
337+ } else {
338+ Ok ( Arc :: new ( other_plan) )
339+ }
340+ }
319341 }
320342 } )
321343 . collect :: < Result < Vec < _ > > > ( ) ?;
Original file line number Diff line number Diff line change @@ -380,7 +380,8 @@ mod tests {
380380 TableScan: table
381381 Projection: id AS table_id, key, value
382382 TableScan: table
383- TableScan: table
383+ Projection: table.id AS table_id, table.key, table.value
384+ TableScan: table
384385 " )
385386 }
386387
Original file line number Diff line number Diff line change @@ -1044,3 +1044,12 @@ physical_plan
10441044
10451045statement ok
10461046DROP TABLE t22489;
1047+
1048+ # Limited UNION branches must preserve same-named join columns through Substrait.
1049+ query II rowsort
1050+ (SELECT * FROM (VALUES (1)) AS x(a) CROSS JOIN (VALUES (2)) AS y(a) LIMIT 1)
1051+ UNION ALL
1052+ SELECT * FROM (VALUES (3)) AS x(a) CROSS JOIN (VALUES (4)) AS y(a);
1053+ ----
1054+ 1 2
1055+ 3 4
You can’t perform that action at this time.
0 commit comments