Skip to content

Commit 119f90f

Browse files
authored
remove redundant outer_query_schema (#4576)
1 parent 9a93398 commit 119f90f

File tree

1 file changed

+7
-27
lines changed

1 file changed

+7
-27
lines changed

datafusion/sql/src/planner.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -701,20 +701,17 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
701701
&self,
702702
mut from: Vec<TableWithJoins>,
703703
planner_context: &mut PlannerContext,
704-
outer_query_schema: Option<&DFSchema>,
705704
) -> Result<LogicalPlan> {
706705
match from.len() {
707706
0 => Ok(LogicalPlanBuilder::empty(true).build()?),
708707
1 => {
709708
let from = from.remove(0);
710-
self.plan_table_with_joins(from, planner_context, outer_query_schema)
709+
self.plan_table_with_joins(from, planner_context)
711710
}
712711
_ => {
713712
let plans = from
714713
.into_iter()
715-
.map(|t| {
716-
self.plan_table_with_joins(t, planner_context, outer_query_schema)
717-
})
714+
.map(|t| self.plan_table_with_joins(t, planner_context))
718715
.collect::<Result<Vec<_>>>()?;
719716
let mut left = plans[0].clone();
720717
for right in plans.iter().skip(1) {
@@ -729,16 +726,14 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
729726
&self,
730727
t: TableWithJoins,
731728
planner_context: &mut PlannerContext,
732-
outer_query_schema: Option<&DFSchema>,
733729
) -> Result<LogicalPlan> {
734730
// From clause may exist CTEs, we should separate them from global CTEs.
735731
// CTEs in from clause are allowed to be duplicated.
736732
// Such as `select * from (WITH source AS (select 1 as e) SELECT * FROM source) t1, (WITH source AS (select 1 as e) SELECT * FROM source) t2;` which is valid.
737733
// So always use original global CTEs to plan CTEs in from clause.
738734
// Btw, don't need to add CTEs in from to global CTEs.
739735
let origin_planner_context = planner_context.clone();
740-
let left =
741-
self.create_relation(t.relation, planner_context, outer_query_schema)?;
736+
let left = self.create_relation(t.relation, planner_context)?;
742737
match t.joins.len() {
743738
0 => {
744739
*planner_context = origin_planner_context;
@@ -751,16 +746,10 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
751746
left,
752747
joins.next().unwrap(), // length of joins > 0
753748
planner_context,
754-
outer_query_schema,
755749
)?;
756750
for join in joins {
757751
*planner_context = origin_planner_context.clone();
758-
left = self.parse_relation_join(
759-
left,
760-
join,
761-
planner_context,
762-
outer_query_schema,
763-
)?;
752+
left = self.parse_relation_join(left, join, planner_context)?;
764753
}
765754
*planner_context = origin_planner_context;
766755
Ok(left)
@@ -773,10 +762,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
773762
left: LogicalPlan,
774763
join: Join,
775764
planner_context: &mut PlannerContext,
776-
outer_query_schema: Option<&DFSchema>,
777765
) -> Result<LogicalPlan> {
778-
let right =
779-
self.create_relation(join.relation, planner_context, outer_query_schema)?;
766+
let right = self.create_relation(join.relation, planner_context)?;
780767
match join.join_operator {
781768
JoinOperator::LeftOuter(constraint) => {
782769
self.parse_join(left, right, constraint, JoinType::Left, planner_context)
@@ -914,7 +901,6 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
914901
&self,
915902
relation: TableFactor,
916903
planner_context: &mut PlannerContext,
917-
outer_query_schema: Option<&DFSchema>,
918904
) -> Result<LogicalPlan> {
919905
let (plan, alias) = match relation {
920906
TableFactor::Table { name, alias, .. } => {
@@ -946,11 +932,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
946932
table_with_joins,
947933
alias,
948934
} => (
949-
self.plan_table_with_joins(
950-
*table_with_joins,
951-
planner_context,
952-
outer_query_schema,
953-
)?,
935+
self.plan_table_with_joins(*table_with_joins, planner_context)?,
954936
alias,
955937
),
956938
// @todo Support TableFactory::TableFunction?
@@ -1095,9 +1077,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
10951077
}
10961078

10971079
// process `from` clause
1098-
let plan =
1099-
self.plan_from_tables(select.from, planner_context, outer_query_schema)?;
1100-
1080+
let plan = self.plan_from_tables(select.from, planner_context)?;
11011081
let empty_from = matches!(plan, LogicalPlan::EmptyRelation(_));
11021082
// build from schema for unqualifier column ambiguous check
11031083
// we should get only one field for unqualifier column from schema.

0 commit comments

Comments
 (0)