Skip to content

Commit

Permalink
Fix reserved word acceptance test, and broken between one (#77)
Browse files Browse the repository at this point in the history
* Fix acceptance test for reserved keyword
* Add broken between query
  • Loading branch information
crisptrutski authored Jul 2, 2024
1 parent f5db94f commit 34a6ae5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
16 changes: 9 additions & 7 deletions test/macaw/acceptance_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
(def broken-queries
"The DANGER ZONE
This map gives a pattern in the exception message we expect to receive when trying to analyze the given fixture."
{:broken/between #"Encountered unexpected token: \"BETWEEN\""
:broken/reserved #"Encountered unexpected token: \"final\" \"FINAL\""})
{:broken/between #"Encountered unexpected token: \"BETWEEN\""
:broken/filter-where #"Encountered unexpected token: \"\(\""})

(defn- fixture-analysis [fixture]
(some-> fixture (ct/fixture->filename "acceptance" ".analysis.edn") io/resource slurp read-string))
Expand All @@ -39,14 +39,15 @@
sql (ct/query-fixture fixture)
expected-cs (fixture-analysis fixture)
renames (fixture-renames fixture)
expected-rw (fixture-rewritten fixture)]
expected-rw (fixture-rewritten fixture)
opts {:non-reserved-words [:final]}]
(if-let [expected-msg (broken-queries fixture)]
(testing (str prefix " analysis cannot be parsed")
(is (thrown-with-msg? Exception
expected-msg
(ct/components sql))))
(ct/components sql opts))))
(when-let [cs (testing (str prefix " analysis does not throw")
(is (ct/components sql)))]
(is (ct/components sql opts)))]
(doseq [[ck cv] (dissoc expected-cs :overrides)]
(testing (str prefix " analysis is correct: " (name ck))
(let [actual-cv (get-component cs ck)
Expand All @@ -57,7 +58,7 @@
(when renames
(let [broken? (:broken? renames)
rewritten (testing (str prefix " rewriting does not throw")
(is (m/replace-names sql (dissoc renames :broken?))))]
(is (m/replace-names sql (dissoc renames :broken?) opts)))]
(when expected-rw
(testing (str prefix " rewritten SQL is correct")
(if broken?
Expand Down Expand Up @@ -97,4 +98,5 @@
(ns-unmap *ns* sym)))

(test-fixture :compound/cte)
)

(test-fixture :broken/filter-where))
7 changes: 7 additions & 0 deletions test/resources/acceptance/broken__filter_where.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select
e.instance_id
, percentile_cont(0.75) within group (order by e.running_time) as p75_time
-- the parser trips up on the opening bracket in the `filter (where ...)` clause
, percentile_cont(0.75) within group (order by e.running_time) filter (where e.error = '') as p75_success_time
from execution e
group by 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:tables [{:table "employees"}]
:source-columns [{:table "employees", :column "id"}
{:table "employees", :column "manager_id"}
{:table "employees", :column "name"}]}
10 changes: 10 additions & 0 deletions test/resources/acceptance/compound__cte_recursive.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
WITH RECURSIVE hierarchy AS (
SELECT id, manager_id, name
FROM employees
WHERE manager_id IS NULL
UNION ALL
SELECT e.id, e.manager_id, e.name
FROM employees e
JOIN hierarchy eh ON e.manager_id = eh.id
)
SELECT * FROM hierarchy;

0 comments on commit 34a6ae5

Please sign in to comment.