Skip to content

Commit 029c46a

Browse files
committed
fix: Don't try to extract relation from subquery column alias
1 parent ba12729 commit 029c46a

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

datafusion/core/src/sql/planner.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
821821
(
822822
project_with_alias(
823823
logical_plan.clone(),
824-
logical_plan
825-
.schema()
826-
.fields()
827-
.iter()
828-
.map(|field| col(field.name())),
824+
logical_plan.schema().fields().iter().map(|field| {
825+
Expr::Column(Column {
826+
relation: None,
827+
name: field.name().clone(),
828+
})
829+
}),
829830
alias.as_ref().map(|a| a.name.value.to_string()),
830831
)?,
831832
alias,
@@ -2971,6 +2972,19 @@ mod tests {
29712972
quick_test(sql, expected);
29722973
}
29732974

2975+
#[test]
2976+
fn select_nested_with_dotted_columns() {
2977+
let sql = "SELECT \"a.b\"
2978+
FROM (
2979+
SELECT 1 \"a.b\"
2980+
) AS t";
2981+
let expected = "Projection: #t.a.b\
2982+
\n Projection: #t.a.b, alias=t\
2983+
\n Projection: Int64(1) AS a.b, alias=t\
2984+
\n EmptyRelation";
2985+
quick_test(sql, expected);
2986+
}
2987+
29742988
#[test]
29752989
fn table_with_column_alias() {
29762990
let sql = "SELECT a, b, c

0 commit comments

Comments
 (0)