diff --git a/src/macaw/rewrite.clj b/src/macaw/rewrite.clj index 2ff7ba0..2746f22 100644 --- a/src/macaw/rewrite.clj +++ b/src/macaw/rewrite.clj @@ -84,8 +84,7 @@ (let [col (get known-columns column) name' (when col (or (get column-renames (select-keys col [:column :table :schema])) - (get column-renames (select-keys col [:column :table])) - (get column-renames (:column col))))] + (get column-renames (select-keys col [:column :table]))))] (when name' (vswap! updated-nodes conj column) (.setColumnName column name')))) diff --git a/test/macaw/core_test.clj b/test/macaw/core_test.clj index 11f0c25..2e0c8f2 100644 --- a/test/macaw/core_test.clj +++ b/test/macaw/core_test.clj @@ -217,10 +217,20 @@ (deftest replace-names-test (test-replacement "SELECT a.x, b.x, b.y FROM a, b;" {:tables {"a" "aa"} - :columns {{:table "a" :column "x"} "xx" - "y" "yy"}} + :columns {{:table "a" :column "x"} "xx"}} "SELECT aa.xx, b.x, b.yy FROM aa, b;") + (test-replacement + "SELECT SUM(public.orders.amount) AS s, + MAX(orders.amount) AS max, + MIN(amount) AS min + FROM public.orders" + {:columns {{:table "orders" :column "amount"} "total"}} + "SELECT SUM(public.orders.total) AS s, + MAX(orders.total) AS max, + MIN(total) AS min + FROM public.orders") + (test-replacement "SELECT *, boink , yoink AS oink