Skip to content

Commit

Permalink
more and better tests for renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
piranha committed May 16, 2024
1 parent 01be694 commit 724ea2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/macaw/rewrite.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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'))))
Expand Down
14 changes: 12 additions & 2 deletions test/macaw/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 724ea2e

Please sign in to comment.