NoahKusaba opened a new issue, #2956:
URL: https://github.com/apache/datafusion-ballista/issues/2956

   **Describe the bug**
   
   With the static planner and `datafusion.optimizer.preserve_file_partitions = 
1`, a `GROUP BY f_dkey ORDER BY f_dkey` over a table partitioned by `f_dkey` 
often returns its groups out of order. The adaptive planner returns them in 
order.
   
   **To Reproduce**
   
   Standalone Ballista on `main` (446fa54c9), static planner (default), default 
settings otherwise. Taken from DataFusion's `preserve_file_partitioning.slt`:
   
   ```sql
   SET datafusion.execution.target_partitions = 3;
   
   COPY (SELECT column1 AS timestamp, column2 AS value FROM (VALUES
     (TIMESTAMP '2023-01-01T09:00:00', 95.5), (TIMESTAMP '2023-01-01T09:00:10', 
102.3),
     (TIMESTAMP '2023-01-01T09:00:20', 98.7), (TIMESTAMP '2023-01-01T09:12:20', 
105.1),
     (TIMESTAMP '2023-01-01T09:12:30', 100.0), (TIMESTAMP 
'2023-01-01T09:12:40', 150.0),
     (TIMESTAMP '2023-01-01T09:12:50', 120.8)))
   TO '/tmp/pfp/fact/f_dkey=A/data.parquet' STORED AS PARQUET;
   
   COPY (SELECT column1 AS timestamp, column2 AS value FROM (VALUES
     (TIMESTAMP '2023-01-01T09:00:00', 75.2), (TIMESTAMP '2023-01-01T09:00:10', 
82.4),
     (TIMESTAMP '2023-01-01T09:00:20', 78.9), (TIMESTAMP '2023-01-01T09:00:30', 
85.6),
     (TIMESTAMP '2023-01-01T09:12:30', 80.0), (TIMESTAMP '2023-01-01T09:12:40', 
120.0),
     (TIMESTAMP '2023-01-01T09:12:50', 92.3)))
   TO '/tmp/pfp/fact/f_dkey=B/data.parquet' STORED AS PARQUET;
   
   COPY (SELECT column1 AS timestamp, column2 AS value FROM (VALUES
     (TIMESTAMP '2023-01-01T09:00:00', 300.5), (TIMESTAMP 
'2023-01-01T09:00:10', 285.7),
     (TIMESTAMP '2023-01-01T09:00:20', 310.2), (TIMESTAMP 
'2023-01-01T09:00:30', 295.8),
     (TIMESTAMP '2023-01-01T09:00:40', 300.0), (TIMESTAMP 
'2023-01-01T09:12:40', 250.0),
     (TIMESTAMP '2023-01-01T09:12:50', 275.4)))
   TO '/tmp/pfp/fact/f_dkey=C/data.parquet' STORED AS PARQUET;
   
   CREATE EXTERNAL TABLE fact_table_ordered (timestamp TIMESTAMP, value DOUBLE)
   STORED AS PARQUET
   PARTITIONED BY (f_dkey STRING)
   WITH ORDER (f_dkey ASC, timestamp ASC)
   LOCATION '/tmp/pfp/fact/';
   
   SET datafusion.optimizer.preserve_file_partitions = 1;
   
   SELECT f_dkey, count(*), avg(value) FROM fact_table_ordered GROUP BY f_dkey 
ORDER BY f_dkey;
   ```
   
   In 2 of 3 runs the static planner returned `B`, `C`, `A`.
   
   **Expected behavior**
   
   `A`, `B`, `C`.
   
   **Additional context**
   
   Found by running DataFusion's sqllogictest files on Ballista (#2945): 
`preserve_file_partitioning.slt:312`. In DataFusion the plan is a 
`SortPreservingMergeExec` over an `AggregateExec` in `SinglePartitioned` mode, 
with no `SortExec`, so the order depends on that merge.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to