This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new cb2cbbefc Allow subqueries without aliases (#2418)
cb2cbbefc is described below
commit cb2cbbefcafdfff8989f608b93c71cb03c0188f6
Author: Andy Grove <[email protected]>
AuthorDate: Mon May 2 13:46:27 2022 -0600
Allow subqueries without aliases (#2418)
---
datafusion/core/src/sql/planner.rs | 6 ----
datafusion/core/tests/sql/select.rs | 55 +++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/datafusion/core/src/sql/planner.rs
b/datafusion/core/src/sql/planner.rs
index ca8cb23bc..cf974c0d1 100644
--- a/datafusion/core/src/sql/planner.rs
+++ b/datafusion/core/src/sql/planner.rs
@@ -712,12 +712,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
subquery, alias, ..
} => {
let normalized_alias = alias.as_ref().map(|a|
normalize_ident(&a.name));
- // if alias is None, return Err
- if normalized_alias.is_none() {
- return Err(DataFusionError::Plan(
- "subquery in FROM must have an alias".to_string(),
- ));
- }
let logical_plan = self.query_to_plan_with_alias(
*subquery,
normalized_alias.clone(),
diff --git a/datafusion/core/tests/sql/select.rs
b/datafusion/core/tests/sql/select.rs
index 43105836b..747a9e05a 100644
--- a/datafusion/core/tests/sql/select.rs
+++ b/datafusion/core/tests/sql/select.rs
@@ -968,6 +968,61 @@ async fn csv_select_nested() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn csv_select_nested_without_aliases() -> Result<()> {
+ let ctx = SessionContext::new();
+ register_aggregate_csv(&ctx).await?;
+ let sql = "SELECT o1, o2, c3
+ FROM (
+ SELECT c1 AS o1, c2 + 1 AS o2, c3
+ FROM (
+ SELECT c1, c2, c3, c4
+ FROM aggregate_test_100
+ WHERE c1 = 'a' AND c2 >= 4
+ ORDER BY c2 ASC, c3 ASC
+ )
+ )";
+ let actual = execute_to_batches(&ctx, sql).await;
+ let expected = vec![
+ "+----+----+------+",
+ "| o1 | o2 | c3 |",
+ "+----+----+------+",
+ "| a | 5 | -101 |",
+ "| a | 5 | -54 |",
+ "| a | 5 | -38 |",
+ "| a | 5 | 65 |",
+ "| a | 6 | -101 |",
+ "| a | 6 | -31 |",
+ "| a | 6 | 36 |",
+ "+----+----+------+",
+ ];
+ assert_batches_eq!(expected, &actual);
+ Ok(())
+}
+
+#[tokio::test]
+async fn csv_join_unaliased_subqueries() -> Result<()> {
+ let ctx = SessionContext::new();
+ register_aggregate_csv(&ctx).await?;
+ let sql = "SELECT o1, o2, c3, p1, p2, p3 FROM \
+ (SELECT c1 AS o1, c2 + 1 AS o2, c3 FROM aggregate_test_100), \
+ (SELECT c1 AS p1, c2 - 1 AS p2, c3 AS p3 FROM aggregate_test_100)
LIMIT 5";
+ let actual = execute_to_batches(&ctx, sql).await;
+ let expected = vec![
+ "+----+----+----+----+----+-----+",
+ "| o1 | o2 | c3 | p1 | p2 | p3 |",
+ "+----+----+----+----+----+-----+",
+ "| c | 3 | 1 | c | 1 | 1 |",
+ "| c | 3 | 1 | d | 4 | -40 |",
+ "| c | 3 | 1 | b | 0 | 29 |",
+ "| c | 3 | 1 | a | 0 | -85 |",
+ "| c | 3 | 1 | b | 4 | -82 |",
+ "+----+----+----+----+----+-----+",
+ ];
+ assert_batches_eq!(expected, &actual);
+ Ok(())
+}
+
#[tokio::test]
async fn parallel_query_with_filter() -> Result<()> {
let tmp_dir = TempDir::new()?;