How to extract pairs of tables such that they are joined? #4517
Replies: 2 comments 2 replies
-
I'd suggest taking a look at these two docs, you may find useful patterns:
There's quite a bit of info in this post and it's not very clear which part you're stuck on exactly. Can you reduce it to a simple example, demonstrating the initial & expected state of things? That way it'll be easier to point you to places to look. |
Beta Was this translation helpful? Give feedback.
2 replies
-
It is unclear to me why this discussion has been closed. The original question has not been answered and the thread has not been abandoned for any substantial length of time. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to write a function which takes a string of a SQL query and returns a Networkx graph where the nodes are the table names and the edges connect two table names where they are joined on one or more columns. I want to make sure that it works for simple queries, queries with one or more CTEs, and queries with one or more nested queries.
I attempted this something like 11 months ago so my memory is a little foggy. Below is a script I extracted from the Jupyter notebook I wrote at that time to try to exract the pairs. I remember getting stuck on trying to get all the tables that a given table is joined to. The script accesses one of a collection of example sql scripts. The script currently accesses example 13.
I 'feel' like this is something that should be easy to extract if I knew the underlying implementation better. Of course, eventually, I will resort to carefully doing static and dynamic analysis of SQLGlot if it comes to it, but I am hoping not to get into that.
It isn't evident to me how to proceed from AST Introspection which appears to cover only a minimal example. I think more topical guides in the docs would be useful; especially if they followed Diátaxis.
Suggestions and feedback would be appreciated. 🙏
I should add, I did ask on Slack way back at the time that I was first looking at this. I recall only getting some partial information, perhaps how to get table names. However, I cannot see those messages anymore.
Beta Was this translation helpful? Give feedback.
All reactions