Add standalone example of using the SQL frontend#11088
Conversation
|
@andygrove or @jdye64 I wonder if you might have some time to review this PR as I think it is relevant to to your use of DataFusion |
|
I am working on getting the CI to run successfully on this PR, see #11173 |
|
🤔 this might also make https://github.com/apache/datafusion/blob/main/datafusion/sql/examples/sql.rs redundant |
| // The initial LogicalPlan is a mechanical translation from the parsed SQL | ||
| // and often can not run without the Analyzer passes. | ||
| // | ||
| // In this example, `person.age` is actually a different data type (Int32) |
There was a problem hiding this comment.
At the source schema data type defined as Uint8
| // (Int64). However, this plan is not as efficient as it could be, as it | ||
| // will require casting *each row* of the input to UInt64 before comparison | ||
| // to 21 and 32. To optimize this query's performance, it is better to cast | ||
| // the constants once at plan time to Int32. |
There was a problem hiding this comment.
I guess this should be to Uint8
mustafasrepo
left a comment
There was a problem hiding this comment.
Thanks @alamb for this PR.
| 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!( |
There was a problem hiding this comment.
maybe we can use assert! here to let the user know the expected output?
There was a problem hiding this comment.
that is a good idea -- I will do so (the existing examples are inconsistent with that).
| config.options(), | ||
| observe_analyzer, | ||
| )?; | ||
| println!( |
| // 4. Pushed the filter into the scan | ||
| let optimized_plan = | ||
| Optimizer::new().optimize(analyzed_plan, &config, observe_optimizer)?; | ||
| println!( |
Co-authored-by: Oleks V <comphead@users.noreply.github.com>
|
Thanks everyone for the comments and feedback |
* Add standalone example of using the SQL frontend * Disable debug info for all example jobs * Revert "Disable debug info for all example jobs" This reverts commit f222a10. * fix type * Int32 --> Int8 * Use assert_eq rather than println * Update datafusion-examples/examples/sql_frontend.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> --------- Co-authored-by: Oleks V <comphead@users.noreply.github.com>
* Add standalone example of using the SQL frontend * Disable debug info for all example jobs * Revert "Disable debug info for all example jobs" This reverts commit f222a10. * fix type * Int32 --> Int8 * Use assert_eq rather than println * Update datafusion-examples/examples/sql_frontend.rs Co-authored-by: Oleks V <comphead@users.noreply.github.com> --------- Co-authored-by: Oleks V <comphead@users.noreply.github.com>
Which issue does this PR close?
Part of #10855
Rationale for this change
The current
rewrite_expr.rsexample has three distinct examples:AnalyzerRuleOptimizerRuleEach I think should be its own example to make them easier to find and more full featured
What changes are included in this PR?
sql_frontend.rsAre these changes tested?
Yes by CI
Are there any user-facing changes?