alamb commented on PR #12941:
URL: https://github.com/apache/datafusion/pull/12941#issuecomment-2417001979

   
   I verified that before this PR this query fails like this:
   
   ```sql
   > create table foo as values (1), (2);
   0 row(s) fetched.
   
   > select distinct on (column1) * from foo;
   Optimizer rule 'replace_distinct_aggregate' failed
   caused by
   replace_distinct_aggregate
   caused by
   Internal error: Failed due to a difference in schemas, original schema: 
DFSchema { inner: Schema { fields: [Field { name: "column1", data_type: Int64, 
nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: 
{} }, field_qualifiers: [Some(Bare { table: "foo" })], functional_dependencies: 
FunctionalDependencies { deps: [] } }, new schema: DFSchema { inner: Schema { 
fields: [Field { name: "column1", data_type: Null, nullable: true, dict_id: 0, 
dict_is_ordered: false, metadata: {} }], metadata: {} }, field_qualifiers: 
[Some(Bare { table: "foo" })], functional_dependencies: FunctionalDependencies 
{ deps: [] } }.
   This was likely caused by a bug in DataFusion's code and we would welcome 
that you file an bug report in our issue tracker
   ```
   And after this PR it works
   
   ```
   DataFusion CLI v42.0.0
   > create table foo as values (1), (2);
   0 row(s) fetched.
   Elapsed 0.024 seconds.
   
   > select distinct on (column1) * from foo;
   +---------+
   | column1 |
   +---------+
   | 1       |
   | 2       |
   +---------+
   2 row(s) fetched.
   Elapsed 0.026 seconds.
   ```
   
   > How about adding an SQL test in 
datafusion/sqllogictest/test_files/distinct_on.slt?
   
   this is an excellent call @goldmedal  -- I will make a follow on PR


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