Skip to content

Apache DataFusion SQL Query Engine

normalize subquery alias (#2359)

Andy Groved5500ca0d0d3
diff --git a/datafusion/core/src/sql/planner.rs b/datafusion/core/src/sql/planner.rs
index e693d7b209..d70c1da7c7 100644
--- a/datafusion/core/src/sql/planner.rs
+++ b/datafusion/core/src/sql/planner.rs
@@ -716,7 +716,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
.fields()
.iter()
.map(|field| col(field.name())),
- alias.as_ref().map(|a| a.name.value.to_string()),
+ alias.as_ref().map(|a| normalize_ident(a.name.clone())),
)?,
alias,
)
diff --git a/datafusion/core/tests/sql/projection.rs b/datafusion/core/tests/sql/projection.rs
index d717698e45..fb3919ed76 100644
--- a/datafusion/core/tests/sql/projection.rs
+++ b/datafusion/core/tests/sql/projection.rs
@@ -134,6 +134,24 @@ async fn parallel_projection() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn subquery_alias_case_insensitive() -> Result<()> {
+ let partition_count = 1;
+ let results =
+ partitioned_csv::execute("SELECT V1.c1, v1.C2 FROM (SELECT test.C1, TEST.c2 FROM test) V1 ORDER BY v1.c1, V1.C2 LIMIT 1", partition_count).await?;
+
+ let expected = vec![
+ "+----+----+",
+ "| c1 | c2 |",
+ "+----+----+",
+ "| 0 | 1 |",
+ "+----+----+",
+ ];
+ assert_batches_sorted_eq!(expected, &results);
+
+ Ok(())
+}
+
#[tokio::test]
async fn projection_on_table_scan() -> Result<()> {
let tmp_dir = TempDir::new()?;