Skip to content

Commit

Permalink
test: Add SELECT * EXCEPT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KingMob committed Apr 8, 2024
1 parent 60b198b commit bf4a518
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion test/inferenceql/query/plan_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"SELECT * FROM data"
"SELECT x FROM data"
"SELECT (x) FROM data"
"SELECT * EXCEPT (foo, bar) FROM data"
"SELECT PROBABILITY OF VAR x = x UNDER model FROM data"
"SELECT (PROBABILITY OF VAR x = x UNDER model) FROM data"))

Expand All @@ -29,6 +30,7 @@
"SELECT * FROM data"
"SELECT x FROM data"
"SELECT (x) FROM data"
"SELECT * EXCEPT (foo, bar) FROM data"
"SELECT PROBABILITY OF x UNDER model FROM data"
"SELECT (PROBABILITY OF x UNDER model) FROM data"))

Expand Down Expand Up @@ -74,7 +76,6 @@
"SELECT * FROM data;" [{"x" 0}] ["x" "y"] ["x" "y"]
"SELECT x FROM data;" [{}] ["x"] ["x"]))


(testing "from aliasing"
(are [query in attrs expected] (= expected
(try (-> (eval query {"data" (relation/relation in :attrs attrs)})
Expand Down
3 changes: 2 additions & 1 deletion test/inferenceql/query/strict/parser_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"SELECT x AS y FROM data"
"SELECT (x) FROM data"
"SELECT (x) AS y FROM data"
"SELECT avg(x) FROM data"))
"SELECT avg(x) FROM data"
"SELECT * EXCEPT (foo, bar) FROM data"))

(deftest select-invalid
(are [s] (insta/failure? (parser/parse s))
Expand Down
12 changes: 11 additions & 1 deletion test/inferenceql/query/strict_test.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns inferenceql.query.strict-test
(:refer-clojure :exclude [alter])
#?(:clj (:import [clojure.lang ExceptionInfo]))
(:require [clojure.string :as string]
(:require [clojure.set :as set]
[clojure.string :as string]
[clojure.test :as test :refer [are deftest is testing]]
[clojure.test.check.clojure-test :refer [defspec]]
[clojure.test.check.generators :as gen]
Expand Down Expand Up @@ -109,6 +110,15 @@
(let [results (q "SELECT * FROM data" table)]
(is (= results table)))))

(defspec select-star-except
(prop/for-all [[table ks] gen-table-col-subset]
(let [kset (set ks)
col-list (->> ks #_ (map name) (string/join ", "))
results (q (str "SELECT * EXCEPT (" col-list ") FROM data") table)]
(is (every? (every-pred #(empty? (select-keys % ks))
#(empty? (set/intersection kset (set (keys %)))))
results)))))

(defspec select-col
(prop/for-all [[table ks] gen-table-col-subset]
(let [cols (->> ks (map name) (string/join ", "))
Expand Down

0 comments on commit bf4a518

Please sign in to comment.