Skip to content

Commit 40b877f

Browse files
committed
Improve the logic
1 parent ade4b38 commit 40b877f

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/binder/delete.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,8 @@ impl<T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'_, '_, T, A>
4040
let mut plan = TableScanOperator::build(table_name.clone(), table, true);
4141

4242
if let Some(alias_idents) = alias_idents {
43-
plan = self.bind_alias(
44-
plan,
45-
alias_idents,
46-
table_alias.unwrap(),
47-
Some(table_name.clone()),
48-
)?;
43+
plan =
44+
self.bind_alias(plan, alias_idents, table_alias.unwrap(), table_name.clone())?;
4945
}
5046

5147
if let Some(predicate) = selection {

src/binder/select.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,12 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
417417
}
418418
let table_alias = Arc::new(name.value.to_lowercase());
419419

420-
plan = self.bind_alias(plan, alias_column, table_alias, tables.pop())?;
420+
plan = self.bind_alias(
421+
plan,
422+
alias_column,
423+
table_alias,
424+
tables.pop().unwrap_or(Arc::new("_temp_table_".to_string())),
425+
)?;
421426
}
422427
plan
423428
}
@@ -439,7 +444,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
439444
plan,
440445
alias_column,
441446
table_alias.clone().unwrap(),
442-
Some(table_name.clone()),
447+
table_name.clone(),
443448
)?;
444449
}
445450

@@ -462,7 +467,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
462467
mut plan: LogicalPlan,
463468
alias_column: &[Ident],
464469
table_alias: TableName,
465-
table_name: Option<TableName>,
470+
table_name: TableName,
466471
) -> Result<LogicalPlan, DatabaseError> {
467472
let input_schema = plan.output_schema();
468473
if !alias_column.is_empty() && alias_column.len() != input_schema.len() {
@@ -505,9 +510,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
505510
);
506511
alias_exprs.push(alias_column_expr);
507512
}
508-
if let Some(table_name) = table_name {
509-
self.context.add_table_alias(table_alias, table_name);
510-
}
513+
self.context.add_table_alias(table_alias, table_name);
511514
self.bind_project(plan, alias_exprs)
512515
}
513516

@@ -537,7 +540,7 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
537540
};
538541

539542
if let Some(idents) = alias_idents {
540-
plan = self.bind_alias(plan, idents, table_alias.unwrap(), Some(table_name.clone()))?;
543+
plan = self.bind_alias(plan, idents, table_alias.unwrap(), table_name.clone())?;
541544
}
542545
Ok(plan)
543546
}

0 commit comments

Comments
 (0)