diff --git a/datafusion/core/tests/sql/joins.rs b/datafusion/core/tests/sql/joins.rs index d1632277a30bf..185084cdbfe54 100644 --- a/datafusion/core/tests/sql/joins.rs +++ b/datafusion/core/tests/sql/joins.rs @@ -897,6 +897,24 @@ async fn inner_join_qualified_names() -> Result<()> { Ok(()) } +#[tokio::test] +async fn nestedjoin_with_alias() -> Result<()> { + // repro case for https://github.com/apache/arrow-datafusion/issues/2867 + let sql = "select * from ((select 1 as a, 2 as b) c INNER JOIN (select 1 as a, 3 as d) e on c.a = e.a) f;"; + let expected = vec![ + "+---+---+---+---+", + "| a | b | c | d |", + "+----+--+---+---|", + "| 1 | 2 | 1 | 3 |", + "+---+---+---+---+", + ]; + let ctx = SessionContext::new(); + let actual = execute_to_batches(&ctx, sql).await; + assert_batches_eq!(expected, &actual); + + Ok(()) +} + #[tokio::test] async fn issue_3002() -> Result<()> { // repro case for https://github.com/apache/arrow-datafusion/issues/3002