Skip to content

Commit

Permalink
Back to atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmacdonald committed Feb 20, 2024
1 parent 18c5e0d commit 9af463e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions java/com/metabase/macaw/ASTWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@
import net.sf.jsqlparser.statement.upsert.Upsert;

/**
* Walks the AST, using JSqlParser's `visit()` methods. Each `visit()` method additionally calls an applicable callback method provided in the `callbacks` map.
* Supported callbacks have a corresponding key string (see below).
* Walks the AST, using JSqlParser's `visit()` methods. Each `visit()` method additionally calls an applicable callback
* method provided in the `callbacks` map. Supported callbacks have a corresponding key string (see below).
*
* Why this class? Why the callbacks?
*
* Clojure is not good at working with Java Visitors. They require over<em>riding</em> various over<em>loaded</em>
* Clojure is not good at working with Java visitors. They require over<em>riding</em> various over<em>loaded</em>
* methods and, in the case of walking a tree (exactly what we want to do here) we of course need to call `visit()`
* recursively.
*
Expand Down
14 changes: 7 additions & 7 deletions src/macaw/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
(defn query->components
"Given a parsed query (i.e., a [subclass of] `Statement`) return a map with the `:tables` and `:columns` found within it.
(Specifically, it returns their fully-qualified names as strings, where 'fully-qualified' means 'as found in the query'.)"
(Specifically, it returns their fully-qualified names as strings, where 'fully-qualified' means 'as referred to in the query'; this function doesn't do additional inference work to find out a table's schema.)"
[^Statement parsed-query]
(let [column-names (transient #{})
table-names (transient #{})
(let [column-names (atom #{})
table-names (atom #{})
ast-walker (ASTWalker. {:column (fn [^Column column]
(conj! column-names (.getColumnName column)))
(swap! column-names conj (.getColumnName column)))
:table (fn [^Table table]
(conj! table-names (.getFullyQualifiedName table)))})]
(swap! table-names conj (.getFullyQualifiedName table)))})]
(.walk ast-walker parsed-query)
{:columns (persistent! column-names)
:tables (persistent! table-names)}))
{:columns @column-names
:tables @table-names}))

(defn parsed-query
"Main entry point: takes a string query and returns a `Statement` object that can be handled by the other functions."
Expand Down

0 comments on commit 9af463e

Please sign in to comment.