Skip to content

Commit

Permalink
Suppress columns coming from unknown tables (#97)
Browse files Browse the repository at this point in the history
* Add failing test for phantom field from generated table
* Suppress columns from unknown tables
  • Loading branch information
crisptrutski authored Sep 2, 2024
1 parent 923fd8a commit ba695c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/macaw/collect.clj
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,16 @@
:column))
unqualified)))

(defn- remove-phantom-table-columns
"If a column reference is qualified by a table that we don't know about, its probably
not a real field.
See the `:generate_series` fixture."
[table-map columns]
(let [known-table-name? (into #{} (map (comp :table :component val)) table-map)]
(filter (fn [{s :schema, t :table}]
(or (nil? t) (some? s) (known-table-name? t)))
columns)))

(defn- infer-table-schema [columns node]
(update node :component
#(let [{:keys [schema table] :as element} %]
Expand Down Expand Up @@ -220,6 +230,7 @@
source-columns (->> (map :component all-columns)
(remove-redundant-columns alias?)
(remove literal?)
(remove-phantom-table-columns table-map)
(into #{}
(comp (remove (comp pseudo-table-names :table))
(remove :internal?)
Expand Down
2 changes: 2 additions & 0 deletions test/resources/acceptance/generate_series.analysis.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{:tables []
:source-columns []}
2 changes: 2 additions & 0 deletions test/resources/acceptance/generate_series.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT t.day::date AS date
FROM generate_series(timestamp '2021-01-01', now(), interval '1 day') AS t(day)

0 comments on commit ba695c5

Please sign in to comment.