Skip to content

Commit f758fa1

Browse files
committed
more testing
1 parent 4526e2b commit f758fa1

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/macaw/scope_experiments.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@
7474
#{table-name}
7575
(scope->nested-tables scope-id))])))))
7676

77+
(defn- ->vec [x]
78+
(mapv x [:schema :table :column]))
79+
7780
(defn fields-to-search
7881
"Get a set of qualified columns. Where the qualification was uncertain, we enumerate all possibilities"
7982
[f->ts]
80-
(into (sorted-set)
83+
(into (sorted-set-by (fn [x y] (compare (->vec x) (->vec y))))
8184
(mapcat (fn [[[_ column-name] table-names]]
82-
(map #(vector :table % :column column-name) table-names)))
83-
85+
(map #(hash-map :table % :column column-name) table-names)))
8486
f->ts))

test/macaw/scope_experiments.clj renamed to test/macaw/scope_experiments_test.clj

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns macaw.scope-experiments
1+
(ns macaw.scope-experiments-test
22
(:require
33
[clojure.test :refer :all]
44
[macaw.scope-experiments :as mse]))
@@ -57,13 +57,29 @@
5757
;; like source-columns, but understands scope
5858
(is (= (mse/fields-to-search
5959
(mse/fields->tables-in-scope "select x from t, u, v left join w on w.a = v.a where t.b = u.b and u.c = v.c limit 3"))
60-
#{[:table "t" :column "b"]
61-
[:table "t" :column "x"]
62-
[:table "u" :column "b"]
63-
[:table "u" :column "c"]
64-
[:table "u" :column "x"]
65-
[:table "v" :column "a"]
66-
[:table "v" :column "c"]
67-
[:table "v" :column "x"]
68-
[:table "w" :column "a"]
69-
[:table "w" :column "x"]})))
60+
#{{:table "t" :column "b"}
61+
{:table "t" :column "x"}
62+
{:table "u" :column "b"}
63+
{:table "u" :column "c"}
64+
{:table "u" :column "x"}
65+
{:table "v" :column "a"}
66+
{:table "v" :column "c"}
67+
{:table "v" :column "x"}
68+
{:table "w" :column "a"}
69+
{:table "w" :column "x"}}))
70+
71+
(is (= (mse/fields-to-search
72+
(mse/fields->tables-in-scope
73+
"with b as (select x, * from a),
74+
c as (select y, * from b)
75+
select z from c;"))
76+
;; getting there - needs to unwrap cte aliases to the tables that they come from
77+
#{{:table "a" :column "x"}
78+
{:table "b" :column "y"}
79+
{:table "c" :column "z"}}))
80+
81+
(is (= (mse/fields-to-search
82+
(mse/fields->tables-in-scope
83+
"select x, y, (select z from u) from t"))
84+
;; totally loses x and y :-(
85+
#{{:table "u" :column "z"}})))

0 commit comments

Comments
 (0)