mkmik commented on issue #2867:
URL: 
https://github.com/apache/arrow-datafusion/issues/2867#issuecomment-1305401887

   I stumbled upon a bug that may be a simpler reproducer of this
   
   ```console
   ❯ select a from (select a from (select 1 as a) as foo group by 1 order by a) 
as c;
   SchemaError(FieldNotFound { field: Column { relation: Some("foo"), name: "a" 
}, valid_fields: Some([Column { relation: Some("c"), name: "a" }]) })
   ```
   
   ----
   
   Interestingly if I remove as c in the outer expression it works:
   
   ```console
   ❯ select a from (select a from (select 1 as a) as foo group by 1 order by a);
   +---+
   | a |
   +---+
   | 1 |
   +---+
   1 row in set. Query took 0.005 seconds.
   ```
   
   It's also interesting that using positional column references in the order 
by works:
   
   ```console
   ❯ select a from (select a from (select 1 as a) as foo group by 1 order by 1) 
as c;
   +---+
   | a |
   +---+
   | 1 |
   +---+
   1 row in set. Query took 0.005 seconds.
   ```
   
   Furthermore, the bug reproduces only if `group by a` and `order by a` are 
*both* present:
   
   ```console
   ❯ select a from (select a from (select 1 as a) as foo group by a) as c;
   +---+
   | a |
   +---+
   | 1 |
   +---+
   1 row in set. Query took 0.005 seconds.
   ❯ select a from (select a from (select 1 as a) as foo order by a) as c;
   +---+
   | a |
   +---+
   | 1 |
   +---+
   1 row in set. Query took 0.004 seconds.
   ```


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