You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/07 10:29:07 UTC

[GitHub] [arrow-datafusion] mkmik commented on issue #2867: Error parsing valid SQL with aliases

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: github-unsubscribe@arrow.apache.org

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