buraksenn commented on code in PR #20720:
URL: https://github.com/apache/datafusion/pull/20720#discussion_r2895761682
##########
datafusion/sql/src/select.rs:
##########
@@ -690,21 +694,70 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
self.plan_table_with_joins(input, planner_context)
}
_ => {
+ let extract_table_name =
+ |t: &TableWithJoins| -> Option<(String, Option<Span>)> {
+ let span =
Span::try_from_sqlparser_span(t.relation.span());
+ match &t.relation {
+ TableFactor::Table { alias: Some(a), .. } => {
+ let name =
+
self.ident_normalizer.normalize(a.name.clone());
+ Some((name, span))
+ }
+ TableFactor::Table {
+ name, alias: None, ..
+ } => {
+ let table_name = name
+ .0
+ .iter()
+ .filter_map(|p| p.as_ident())
+ .map(|id|
self.ident_normalizer.normalize(id.clone()))
+ .next_back()?;
+ Some((table_name, span))
+ }
+ _ => None,
+ }
+ };
+
+ let mut alias_spans: HashMap<String, Option<Span>> =
HashMap::new();
+
let mut from = from.into_iter();
+ let first = from.next().unwrap();
+
+ if let Some((name, span)) = extract_table_name(&first) {
+ alias_spans.entry(name).or_insert(span);
+ }
+
+ let mut left = LogicalPlanBuilder::from(
+ self.plan_table_with_joins(first, planner_context)?,
+ );
- let mut left = LogicalPlanBuilder::from({
- let input = from.next().unwrap();
- self.plan_table_with_joins(input, planner_context)?
- });
let old_outer_from_schema = {
let left_schema = Some(Arc::clone(left.schema()));
planner_context.set_outer_from_schema(left_schema)
};
for input in from {
- // Join `input` with the current result (`left`).
+ let current_name = extract_table_name(&input);
+
+ if let Some((ref name, ref span)) = current_name {
+ alias_spans.entry(name.clone()).or_insert(*span);
Review Comment:
Thanks I did not realize this. I've added two test cases that had error due
to this and with multiple tables. I think it should be ok now
--
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]