Skip to content

Commit

Permalink
Add test for subquery name clash bug (#98)
Browse files Browse the repository at this point in the history
* Add test for subquery clashes

* Fix =? handling

* Little cleanups
  • Loading branch information
tsmacdonald authored Sep 6, 2024
1 parent ba695c5 commit bc2b663
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
clojure.core/prn {:message "Use clojure.tools.logging instead."}
clojure.pprint/pprint {:message "Use clojure.tools.logging instead."}}

:unresolved-symbol
{:exclude
[(clojure.test/is [=? malli=])]}

:refer
{:level :warning
:exclude [clojure.test
Expand Down
4 changes: 1 addition & 3 deletions test/macaw/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[macaw.core :as m]
[macaw.test.util :refer [ws=]]
[macaw.walk :as mw]
[mb.hawk.assert-exprs.approximately-equal])
[mb.hawk.assert-exprs])
(:import
(clojure.lang ExceptionInfo)
(net.sf.jsqlparser.schema Table)))
Expand Down Expand Up @@ -355,8 +355,6 @@ from foo")
(is (= #{{:table "foo"}}
(table-wcs "SELECT f.* FROM orders o JOIN foo f ON orders.id = foo.order_id"))))

;; TODO Fix kondo linting of =? (strangely enough I don't need this locally)
^:clj-kondo/ignore
(deftest context-test
(testing "Sub-select with outer wildcard"
;; TODO we should test the source and result columns too
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{:tables #{{:table "addresses"}
{:table "customers"}
{:table "orders"}}
:source-columns #{{:table "addresses" :column "country"}
{:table "addresses" :column "organization_id"}
{:table "addresses" :column "region"}
{:table "customers" :column "country"}
{:table "customers" :column "id"}
{:table "customers" :column "state"}
{:table "orders" :column "customer_id"}
{:table "orders" :column "organization_id"}}

;; In the same general category as https://github.com/metabase/metabase/issues/42586
:overrides
{:source-columns #{{:table "addresses" :column "country"}
{:table "addresses" :column "organization_id"}
{:table "addresses" :column "region"}
{:table "addresses" :column "state"} ;; This one is spurious
{:table "customers" :column "country"}
{:table "customers" :column "id"}
{:table "customers" :column "state"}
{:table "orders" :column "customer_id"}
{:table "orders" :column "organization_id"}}}}
10 changes: 10 additions & 0 deletions test/resources/acceptance/compound__subselect_table_masking.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT
CASE WHEN Addr.country = 'US' THEN Addr.state ELSE 'ex-US' END AS state
FROM (
SELECT DISTINCT
coalesce(Cust.state, Addr.region) AS state,
coalesce(Cust.country, Addr.country) AS country
FROM orders
LEFT JOIN addresses AS Addr ON orders.organization_id = Addr.organization_id
LEFT JOIN customers AS Cust ON orders.customer_id = Cust.id
) AS Addr

0 comments on commit bc2b663

Please sign in to comment.