alamb commented on code in PR #16625:
URL: https://github.com/apache/datafusion/pull/16625#discussion_r2178510104


##########
datafusion/sqllogictest/test_files/group_by.slt:
##########
@@ -2903,7 +2909,8 @@ logical_plan
 physical_plan
 01)ProjectionExec: expr=[country@0 as country, 
first_value(sales_global.amount) ORDER BY [sales_global.ts DESC NULLS FIRST]@1 
as fv1, last_value(sales_global.amount) ORDER BY [sales_global.ts DESC NULLS 
FIRST]@2 as lv1, sum(sales_global.amount) ORDER BY [sales_global.ts DESC NULLS 
FIRST]@3 as sum1]
 02)--AggregateExec: mode=Single, gby=[country@0 as country], 
aggr=[first_value(sales_global.amount) ORDER BY [sales_global.ts DESC NULLS 
FIRST], last_value(sales_global.amount) ORDER BY [sales_global.ts DESC NULLS 
FIRST], sum(sales_global.amount) ORDER BY [sales_global.ts DESC NULLS FIRST]]
-03)----DataSourceExec: partitions=1, partition_sizes=[1]
+03)----SortExec: expr=[ts@1 DESC], preserve_partitioning=[false]

Review Comment:
   It is weird -- the comments say this plan should have a SortExec but the 
plan that is checked in does not have one



##########
datafusion/sqllogictest/test_files/aggregate.slt:
##########
@@ -6306,7 +6356,7 @@ logical_plan
 physical_plan
 01)AggregateExec: mode=Final, gby=[], 
aggr=[first_value(convert_first_last_table.c1) ORDER BY 
[convert_first_last_table.c3 DESC NULLS FIRST]]
 02)--CoalescePartitionsExec
-03)----AggregateExec: mode=Partial, gby=[], 
aggr=[last_value(convert_first_last_table.c1) ORDER BY 
[convert_first_last_table.c3 ASC NULLS LAST]]
+03)----AggregateExec: mode=Partial, gby=[], 
aggr=[first_value(convert_first_last_table.c1) ORDER BY 
[convert_first_last_table.c3 DESC NULLS FIRST]]

Review Comment:
   Now this makes it look like the plan is wrong:
   1. the query calls for `first_value(c1 ORDER BY c3 desc)` but the table is 
sorted by `c3 ASC`
   
   I think internally the optimizer has rewritten `first_value(c1 ORDER BY c3 
desc)` to `last_value(c1 ORDER BY c3 ASC)`
   
   However this plan makes it look like that didn't happen



##########
datafusion/sqllogictest/test_files/group_by.slt:
##########
@@ -2742,7 +2747,7 @@ logical_plan
 03)----TableScan: sales_global projection=[country, amount]
 physical_plan
 01)ProjectionExec: expr=[country@0 as country, array_agg(sales_global.amount) 
ORDER BY [sales_global.amount DESC NULLS FIRST]@1 as amounts, 
first_value(sales_global.amount) ORDER BY [sales_global.amount ASC NULLS 
LAST]@2 as fv1, last_value(sales_global.amount) ORDER BY [sales_global.amount 
DESC NULLS FIRST]@3 as fv2]
-02)--AggregateExec: mode=Single, gby=[country@0 as country], 
aggr=[array_agg(sales_global.amount) ORDER BY [sales_global.amount DESC NULLS 
FIRST], last_value(sales_global.amount) ORDER BY [sales_global.amount DESC 
NULLS FIRST], last_value(sales_global.amount) ORDER BY [sales_global.amount 
DESC NULLS FIRST]]
+02)--AggregateExec: mode=Single, gby=[country@0 as country], 
aggr=[array_agg(sales_global.amount) ORDER BY [sales_global.amount DESC NULLS 
FIRST], first_value(sales_global.amount) ORDER BY [sales_global.amount ASC 
NULLS LAST], last_value(sales_global.amount) ORDER BY [sales_global.amount DESC 
NULLS FIRST]]

Review Comment:
   that certainly seems like an improvement



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to