Skip to content

Minor: Do not force analyzer to copy logical plans #10367

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion-examples/examples/rewrite_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn main() -> Result<()> {
let config = OptimizerContext::default().with_skip_failing_rules(false);
let analyzer = Analyzer::with_rules(vec![Arc::new(MyAnalyzerRule {})]);
let analyzed_plan =
analyzer.execute_and_check(&logical_plan, config.options(), |_, _| {})?;
analyzer.execute_and_check(logical_plan, config.options(), |_, _| {})?;
println!(
"Analyzed Logical Plan:\n\n{}\n",
analyzed_plan.display_indent()
Expand Down
10 changes: 6 additions & 4 deletions datafusion/core/src/execution/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,7 +1864,7 @@ impl SessionState {

// analyze & capture output of each rule
let analyzer_result = self.analyzer.execute_and_check(
e.plan.as_ref(),
e.plan.as_ref().clone(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where the cloning happens now (at the callsite)

self.options(),
|analyzed_plan, analyzer| {
let analyzer_name = analyzer.name().to_string();
Expand Down Expand Up @@ -1923,9 +1923,11 @@ impl SessionState {
logical_optimization_succeeded,
}))
} else {
let analyzed_plan =
self.analyzer
.execute_and_check(plan, self.options(), |_, _| {})?;
let analyzed_plan = self.analyzer.execute_and_check(
plan.clone(),
self.options(),
|_, _| {},
)?;
self.optimizer.optimize(analyzed_plan, self, |_, _| {})
}
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/core/tests/optimizer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let analyzer = Analyzer::new();
let optimizer = Optimizer::new();
// analyze and optimize the logical plan
let plan = analyzer.execute_and_check(&plan, config.options(), |_, _| {})?;
let plan = analyzer.execute_and_check(plan, config.options(), |_, _| {})?;
optimizer.optimize(plan, &config, |_, _| {})
}

Expand Down
16 changes: 8 additions & 8 deletions datafusion/optimizer/src/analyzer/count_wildcard_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ mod tests {
};
use std::sync::Arc;

fn assert_plan_eq(plan: &LogicalPlan, expected: &str) -> Result<()> {
fn assert_plan_eq(plan: LogicalPlan, expected: &str) -> Result<()> {
assert_analyzed_plan_eq_display_indent(
Arc::new(CountWildcardRule::new()),
plan,
Expand All @@ -132,7 +132,7 @@ mod tests {
\n Projection: COUNT(*) [COUNT(*):Int64;N]\
\n Aggregate: groupBy=[[test.b]], aggr=[[COUNT(Int64(1)) AS COUNT(*)]] [b:UInt32, COUNT(*):Int64;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}

#[test]
Expand All @@ -158,7 +158,7 @@ mod tests {
\n Aggregate: groupBy=[[]], aggr=[[COUNT(Int64(1)) AS COUNT(*)]] [COUNT(*):Int64;N]\
\n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]\
\n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}

#[test]
Expand All @@ -181,7 +181,7 @@ mod tests {
\n Aggregate: groupBy=[[]], aggr=[[COUNT(Int64(1)) AS COUNT(*)]] [COUNT(*):Int64;N]\
\n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]\
\n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}

#[test]
Expand Down Expand Up @@ -214,7 +214,7 @@ mod tests {
\n Filter: outer_ref(t1.a) = t2.a [a:UInt32, b:UInt32, c:UInt32]\
\n TableScan: t2 [a:UInt32, b:UInt32, c:UInt32]\
\n TableScan: t1 [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}
#[test]
fn test_count_wildcard_on_window() -> Result<()> {
Expand All @@ -239,7 +239,7 @@ mod tests {
let expected = "Projection: COUNT(Int64(1)) AS COUNT(*) [COUNT(*):Int64;N]\
\n WindowAggr: windowExpr=[[COUNT(Int64(1)) ORDER BY [test.a DESC NULLS FIRST] RANGE BETWEEN 6 PRECEDING AND 2 FOLLOWING AS COUNT(*) ORDER BY [test.a DESC NULLS FIRST] RANGE BETWEEN 6 PRECEDING AND 2 FOLLOWING]] [a:UInt32, b:UInt32, c:UInt32, COUNT(*) ORDER BY [test.a DESC NULLS FIRST] RANGE BETWEEN 6 PRECEDING AND 2 FOLLOWING:Int64;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}

#[test]
Expand All @@ -253,7 +253,7 @@ mod tests {
let expected = "Projection: COUNT(*) [COUNT(*):Int64;N]\
\n Aggregate: groupBy=[[]], aggr=[[COUNT(Int64(1)) AS COUNT(*)]] [COUNT(*):Int64;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}

#[test]
Expand All @@ -278,6 +278,6 @@ mod tests {
let expected = "Projection: COUNT(Int64(1)) AS COUNT(*) [COUNT(*):Int64;N]\
\n Aggregate: groupBy=[[]], aggr=[[MAX(COUNT(Int64(1))) AS MAX(COUNT(*))]] [MAX(COUNT(*)):Int64;N]\
\n TableScan: test [a:UInt32, b:UInt32, c:UInt32]";
assert_plan_eq(&plan, expected)
assert_plan_eq(plan, expected)
}
}
4 changes: 2 additions & 2 deletions datafusion/optimizer/src/analyzer/inline_table_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod tests {
\n Projection: y.a, y.b\
\n TableScan: y";

assert_analyzed_plan_eq(Arc::new(InlineTableScan::new()), &plan, expected)
assert_analyzed_plan_eq(Arc::new(InlineTableScan::new()), plan, expected)
}

#[test]
Expand All @@ -197,6 +197,6 @@ mod tests {
\n Projection: y.a\
\n TableScan: y";

assert_analyzed_plan_eq(Arc::new(InlineTableScan::new()), &plan, expected)
assert_analyzed_plan_eq(Arc::new(InlineTableScan::new()), plan, expected)
}
}
2 changes: 1 addition & 1 deletion datafusion/optimizer/src/analyzer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Analyzer {
/// do necessary check and fail the invalid plans
pub fn execute_and_check<F>(
&self,
plan: &LogicalPlan,
plan: LogicalPlan,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the API change and the clone is removed

config: &ConfigOptions,
mut observer: F,
) -> Result<LogicalPlan>
Expand Down
Loading
Loading