This is an automated email from the ASF dual-hosted git repository.
dheres pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/master by this push:
new 91af820 support table alias in join clause (#547)
91af820 is described below
commit 91af8203faa80e959e30a6350b1486c9ddc25247
Author: QP Hou <[email protected]>
AuthorDate: Mon Jun 14 00:02:39 2021 -0700
support table alias in join clause (#547)
* support table alias in join clause
* Update datafusion/src/sql/planner.rs
Co-authored-by: Andrew Lamb <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
---
datafusion/src/sql/planner.rs | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/datafusion/src/sql/planner.rs b/datafusion/src/sql/planner.rs
index 7e7462e..e860bd7 100644
--- a/datafusion/src/sql/planner.rs
+++ b/datafusion/src/sql/planner.rs
@@ -424,7 +424,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
ctes: &mut HashMap<String, LogicalPlan>,
) -> Result<LogicalPlan> {
match relation {
- TableFactor::Table { name, .. } => {
+ TableFactor::Table { name, alias, .. } => {
let table_name = name.to_string();
let cte = ctes.get(&table_name);
match (
@@ -432,10 +432,17 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
self.schema_provider.get_table_provider(name.try_into()?),
) {
(Some(cte_plan), _) => Ok(cte_plan.clone()),
- (_, Some(provider)) => {
- LogicalPlanBuilder::scan(&table_name, provider,
None)?.build()
- }
- (_, None) => Err(DataFusionError::Plan(format!(
+ (_, Some(provider)) => LogicalPlanBuilder::scan(
+ // take alias into account to support `JOIN table1 as
table2`
+ alias
+ .as_ref()
+ .map(|a| a.name.value.as_str())
+ .unwrap_or(&table_name),
+ provider,
+ None,
+ )?
+ .build(),
+ (None, None) => Err(DataFusionError::Plan(format!(
"Table or CTE with name '{}' not found",
name
))),