-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be to Uint8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch -- fixed in 6152fd6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can use assert!
here to let the user know the expected output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is a good idea -- I will do so (the existing examples are inconsistent with that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #11230
config.options(), | ||
observe_analyzer, | ||
)?; | ||
println!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert?
// 4. Pushed the filter into the scan | ||
let optimized_plan = | ||
Optimizer::new().optimize(analyzed_plan, &config, observe_optimizer)?; | ||
println!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm thanks @alamb
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 <[email protected]> --------- Co-authored-by: Oleks V <[email protected]>
* 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 <[email protected]> --------- Co-authored-by: Oleks V <[email protected]>
Which issue does this PR close?
Part of #10855
Rationale for this change
The current
rewrite_expr.rs
example has three distinct examples:AnalyzerRule
OptimizerRule
Each 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.rs
Are these changes tested?
Yes by CI
Are there any user-facing changes?