Skip to content

Replace println! with assert! if possible in DataFusion examples #11237

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
24 changes: 14 additions & 10 deletions datafusion-examples/examples/rewrite_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,32 @@ pub fn main() -> Result<()> {
let context_provider = MyContextProvider::default();
let sql_to_rel = SqlToRel::new(&context_provider);
let logical_plan = sql_to_rel.sql_statement_to_plan(statements[0].clone())?;
println!(
"Unoptimized Logical Plan:\n\n{}\n",
logical_plan.display_indent()
assert_eq!(
logical_plan.display_indent().to_string(),
"Projection: person.name\
\n Filter: person.age BETWEEN Int64(21) AND Int64(32)\
\n TableScan: person"
);

// run the analyzer with our custom rule
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(), |_, _| {})?;
println!(
"Analyzed Logical Plan:\n\n{}\n",
analyzed_plan.display_indent()
assert_eq!(
analyzed_plan.display_indent().to_string(),
"Projection: person.name, person.age\
\n Filter: person.age BETWEEN Int64(21) AND Int64(32)\
\n TableScan: person"
);

// then run the optimizer with our custom rule
let optimizer = Optimizer::with_rules(vec![Arc::new(MyOptimizerRule {})]);
let optimized_plan = optimizer.optimize(analyzed_plan, &config, observe)?;
println!(
"Optimized Logical Plan:\n\n{}\n",
optimized_plan.display_indent()
);
assert_eq!(
optimized_plan.display_indent().to_string(),
"TableScan: person projection=[name], full_filters=[person.age >= UInt8(21), person.age <= UInt8(32)]"
);

Ok(())
}
Expand Down
8 changes: 5 additions & 3 deletions datafusion-examples/examples/sql_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ from
// We can create a LogicalPlan from a SQL query like this
let logical_plan = ctx.sql(tpcds_query_88).await?.into_optimized_plan()?;

println!(
"Optimized Logical Plan:\n\n{}\n",
logical_plan.display_indent()
assert_eq!(
logical_plan.display_indent().to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

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

this actual plan is quite a bit more complicated than shown here

"Projection: person.name\
\n Filter: person.age BETWEEN Int64(21) AND Int64(32)\
\n TableScan: person"
);
// we can get the total count (query 88 has 31 joins: 7 CROSS joins and 24 INNER joins => 40 input relations)
let total_join_count = total_join_count(&logical_plan);
Expand Down
Loading