kysshsy commented on issue #18932: URL: https://github.com/apache/datafusion/issues/18932#issuecomment-3694599070
**Observation** - In `statement_to_plan`, a query like `WITH barbaz AS (...) SELECT * FROM "barbaz"` is initially collected as a `TableReference` (looks like a regular table) during `resolve_table_references`. - Because `visit_statement(statement, &mut visitor)` collects CTE refs and table refs *before* normalization, `barbaz` and `"barbaz"` are treated as different idents at that stage. **However** - During planning, `SqlToRel` re-resolves the reference: it first checks the CTE stack (`PlannerContext::get_cte`) and only falls back to the catalog/provider if the CTE isn’t found. In practice, the CTE is found there, so the query still succeeds. **Uncertainty** - It’s unclear whether emitting the quoted CTE name as a table ref in `resolve_table_references` is just a benign quirk or a bug (it triggers unnecessary catalog lookup and can fail with custom providers). I’m happy to submit a PR to align collection and CTE resolution so quoted CTE names aren’t emitted as table refs at all. -- 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]
