jonahgao commented on code in PR #14102: URL: https://github.com/apache/datafusion/pull/14102#discussion_r1912755777
########## datafusion/expr/src/utils.rs: ########## @@ -379,14 +379,12 @@ fn get_exprs_except_skipped( } } -/// Resolves an `Expr::Wildcard` to a collection of `Expr::Column`'s. -pub fn expand_wildcard( - schema: &DFSchema, - plan: &LogicalPlan, - wildcard_options: Option<&WildcardOptions>, -) -> Result<Vec<Expr>> { +/// For each column specified in the USING JOIN condition, the JOIN plan outputs it twice +/// (once for each join side), but an unqualified wildcard should include it only once. +/// This function returns the columns that should be excluded. +fn exclude_using_columns(plan: &LogicalPlan) -> Result<HashSet<Column>> { let using_columns = plan.using_columns()?; Review Comment: [using_columns()](https://github.com/apache/datafusion/blob/f9cc3325cdb5891b7566a6f3503c1f7ac6ad51e0/datafusion/expr/src/logical_plan/plan.rs#L485) finds join condition columns by traversing the plan tree. This manner might be unsafe as it could incorrectly find columns that are not relevant to the current SQL context. For example, the result of the query below is different from other databases. ```sql create table t(a int); insert into t values(1),(2),(3); select * from (select t.a+2 as a from t join t t2 using(a)) as t2; ``` -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org