Skip to content
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 SQL analysis using DataFusion structures #10938

Merged
merged 10 commits into from
Jun 18, 2024

Conversation

LorrensP-2158466
Copy link
Contributor

Which issue does this PR close?

Closes #10871 .

Rationale for this change

What changes are included in this PR?

Added an example of an SQL analysis where we count joins in a SQL query.

Are these changes tested?

Ran it on some other queries and the join counts where right.

Are there any user-facing changes?

No

@alamb
Copy link
Contributor

alamb commented Jun 17, 2024

Thank you @LorrensP-2158466 -- I am going to check this out later today

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @LorrensP-2158466 -- this looks great. I left some small suggestions but I think this is basically a great example.

Do you potentially have time to finish it up? Otherwise I can help do so too


//! This example shows how we can use the structures that DataFusion provide to perform
//! SQL Analysis.
//! We'll show how we can count the amount of join's in a query as well as how many
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

)?;
}

let query_88 = "datafusion/core/tests/tpc-ds/88.sql";
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very cool -- thank you

This example might actually be easier to understand if we inlined these queries below -- I can do it if you like -- so the example stands on its own

https://github.com/apache/datafusion/blob/main/datafusion/core/tests/tpc-ds/88.sql

datafusion-examples/examples/sql_analysis.rs Outdated Show resolved Hide resolved
datafusion-examples/examples/sql_analysis.rs Show resolved Hide resolved
@LorrensP-2158466
Copy link
Contributor Author

It's currently midnight where I live, so I can do it tomorrow. If you have free time you're free to make these changes.
Thanks for the reply and help!

LorrensP-2158466 and others added 2 commits June 18, 2024 11:26
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
@alamb
Copy link
Contributor

alamb commented Jun 18, 2024

It's currently midnight where I live, so I can do it tomorrow. If you have free time you're free to make these changes. Thanks for the reply and help!

No worries! In general we operate asynchronously, so there is no need to an immediate response. Thank you for making the changes -- I am taking a second look now

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

This is amazing -- thank you so much @LorrensP-2158466

It is really neat to see how to use the TreeNode API from @peter-toth and others to write non trivial analyses that walk the tree.

I took the liberty of merging this branch up to main and fixing the Cargo.toml formatting, as well doing some small textual cleanups

I plan to merge it once the CI checks complete.

Again, thank you, this is so cool

@alamb alamb merged commit 5cb1917 into apache:main Jun 18, 2024
25 checks passed
@alamb
Copy link
Contributor

alamb commented Jun 18, 2024

Thanks again @LorrensP-2158466

@LorrensP-2158466
Copy link
Contributor Author

Glad I could help, it was a lot fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add example for writing an SQL analysis pass
2 participants