raghavyadav01 commented on code in PR #27767:
URL: https://github.com/apache/datafusion/pull/27767#discussion_r4713273645
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -2427,7 +2427,18 @@ pub fn wrap_projection_for_join_if_necessary(
.collect::<Vec<_>>();
let need_project = join_keys.iter().any(|key| !matches!(key,
Expr::Column(_)));
- let plan = if need_project {
+ let (plan, alias_join_keys) = if need_project {
Review Comment:
Could we alias every non column key here, like the Cast case above does for
#4478? `key.clone().alias(key.schema_name().to_string())` fixed the issue and
the new slt cases for me on main, without the normalizer.
##########
datafusion/sqllogictest/test_files/struct.slt:
##########
@@ -2092,3 +2092,32 @@ prod 10
statement ok
drop table leaf_merge_source;
+
+# Regression test for https://github.com/apache/datafusion/issues/27703
+# Join key is an expression over a struct field of an aliased table.
+statement ok
+create table join_leaf_a as select {f: 1} as s;
+
+statement ok
+create table join_leaf_b as select 2 as f, {g: 0} as s;
+
+query ?I?
+select * from join_leaf_a x join join_leaf_b on x.s['f'] + 1 = join_leaf_b.f;
+----
+{f: 1} 2 {g: 0}
+
+query ?I?
+select * from join_leaf_a x join join_leaf_b y on x.s['f'] + 1 = y.s['g'] + 2;
+----
+{f: 1} 2 {g: 0}
+
+query ?I?
+select * from (select s from join_leaf_a) x left join join_leaf_b on
cast(x.s['f'] as bigint) + 1 = join_leaf_b.f;
Review Comment:
The cast here is inside `+ 1`, so this doesn't hit the Cast alias path and
repeats the first query. Should the cast be the whole key?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]