Better way of "find_all" to a certain depth #5522
Closed
big-c-note
started this conversation in
General
Replies: 1 comment 1 reply
-
Hey @big-c-note, based on your CTE & Select example, it appears that you may find the scope module useful. There are some examples in the AST primer you can look into. If that doesn't fully cover your use case, I'd consider modifying the existing DFS logic to incorporate a depth counter. I don't think we're interested in merging this right now, as there's no concrete use case to justify the additional complexity. Feel free to reach out in our Slack, which is more active compared to GitHub's "Discussions". |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks for the library, it's been awesome working with it. Wanted to pick someone's brain on a better way to do this
I had a need to find all up to a certain depth. A good example is when I need to get all columns that are selected in an
exp.Select
. So I have a node of typeexp.CTE
orexp.Select
and I need to get the nextexp.Column
s. It's a BFS traversal, essentially I could think of two ways to do this.find_all
, and return all found of a certain type up to that depth.exp.Column
or a variable type, then return all nodes of that type at that depth.Curious if you have interest in either of these, and I can submit a PR. Otherwise, is there a better way to do this with the library by passing something to
prune
inwalk
. Maybe that is the most elegant approach. Thank you in advanceBeta Was this translation helpful? Give feedback.
All reactions