From bf4a51896782c3e4e716856ec1566397bac79272 Mon Sep 17 00:00:00 2001 From: Matthew Davidson Date: Mon, 8 Apr 2024 17:16:14 +0700 Subject: [PATCH] test: Add SELECT * EXCEPT tests --- test/inferenceql/query/plan_test.cljc | 3 ++- test/inferenceql/query/strict/parser_test.cljc | 3 ++- test/inferenceql/query/strict_test.cljc | 12 +++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/inferenceql/query/plan_test.cljc b/test/inferenceql/query/plan_test.cljc index 4ecc857..19cc6cb 100644 --- a/test/inferenceql/query/plan_test.cljc +++ b/test/inferenceql/query/plan_test.cljc @@ -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")) @@ -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")) @@ -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)}) diff --git a/test/inferenceql/query/strict/parser_test.cljc b/test/inferenceql/query/strict/parser_test.cljc index fcb594d..9226d73 100644 --- a/test/inferenceql/query/strict/parser_test.cljc +++ b/test/inferenceql/query/strict/parser_test.cljc @@ -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)) diff --git a/test/inferenceql/query/strict_test.cljc b/test/inferenceql/query/strict_test.cljc index 6c9ad19..94819ca 100644 --- a/test/inferenceql/query/strict_test.cljc +++ b/test/inferenceql/query/strict_test.cljc @@ -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] @@ -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 ", "))