simonvandel opened a new issue, #6710:
URL: https://github.com/apache/arrow-datafusion/issues/6710

   ### Describe the bug
   
   This query
   ```sql
   CREATE VIEW test(timestamp , value) AS VALUES(1,2),(5,6);
   
   EXPLAIN SELECT LAG(timestamp) OVER (ORDER BY timestamp) as prev, value FROM 
(SELECT * FROM test ORDER BY timestamp);
   ```
   gives
   
   ```
   DataFusion CLI v26.0.0
   0 rows in set. Query took 0.000 seconds.
   
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | plan_type     | plan                                                       
                                                                                
                                                                                
                                                                      |
   
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | logical_plan  | Projection: LAG(test.timestamp) ORDER BY [test.timestamp 
ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW AS prev, 
test.value                                                                      
                                                                             |
   |               |   WindowAggr: windowExpr=[[LAG(test.timestamp) ORDER BY 
[test.timestamp ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT 
ROW]]                                                                           
                                                                           |
   |               |     Sort: test.timestamp ASC NULLS LAST                    
                                                                                
                                                                                
                                                                      |
   |               |       SubqueryAlias: test                                  
                                                                                
                                                                                
                                                                      |
   |               |         Projection: column1 AS timestamp, column2 AS value 
                                                                                
                                                                                
                                                                      |
   |               |           Values: (Int64(1), Int64(2)), (Int64(5), 
Int64(6))                                                                       
                                                                                
                                                                              |
   | physical_plan | ProjectionExec: expr=[LAG(test.timestamp) ORDER BY 
[test.timestamp ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT 
ROW@2 as prev, value@1 as value]                                                
                                                                                
|
   |               |   BoundedWindowAggExec: wdw=[LAG(test.timestamp): Ok(Field 
{ name: "LAG(test.timestamp)", data_type: Int64, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, 
start_bound: Preceding(Int64(NULL)), end_bound: CurrentRow }], mode=[Sorted] |
   |               |     SortExec: expr=[timestamp@0 ASC NULLS LAST]            
                                                                                
                                                                                
                                                                      |
   |               |       ProjectionExec: expr=[column1@0 as timestamp, 
column2@1 as value]                                                             
                                                                                
                                                                             |
   |               |         ValuesExec                                         
                                                                                
                                                                                
                                                                      |
   |               |                                                            
                                                                                
                                                                                
                                                                      |
   
+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   ```
   
   ### To Reproduce
   
   _No response_
   
   ### Expected behavior
   
   I would expect that the `ORDER BY` in the window frame could be eliminated 
since the `SortExec` upstream enforces the same ordering.
   
   ### Additional context
   
   _No response_


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to