-
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 example for writing an SQL analysis pass #10871
Comments
I like the Join count analysis, I had to do this in my project (mentioned in #10808) in a really hacky way. We can have 2 sorts of counts:
I do have a question. |
Thank you @LorrensP-2158466 -- sorry for the delay . I have been traveling
I think in an example, we can use datafusion/datafusion-examples/examples/rewrite_expr.rs Lines 45 to 48 in 3773fb7
Normally the idea is to give a well documented example that shows the basic pattern that people can start with For this one, maybe you could show how to use let mut join_count = 0;
plan.apply(|child| {
if matches!(child, LogicalPlan::Join(_)) {
join_count += 1;
}
});
println!("Found {join_count} joins in the plan"); |
Thanks for the reply! That's exactly what I have made, I'll open up a PR later today or tomorrow. |
Is your feature request related to a problem or challenge?
We have many good examples in https://github.com/apache/datafusion/tree/3773fb7fb54419f889e7d18b73e9eb48069eb08e/datafusion-examples
However, we don't have anexample for writing some sort of SQL analysis -- for example what @LorrensP-2158466 mentions about finding cyclic joins in #10808 (comment).
However, I know of several users of DataFusion doing this (e.g. @sadboy and SDF)
Describe the solution you'd like
The ideal example I think would be to add a file to https://github.com/apache/datafusion/tree/3773fb7fb54419f889e7d18b73e9eb48069eb08e/datafusion-examples
sql_analysis.rs
Perhaps the example could show how to create LogicalPlans for several sql query texts, and then use DataFusion structures to do an analysis (like maybe join counts, or predicate analysis or something) would be really neat.
I think this would be very valuable
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: