mkmik commented on issue #4123:
URL:
https://github.com/apache/arrow-datafusion/issues/4123#issuecomment-1305555968
I tried to look at the parsed SQL AST to see if the bug was in the parser or
in the way the AST is interpreted (in order to know where to file the bug):
I ran:
```rust
use sqlparser::dialect::PostgreSqlDialect;
use sqlparser::parser::Parser;
fn main() {
let dialect = PostgreSqlDialect {}; // or AnsiDialect, or your own
dialect ...
let sql = "select a from (select a from (select 1 as a) as foo group by
a order by 1) as c";
let ast = Parser::parse_sql(&dialect, sql).unwrap();
println!("NUM: {:?}", ast[0]);
let sql = "select a from (select a from (select 1 as a) as foo group by
a order by a) as c";
let ast = Parser::parse_sql(&dialect, sql).unwrap();
println!("SYM: {:?}", ast[0]);
}
```
and got the following output:
```
NUM: Query(Query { with: None, body: Select(Select { distinct: false, top:
None, projection: [UnnamedExpr(Identifier(Ident { value: "a", quote_style: None
}))], into: None, from: [TableWithJoins { relation: Derived { lateral: false,
subquery: Query { with: None, body: Select(Select { distinct: false, top: None,
projection: [UnnamedExpr(Identifier(Ident { value: "a", quote_style: None }))],
into: None, from: [TableWithJoins { relation: Derived { lateral: false,
subquery: Query { with: None, body: Select(Select { distinct: false, top: None,
projection: [ExprWithAlias { expr: Value(Number("1", false)), alias: Ident {
value: "a", quote_style: None } }], into: None, from: [], lateral_views: [],
selection: None, group_by: [], cluster_by: [], distribute_by: [], sort_by: [],
having: None, qualify: None }), order_by: [], limit: None, offset: None, fetch:
None, lock: None }, alias: Some(TableAlias { name: Ident { value: "foo",
quote_style: None }, columns: [] }) }, joins: [] }], lateral_vie
ws: [], selection: None, group_by: [Identifier(Ident { value: "a",
quote_style: None })], cluster_by: [], distribute_by: [], sort_by: [], having:
None, qualify: None }), order_by: [OrderByExpr { expr: Value(Number("1",
false)), asc: None, nulls_first: None }], limit: None, offset: None, fetch:
None, lock: None }, alias: None }, joins: [] }], lateral_views: [], selection:
None, group_by: [], cluster_by: [], distribute_by: [], sort_by: [], having:
None, qualify: None }), order_by: [], limit: None, offset: None, fetch: None,
lock: None })
SYM: Query(Query { with: None, body: Select(Select { distinct: false, top:
None, projection: [UnnamedExpr(Identifier(Ident { value: "a", quote_style: None
}))], into: None, from: [TableWithJoins { relation: Derived { lateral: false,
subquery: Query { with: None, body: Select(Select { distinct: false, top: None,
projection: [UnnamedExpr(Identifier(Ident { value: "a", quote_style: None }))],
into: None, from: [TableWithJoins { relation: Derived { lateral: false,
subquery: Query { with: None, body: Select(Select { distinct: false, top: None,
projection: [ExprWithAlias { expr: Value(Number("1", false)), alias: Ident {
value: "a", quote_style: None } }], into: None, from: [], lateral_views: [],
selection: None, group_by: [], cluster_by: [], distribute_by: [], sort_by: [],
having: None, qualify: None }), order_by: [], limit: None, offset: None, fetch:
None, lock: None }, alias: Some(TableAlias { name: Ident { value: "foo",
quote_style: None }, columns: [] }) }, joins: [] }], lateral_vie
ws: [], selection: None, group_by: [Identifier(Ident { value: "a",
quote_style: None })], cluster_by: [], distribute_by: [], sort_by: [], having:
None, qualify: None }), order_by: [OrderByExpr { expr: Identifier(Ident {
value: "a", quote_style: None }), asc: None, nulls_first: None }], limit: None,
offset: None, fetch: None, lock: None }, alias: None }, joins: [] }],
lateral_views: [], selection: None, group_by: [], cluster_by: [],
distribute_by: [], sort_by: [], having: None, qualify: None }), order_by: [],
limit: None, offset: None, fetch: None, lock: None })
```
wdiff shows only a difference in the `OrderByExpr`:
```
OrderByExpr { expr: [-Value(Number("1", false)),-] {+Identifier(Ident {
value: "a", quote_style: None }),+} asc: None, nulls_first: None }
```
I think this shows that `sqlparser` is parsing the statement correctly and
that the bug is in datafusion.
--
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]