Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Remove mbql5 experiments (#75127)

Riley Thompsondb9803f9b806
diff --git a/dev/src/dev/debug_qp/bulk_compile_cards.clj b/dev/src/dev/debug_qp/bulk_compile_cards.clj
new file mode 100644
index 00000000000..8dd19aa05ee
--- /dev/null
+++ b/dev/src/dev/debug_qp/bulk_compile_cards.clj
@@ -0,0 +1,181 @@
+(ns dev.debug-qp.bulk-compile-cards
+ (:require
+ [clojure.java.io :as io]
+ [clojure.java.shell :as shell]
+ [clojure.string :as str]
+ [metabase.driver.sql.util :as sql.u]
+ [metabase.query-processor.compile :as qp.compile]
+ [metabase.util.json :as json]
+ [toucan2.core :as t2])
+ (:import
+ (java.util.concurrent Executors Callable)))
+
+(set! *warn-on-reflection* true)
+
+(defn- get-card-ids [engine limit]
+ (t2/query {:select [:rc.id :rc.database_id]
+ :from [[:report_card :rc]]
+ :join [[:metabase_database :md] [:= :rc.database_id :md.id]]
+ :where [:and [:= :md.engine engine] [:not= :rc.query_type "native"]]
+ :order-by [[:md.id :asc] [:rc.id :asc]]
+ :limit limit}))
+
+(defn- get-native-card-ids [engine limit]
+ (t2/query {:select [:rc.id :rc.database_id]
+ :from [[:report_card :rc]]
+ :join [[:metabase_database :md] [:= :rc.database_id :md.id]]
+ :where [:and [:= :md.engine engine] [:= :rc.query_type "native"]]
+ :order-by [[:md.id :asc] [:rc.id :asc]]
+ :limit limit}))
+
+(defn- save-card-compilation-results
+ [card-ids output-file]
+ (let [pool (Executors/newFixedThreadPool 8)
+ futures (mapv (fn [{card-id :id db-id :database_id}]
+ (.submit pool ^Callable
+ (fn []
+ (try
+ (let [card-query (t2/select-one-fn :dataset_query :model/Card card-id)
+ {:keys [query params error]} (try
+ (qp.compile/compile card-query)
+ (catch Throwable e
+ {:error (ex-message e)}))]
+ (cond-> {:db_id db-id
+ :card_id card-id
+ :query query
+ :params params}
+ error (assoc :error error)))
+ (catch Throwable e
+ {:db_id db-id
+ :card_id card-id
+ :error (ex-message e)})))))
+ card-ids)]
+ (try
+ (with-open [w (io/writer (str "dev/src/dev/debug_qp/" output-file) :append true)]
+ (doseq [f futures]
+ (.write w (json/encode (.get f)))
+ (.write w "\n")))
+ (finally
+ (.shutdown pool)))))
+
+(defn- load-jsonl-by-card-id [filepath]
+ (with-open [rdr (io/reader filepath)]
+ (into {}
+ (comp (map str/trim)
+ (remove str/blank?)
+ (map #(json/decode % keyword))
+ (map (fn [data] [(:card_id data) data])))
+ (line-seq rdr))))
+
+(defn- get-compilation-diffs [diff-folder mbql4-file mbql5-file]
+ (let [_ (.mkdirs (io/file diff-folder))
+ mbql4-results (load-jsonl-by-card-id mbql4-file)
+ mbql5-results (load-jsonl-by-card-id mbql5-file)
+ _ (assert (= (set (keys mbql4-results)) (set (keys mbql5-results))))
+ card-ids (sort (keys mbql4-results))
+ query-diffs (vec
+ (for [card-id card-ids
+ :let [mbql4-sql (get-in mbql4-results [card-id :query] "")
+ mbql5-sql (get-in mbql5-results [card-id :query] "")]
+ :when (not= mbql4-sql mbql5-sql)]
+ [card-id (sql.u/format-sql :sql mbql4-sql) (sql.u/format-sql :sql mbql5-sql)]))
+ error-diffs (vec
+ (for [card-id card-ids
+ :let [mbql4-err (get-in mbql4-results [card-id :error])
+ mbql5-err (get-in mbql5-results [card-id :error])]
+ :when (not= mbql4-err mbql5-err)]
+ [card-id mbql4-err mbql5-err]))]
+ (when (seq query-diffs)
+ (with-open [^java.io.Writer diff-file (io/writer (io/file diff-folder "query_diffs.txt"))]
+ (doseq [[card-id mbql4-sql mbql5-sql] query-diffs]
+ (doseq [[version sql] [["mbql4" mbql4-sql] ["mbql5" mbql5-sql]]]
+ (spit (io/file diff-folder (str "card_" card-id "_" version ".sql"))
+ (str sql "\n")))
+ (let [result (shell/sh "diff" "-w" "-u"
+ (str (io/file diff-folder (str "card_" card-id "_mbql4.sql")))
+ (str (io/file diff-folder (str "card_" card-id "_mbql5.sql"))))]
+ (.write diff-file (:out result))
+ (.write diff-file "\n")))))
+ (when (seq error-diffs)
+ (with-open [^java.io.Writer f (io/writer (io/file diff-folder "error_diffs.jsonl"))]
+ (doseq [[card-id mbql4-err mbql5-err] error-diffs]
+ (.write f (str (json/encode {:card_id card-id}) "\n"))
+ (.write f (str (json/encode {:mbql4_error mbql4-err}) "\n"))
+ (.write f (str (json/encode {:mbql5_error mbql5-err}) "\n")))))))
+
+(comment
+
+ (def h2-card-ids (get-card-ids "h2" 3800))
+
+ (time
+ (save-card-compilation-results h2-card-ids "h2_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/h2_4_to_5"
+ "dev/src/dev/debug_qp/h2_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/h2_mbql5_results.jsonl")
+
+ (def postgres-card-ids (get-card-ids "postgres" 16600))
+
+ (time
+ (save-card-compilation-results postgres-card-ids "postgres_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/postgres_4_to_5"
+ "dev/src/dev/debug_qp/postgres_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/postgres_mbql5_results.jsonl")
+
+ (def redshift-card-ids (get-card-ids "redshift" 16600))
+
+ (time
+ (save-card-compilation-results redshift-card-ids "redshift_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/redshift_4_to_5"
+ "dev/src/dev/debug_qp/redshift_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/redshift_mbql5_results.jsonl")
+
+ (time
+ (save-card-compilation-results redshift-card-ids "redshift_mock_quotes_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/redshift_5_to_mock_quotes5"
+ "dev/src/dev/debug_qp/redshift_mbql5_results.jsonl"
+ "dev/src/dev/debug_qp/redshift_mock_quotes_mbql5_results.jsonl")
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/redshift_4_to_mock_quotes5"
+ "dev/src/dev/debug_qp/redshift_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/redshift_mock_quotes_mbql5_results.jsonl"))
+
+(comment
+
+ (def h2-native-card-ids (get-native-card-ids "h2" 3800))
+
+ (time
+ (save-card-compilation-results h2-native-card-ids "h2_native_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/h2_native_4_to_5"
+ "dev/src/dev/debug_qp/h2_native_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/h2_native_mbql5_results.jsonl")
+
+ (def postgres-native-card-ids (get-native-card-ids "postgres" 16600))
+
+ (time
+ (save-card-compilation-results postgres-native-card-ids "postgres_native_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/postgres_native_4_to_5"
+ "dev/src/dev/debug_qp/postgres_native_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/postgres_native_mbql5_results.jsonl")
+
+ (def redshift-native-card-ids (get-native-card-ids "redshift" 16600))
+
+ (time
+ (save-card-compilation-results redshift-native-card-ids "redshift_native_mbql5_results.jsonl"))
+
+ (get-compilation-diffs
+ "dev/src/dev/debug_qp/redshift_native_4_to_5"
+ "dev/src/dev/debug_qp/redshift_native_mbql4_results.jsonl"
+ "dev/src/dev/debug_qp/redshift_native_mbql5_results.jsonl"))
diff --git a/modules/drivers/redshift/src/metabase/driver/redshift.clj b/modules/drivers/redshift/src/metabase/driver/redshift.clj
index ed4356ae064..f82f31dd9c6 100644
--- a/modules/drivers/redshift/src/metabase/driver/redshift.clj
+++ b/modules/drivers/redshift/src/metabase/driver/redshift.clj
@@ -376,7 +376,7 @@
(quote-literal-for-connection conn s))))
(defmethod sql.qp/->honeysql [:redshift :regex-match-first]
- [driver [_ arg pattern]]
+ [driver [_ _opts arg pattern]]
[:regexp_substr
(sql.qp/->honeysql driver arg)
;; the parameter to REGEXP_SUBSTR can only be a string literal; neither prepared statement parameters nor encoding/
@@ -385,14 +385,14 @@
[:raw (quote-literal-for-database driver (driver-api/database (driver-api/metadata-provider)) pattern)]])
(defmethod sql.qp/->honeysql [:redshift :replace]
- [driver [_ arg pattern replacement]]
+ [driver [_ _opts arg pattern replacement]]
[:replace
(sql.qp/->honeysql driver arg)
(sql.qp/->honeysql driver pattern)
(sql.qp/->honeysql driver replacement)])
(defmethod sql.qp/->honeysql [:redshift :concat]
- [driver [_ & args]]
+ [driver [_ _opts & args]]
;; concat() only takes 2 args, so generate multiple concats if we have more,
;; e.g. [:concat :x :y :z] => [:concat [:concat :x :y] :z] => concat(concat(x, y), z)
(->> args
@@ -404,7 +404,7 @@
nil)))
(defmethod sql.qp/->honeysql [:redshift :avg]
- [driver [_ field]]
+ [driver [_ _opts field]]
[:avg [:cast (sql.qp/->honeysql driver field) :float]])
(defmethod sql.qp/->integer :redshift
@@ -418,7 +418,7 @@
[:datediff [:raw (name unit)] x y])
(defmethod sql.qp/->honeysql [:redshift :datetime-diff]
- [driver [_ x y unit]]
+ [driver [_ _opts x y unit]]
(let [x (sql.qp/->honeysql driver x)
y (sql.qp/->honeysql driver y)
_ (sql.qp/datetime-diff-check-args x y (partial re-find #"(?i)^(timestamp|date)"))
@@ -430,7 +430,7 @@
(sql.qp/datetime-diff driver unit x y)))
(defmethod sql.qp/->honeysql [:redshift :relative-datetime]
- [driver [_ amount unit]]
+ [driver [_ _opts amount unit]]
(driver-api/maybe-cacheable-relative-datetime-honeysql driver unit amount))
(defmethod sql.qp/->honeysql [:redshift java.time.LocalDate]
@@ -509,7 +509,7 @@
(h2x/- (extract :epoch y) (extract :epoch x)))
(defmethod sql.qp/->honeysql [:redshift ::sql.qp/expression-literal-text-value]
- [driver [_ value]]
+ [driver [_ _opts value]]
(->> (sql.qp/->honeysql driver value)
(h2x/cast :text)))
diff --git a/src/metabase/driver/h2.clj b/src/metabase/driver/h2.clj
index d29164d1e65..a8584c359fa 100644
--- a/src/metabase/driver/h2.clj
+++ b/src/metabase/driver/h2.clj
@@ -43,13 +43,7 @@
;; method impls live in this namespace
(comment h2.actions/keep-me)
-(driver/register! :h2, :parent #{:sql-jdbc ::like-escape-char-built-in/like-escape-char-built-in})
-
-;; h2 can be used to generate mbql5 natively, but this is not the default yet.
-;; we need to gather more data from the experiment (see query-processor/mbql->honeysql)
-;; before we can switch this over. once that happens, make regular :h2 have
-;; :sql-mbql5 as a parent and move the :h2-mbql5 methods below to just :h2.
-(driver/register! :h2-mbql5, :parent #{:h2 :sql-mbql5})
+(driver/register! :h2, :parent #{:sql-jdbc ::like-escape-char-built-in/like-escape-char-built-in :sql-mbql5})
;;; this will prevent the H2 driver from showing up in the list of options when adding a new Database.
(defmethod driver/superseded-by :h2 [_driver] :deprecated)
@@ -98,12 +92,8 @@
supported?))
(defmethod sql.qp/->honeysql [:h2 :regex-match-first]
- [driver [_ arg pattern]]
- [:regexp_substr (sql.qp/->honeysql driver arg) (sql.qp/->honeysql driver pattern)])
-
-(defmethod sql.qp/->honeysql [:h2-mbql5 :regex-match-first]
[driver [_ _opts arg pattern]]
- ((get-method sql.qp/->honeysql [:h2 :regex-match-first]) driver [:regex-match-first arg pattern]))
+ [:regexp_substr (sql.qp/->honeysql driver arg) (sql.qp/->honeysql driver pattern)])
(defmethod driver/connection-properties :h2
[_]
@@ -371,10 +361,6 @@
[driver hsql-form amount unit]
(h2x/add-interval-honeysql-form driver hsql-form amount unit))
-(defmethod sql.qp/add-interval-honeysql-form :h2-mbql5
- [driver hsql-form amount unit]
- (h2x/add-interval-honeysql-form driver hsql-form amount unit))
-
(defmethod driver/humanize-connection-error-message :h2
[_ messages]
(let [message (first messages)]
@@ -404,10 +390,6 @@
[driver]
(h2x/current-datetime-honeysql-form driver))
-(defmethod sql.qp/current-datetime-honeysql-form :h2-mbql5
- [driver]
- (h2x/current-datetime-honeysql-form driver))
-
(defn- add-to-1970 [expr unit-str]
[:timestampadd
(h2x/literal unit-str)
@@ -478,15 +460,11 @@
(defmethod sql.qp/date [:h2 :week-of-year-iso] [_ _ expr] (extract :iso_week expr))
(defmethod sql.qp/->honeysql [:h2 :log]
- [driver [_ field]]
- [:log10 (sql.qp/->honeysql driver field)])
-
-(defmethod sql.qp/->honeysql [:h2-mbql5 :log]
[driver [_ _opts field]]
- ((get-method sql.qp/->honeysql [:h2 :log]) driver [:log field]))
+ [:log10 (sql.qp/->honeysql driver field)])
(defmethod sql.qp/->honeysql [:h2 ::sql.qp/expression-literal-text-value]
- [driver [_ value]]
+ [driver [_ _opts value]]
;; A literal text value gets compiled to a parameter placeholder like "?". H2 attempts to compile the prepared
;; statement immediately, presumably before the types of the params are known, and sometimes raises an "Unknown
;; data type" error if it can't deduce the type. The recommended workaround is to insert an explicit CAST.
@@ -496,10 +474,6 @@
(->> (sql.qp/->honeysql driver value)
(h2x/cast :text)))
-(defmethod sql.qp/->honeysql [:h2-mbql5 ::sql.qp/expression-literal-text-value]
- [driver [_ _opts value]]
- ((get-method sql.qp/->honeysql [:h2 ::sql.qp/expression-literal-text-value]) driver [::sql.qp/expression-literal-text-value value]))
-
(defn- datediff
"Like H2's `datediff` function but accounts for timestamps with time zones."
[unit x y]
diff --git a/src/metabase/driver/postgres.clj b/src/metabase/driver/postgres.clj
index 58dc3ccaf00..9199275a70c 100644
--- a/src/metabase/driver/postgres.clj
+++ b/src/metabase/driver/postgres.clj
@@ -60,8 +60,7 @@
;; default `LIKE` escape character is already `\`, so an explicit `ESCAPE '\'` clause is
;; redundant *and* the literal `'\'` is unparseable by the PG JDBC driver when the server has
;; `standard_conforming_strings = off` (#73721).
-(driver/register! :postgres, :parent #{:sql-jdbc ::like-escape-char-built-in/like-escape-char-built-in})
-(driver/register! :postgres-mbql5, :parent #{:postgres :sql-mbql5})
+(driver/register! :postgres, :parent #{:sql-jdbc ::like-escape-char-built-in/like-escape-char-built-in :sql-mbql5})
(defmethod driver/display-name :postgres [_] "PostgreSQL")
@@ -110,7 +109,7 @@
:database-replication]]
(defmethod driver/database-supports? [:postgres feature]
[driver _feat _db]
- (or (= driver :postgres) (= driver :postgres-mbql5))))
+ (= driver :postgres)))
(defmethod driver/escape-entity-name-for-metadata :postgres [_driver entity-name]
(when entity-name
@@ -493,18 +492,10 @@
[driver hsql-form amount unit]
(h2x/add-interval-honeysql-form driver hsql-form amount unit))
-(defmethod sql.qp/add-interval-honeysql-form :postgres-mbql5
- [driver hsql-form amount unit]
- (h2x/add-interval-honeysql-form driver hsql-form amount unit))
-
(defmethod sql.qp/current-datetime-honeysql-form :postgres
[driver]
(h2x/current-datetime-honeysql-form driver))
-(defmethod sql.qp/current-datetime-honeysql-form :postgres-mbql5
- [driver]
- (h2x/current-datetime-honeysql-form driver))
-
(defmethod sql.qp/unix-timestamp->honeysql [:postgres :seconds]
[_ _ expr]
;; without tagging the expression, other code will want to add a type
@@ -610,7 +601,7 @@
(h2x/maybe-cast (h2x/database-type expr) (h2x/->date expr)))
(defmethod sql.qp/->honeysql [:postgres :convert-timezone]
- [driver [_ arg target-timezone source-timezone]]
+ [driver [_ _opts arg target-timezone source-timezone]]
(let [expr (sql.qp/->honeysql driver (cond-> arg
(string? arg) u.date/parse))
timestamptz? (or (sql.qp.u/field-with-tz? arg)
@@ -622,13 +613,8 @@
expr)]]
(h2x/with-database-type-info expr "timestamp")))
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :convert-timezone]
- [driver [_ _opts arg target-timezone source-timezone]]
- ((get-method sql.qp/->honeysql [:postgres :convert-timezone])
- driver [:convert-timezone arg target-timezone source-timezone]))
-
(defmethod sql.qp/->honeysql [:postgres :value]
- [driver [_ raw-value {base-type :base_type database-type :database_type}]]
+ [driver [_ {:keys [base-type database-type]} raw-value]]
(when (some? raw-value)
(condp #(isa? %2 %1) base-type
:type/PostgresBitString (h2x/cast :varbit raw-value)
@@ -636,23 +622,12 @@
:type/PostgresEnum (if (quoted? database-type)
(h2x/cast database-type raw-value)
(h2x/quoted-cast database-type raw-value))
- ((get-method sql.qp/->honeysql [:sql-jdbc :value])
- driver [:value raw-value {:base_type base-type :database_type database-type}]))))
-
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :value]
- [driver [_ {:keys [base-type effective-type database-type]} raw-value]]
- ((get-method sql.qp/->honeysql [:postgres :value])
- driver [:value raw-value {:base_type base-type
- :effective_type effective-type
- :database_type database-type}]))
+ ((get-method sql.qp/->honeysql [:sql-mbql5 :value])
+ driver (sql.qp/mbql-clause-with-opts driver :value {:base_type base-type :database_type database-type} raw-value)))))
(defmethod sql.qp/->honeysql [:postgres :median]
- [driver [_ arg]]
- (sql.qp/->honeysql driver (sql.qp/mbql-clause driver :percentile arg 0.5)))
-
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :median]
[driver [_ _opts arg]]
- ((get-method sql.qp/->honeysql [:postgres :median]) driver [:median arg]))
+ (sql.qp/->honeysql driver (sql.qp/mbql-clause driver :percentile arg 0.5)))
(defmethod sql.qp/datetime-diff [:postgres :year]
[_driver _unit x y]
@@ -706,16 +681,12 @@
(sql/register-fn! ::regex-match-first #'format-regex-match-first)
(defmethod sql.qp/->honeysql [:postgres :regex-match-first]
- [driver [_ arg pattern]]
+ [driver [_ _opts arg pattern]]
(let [identifier (sql.qp/->honeysql driver arg)]
[::regex-match-first identifier pattern]))
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :regex-match-first]
- [driver [_ _opts arg pattern]]
- ((get-method sql.qp/->honeysql [:postgres :regex-match-first]) driver [:regex-match-first arg pattern]))
-
(defmethod sql.qp/->honeysql [:postgres :split-part]
- [driver [_ text divider position]]
+ [driver [_ _opts text divider position]]
(let [position (sql.qp/->honeysql driver position)]
[:case
[:< position 1]
@@ -723,17 +694,9 @@
:else
[:split_part (sql.qp/->honeysql driver text) (sql.qp/->honeysql driver divider) position]]))
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :split-part]
- [driver [_ _opts text divider position]]
- ((get-method sql.qp/->honeysql [:postgres :split-part]) driver [:split-part text divider position]))
-
(defmethod sql.qp/->honeysql [:postgres :text]
- [driver [_ value]]
- (h2x/maybe-cast "TEXT" (sql.qp/->honeysql driver value)))
-
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :text]
[driver [_ _opts value]]
- ((get-method sql.qp/->honeysql [:postgres :text]) driver [:text value]))
+ (h2x/maybe-cast "TEXT" (sql.qp/->honeysql driver value)))
(defn- format-pg-conversion [_fn [expr psql-type]]
(let [[expr-sql & expr-args] (sql/format-expr expr {:nested true})]
@@ -806,10 +769,10 @@
[::json-query parent-identifier field-type (rest nfc-path)]))
(defmethod sql.qp/->honeysql [:postgres :field]
- [driver [_ id-or-name opts :as clause]]
+ [driver [_ opts id-or-name :as clause]]
(let [stored-field (when (integer? id-or-name)
(driver-api/field (driver-api/metadata-provider) id-or-name))
- parent-method (get-method sql.qp/->honeysql [:sql :field])
+ parent-method (get-method sql.qp/->honeysql [:sql-mbql5 :field])
identifier (parent-method driver clause)]
(cond
(= (:database-type stored-field) "money")
@@ -839,10 +802,6 @@
:else
identifier)))
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :field]
- [driver [_ opts id-or-name]]
- ((get-method sql.qp/->honeysql [:postgres :field]) driver [:field id-or-name opts]))
-
;; Postgres is not happy with JSON fields which are in group-bys or order-bys
;; being described twice instead of using the alias.
;; Therefore, force the alias, but only for JSON fields to avoid ambiguity.
@@ -850,29 +809,11 @@
(defmethod sql.qp/apply-top-level-clause
[:postgres :breakout]
[driver clause honeysql-form {breakout-fields :breakout, _fields-fields :fields :as query}]
- (let [stored-field-ids (map second breakout-fields)
- stored-fields (map #(when (integer? %)
- (driver-api/field (driver-api/metadata-provider) %))
- stored-field-ids)
- parent-method (partial (get-method sql.qp/apply-top-level-clause [:sql :breakout])
- driver clause honeysql-form)
- qualified (parent-method query)
- unqualified (parent-method (update query
- :breakout
- #(sql.qp/rewrite-fields-to-force-using-column-aliases % {:is-breakout true})))]
- (if (some driver-api/json-field? stored-fields)
- (merge qualified
- (select-keys unqualified #{:group-by}))
- qualified)))
-
-(defmethod sql.qp/apply-top-level-clause
- [:postgres-mbql5 :breakout]
- [driver clause honeysql-form {breakout-fields :breakout, _fields-fields :fields :as query}]
(let [stored-field-ids (map last breakout-fields)
stored-fields (map #(when (integer? %)
(driver-api/field (driver-api/metadata-provider) %))
stored-field-ids)
- parent-method (partial (get-method sql.qp/apply-top-level-clause [:sql :breakout])
+ parent-method (partial (get-method sql.qp/apply-top-level-clause [:sql-mbql5 :breakout])
driver clause honeysql-form)
qualified (parent-method query)
unqualified (parent-method (update query
@@ -894,34 +835,20 @@
(driver-api/json-field? stored-field))))
(defmethod sql.qp/->honeysql [:postgres :desc]
- [driver clause]
- (let [new-clause (if (order-by-is-json-field? clause 1)
- (sql.qp/rewrite-fields-to-force-using-column-aliases clause)
- clause)]
- ((get-method sql.qp/->honeysql [:sql :desc]) driver new-clause)))
-
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :desc]
[driver clause]
(let [new-clause (if (order-by-is-json-field? clause 2)
(sql.qp/rewrite-fields-to-force-using-column-aliases clause)
clause)
[_ opts ordered-clause] new-clause]
- ((get-method sql.qp/->honeysql [:sql :desc]) driver [:desc ordered-clause opts])))
+ ((get-method sql.qp/->honeysql [:sql-mbql5 :desc]) driver (sql.qp/mbql-clause-with-opts driver :desc opts ordered-clause))))
(defmethod sql.qp/->honeysql [:postgres :asc]
- [driver clause]
- (let [new-clause (if (order-by-is-json-field? clause 1)
- (sql.qp/rewrite-fields-to-force-using-column-aliases clause)
- clause)]
- ((get-method sql.qp/->honeysql [:sql :asc]) driver new-clause)))
-
-(defmethod sql.qp/->honeysql [:postgres-mbql5 :asc]
[driver clause]
(let [new-clause (if (order-by-is-json-field? clause 2)
(sql.qp/rewrite-fields-to-force-using-column-aliases clause)
clause)
[_ opts ordered-clause] new-clause]
- ((get-method sql.qp/->honeysql [:sql :asc]) driver [:asc ordered-clause opts])))
+ ((get-method sql.qp/->honeysql [:sql-mbql5 :asc]) driver (sql.qp/mbql-clause-with-opts driver :asc opts ordered-clause))))
;;; +----------------------------------------------------------------------------------------------------------------+
;;; | metabase.driver.sql-jdbc impls |
diff --git a/src/metabase/driver/postgres/actions.clj b/src/metabase/driver/postgres/actions.clj
index 84e5cca9732..97e5fcc0165 100644
--- a/src/metabase/driver/postgres/actions.clj
+++ b/src/metabase/driver/postgres/actions.clj
@@ -99,35 +99,6 @@
:message (tru "Some of your values violate the constraint: {0}" constraint-name)
:errors {}}))
-(defn- maybe-parse-sql-error-with-postgres
- [driver error-type database action-type error-message]
- ((get-method sql-jdbc.actions/maybe-parse-sql-error [:postgres error-type])
- driver error-type database action-type error-message))
-
-(defmethod sql-jdbc.actions/maybe-parse-sql-error [:postgres-mbql5 driver-api/violate-not-null-constraint]
- [driver error-type database action-type error-message]
- (maybe-parse-sql-error-with-postgres driver error-type database action-type error-message))
-
-(defmethod sql-jdbc.actions/maybe-parse-sql-error [:postgres-mbql5 driver-api/violate-unique-constraint]
- [driver error-type database action-type error-message]
- (maybe-parse-sql-error-with-postgres driver error-type database action-type error-message))
-
-(defmethod sql-jdbc.actions/maybe-parse-sql-error [:postgres-mbql5 driver-api/violate-foreign-key-constraint]
- [driver error-type database action-type error-message]
- (maybe-parse-sql-error-with-postgres driver error-type database action-type error-message))
-
-(defmethod sql-jdbc.actions/maybe-parse-sql-error [:postgres-mbql5 driver-api/incorrect-value-type]
- [driver error-type database action-type error-message]
- (maybe-parse-sql-error-with-postgres driver error-type database action-type error-message))
-
-(defmethod sql-jdbc.actions/maybe-parse-sql-error [:postgres-mbql5 driver-api/violate-permission-constraint]
- [driver error-type database action-type error-message]
- (maybe-parse-sql-error-with-postgres driver error-type database action-type error-message))
-
-(defmethod sql-jdbc.actions/maybe-parse-sql-error [:postgres-mbql5 driver-api/violate-check-constraint]
- [driver error-type database action-type error-message]
- (maybe-parse-sql-error-with-postgres driver error-type database action-type error-message))
-
(defmethod sql-jdbc.actions/base-type->sql-type-map :postgres
[_driver]
{:type/BigInteger "BIGINT"
diff --git a/src/metabase/driver/sql/query_processor.clj b/src/metabase/driver/sql/query_processor.clj
index 5f1056c9370..507a4553e8c 100644
--- a/src/metabase/driver/sql/query_processor.clj
+++ b/src/metabase/driver/sql/query_processor.clj
@@ -16,7 +16,6 @@
[metabase.query-processor.util.persisted-cache :as qp.persisted]
[metabase.util :as u]
[metabase.util.date-2 :as u.date]
- [metabase.util.experiment :as experiment]
[metabase.util.honey-sql-2 :as h2x]
[metabase.util.i18n :refer [tru]]
[metabase.util.log :as log]
@@ -2307,7 +2306,10 @@
[driver query]
(apply-clauses driver {} query))
-(defn- mbql->honeysql* [driver query]
+(mu/defn mbql->honeysql :- [:or :map [:tuple [:= :inline] :map]]
+ "Build the HoneySQL form we will compile to SQL and execute."
+ [driver :- :keyword
+ query :- :map]
(if (:lib/type query)
(binding [driver/*driver* driver]
(let [inner-query (preprocess driver query)]
@@ -2323,32 +2325,6 @@
mbql5-query (driver-api/query-from-legacy-inner-query metadata-provider database-id inner-query)]
(recur driver mbql5-query))))
-(def ^:private experimental-mbql5-drivers {:h2 :h2-mbql5
- :postgres :postgres-mbql5})
-
-(defn- mbql5-experiment-report
- [driver experimental-driver query]
- (fn [{:keys [match? candidate-outcome control-outcome] :as result}]
- (when-let [report-fn @experiment/default-report-fn]
- (report-fn result))
- (when-not match?
- (log/with-context {:experimental-mbql5-driver :mismatch
- :driver driver
- :experimental-driver experimental-driver}
- (log/warnf "MBQL5 experiment mismatch:\nQuery: %s\nControl result: %s\nCandidate result: %s"
- query control-outcome candidate-outcome)))))
-
-(mu/defn mbql->honeysql :- [:or :map [:tuple [:= :inline] :map]]
- "Build the HoneySQL form we will compile to SQL and execute."
- [driver :- :keyword
- query :- :map]
- (if-let [experimental-driver (experimental-mbql5-drivers driver)]
- (experiment/experiment {:name :experimental-mbql5-driver
- :report-fn (mbql5-experiment-report driver experimental-driver query)}
- (mbql->honeysql* driver query)
- (mbql->honeysql* experimental-driver query))
- (mbql->honeysql* driver query)))
-
;;;; MBQL -> Native
(mu/defn mbql->native :- [:map
diff --git a/src/metabase/driver/sql/util.clj b/src/metabase/driver/sql/util.clj
index 21a6e718f2d..765c0fae3ee 100644
--- a/src/metabase/driver/sql/util.clj
+++ b/src/metabase/driver/sql/util.clj
@@ -162,7 +162,6 @@
:n1ql Dialect/N1ql
:plsql Dialect/PlSql
:postgres Dialect/PostgreSql
- :postgres-mbql5 Dialect/PostgreSql
:redshift Dialect/Redshift
:sparksql Dialect/SparkSql
:standardsql Dialect/StandardSql
diff --git a/src/metabase/sql_tools/sqlglot/core.clj b/src/metabase/sql_tools/sqlglot/core.clj
index c48ff2dc6a7..1fdd5f6fa56 100644
--- a/src/metabase/sql_tools/sqlglot/core.clj
+++ b/src/metabase/sql_tools/sqlglot/core.clj
@@ -34,7 +34,6 @@
(case driver
nil nil
:postgres "postgres"
- :postgres-mbql5 "postgres"
:mysql "mysql"
:snowflake "snowflake"
:bigquery "bigquery"
@@ -47,7 +46,6 @@
:clickhouse "clickhouse"
:vertica nil
:h2 nil
- :h2-mbql5 nil
;; Default: try using the driver name as dialect
(name driver)))
diff --git a/src/metabase/util/honey_sql_2.clj b/src/metabase/util/honey_sql_2.clj
index 5f6a907ce63..ffd4a518c68 100644
--- a/src/metabase/util/honey_sql_2.clj
+++ b/src/metabase/util/honey_sql_2.clj
@@ -448,9 +448,9 @@
"HoneySQL form that should be used to get the current `datetime` (or equivalent), e.g. `:%now`."
[db-type]
(case db-type
- (:h2 :h2-mbql5) (with-database-type-info :%now "timestamp")
+ :h2 (with-database-type-info :%now "timestamp")
:mysql (with-database-type-info [:now [:inline 6]] "timestamp")
- (:postgres :postgres-mbql5) (with-database-type-info :%now "timestamptz")))
+ :postgres (with-database-type-info :%now "timestamptz")))
(defn- format-postgres-interval
"Generate a Postgres 'INTERVAL' literal.
@@ -505,10 +505,6 @@
(-> (+ hsql-form (pg-interval amount unit))
(with-type-info (type-info hsql-form))))))
-(defmethod add-interval-honeysql-form :postgres-mbql5
- [db-type hsql-form amount unit]
- ((get-method add-interval-honeysql-form :postgres) db-type hsql-form amount unit))
-
(defmethod add-interval-honeysql-form :mysql
[db-type hsql-form amount unit]
;; MySQL doesn't support `:millisecond` as an option, but does support fractional seconds
@@ -541,10 +537,6 @@
:else
(dateadd-h2 unit amount hsql-form)))
-(defmethod add-interval-honeysql-form :h2-mbql5
- [db-type hsql-form amount unit]
- ((get-method add-interval-honeysql-form :h2) db-type hsql-form amount unit))
-
(defmethod add-interval-honeysql-form :default
[db-type hsql-form amount unit]
(throw (ex-info (clojure.core/format (str "metabase.util.honey-sql-2/add-interval-honeysql-form not implemented for db-type %s. "
diff --git a/test/metabase/driver/h2_test.clj b/test/metabase/driver/h2_test.clj
index 67592cf8d6f..58ce1146d42 100644
--- a/test/metabase/driver/h2_test.clj
+++ b/test/metabase/driver/h2_test.clj
@@ -27,14 +27,6 @@
(set! *warn-on-reflection* true)
-;; drop this once h2 is mbql5-compliant by default
-(def ^:dynamic *driver* :h2)
-
-(use-fixtures :each (fn [thunk]
- (thunk)
- (binding [*driver* :h2-mbql5]
- (thunk))))
-
(deftest ^:parallel parse-connection-string-test
(testing "Check that the functions for exploding a connection string's options work as expected"
(is (= ["file:my-file" {"OPTION_1" "TRUE", "OPTION_2" "100", "LOOK_I_INCLUDED_AN_EXTRA_SEMICOLON" "NICE_TRY"}]
@@ -114,7 +106,7 @@
(is (= {:invalid-keys #{"classname"}} (ex-data result))))))))
(deftest ^:parallel db-default-timezone-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(is (= (t/zone-id "Z")
(-> (driver/db-default-timezone :h2 (mt/db))
t/zone-id
@@ -158,7 +150,7 @@
(sql.qp/add-interval-honeysql-form :h2 (sql.qp/current-datetime-honeysql-form :h2) 100.0 :second)))))
(deftest ^:parallel clob-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(testing "Make sure we properly handle rows that come back as `org.h2.jdbc.JdbcClob`"
(let [results (qp/process-query (mt/native-query {:query "SELECT cast('Conchúr Tihomir' AS clob) AS name;"}))]
(testing "rows"
@@ -174,7 +166,7 @@
(mt/cols results))))))))
(deftest ^:parallel native-query-date-trunc-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(testing "A native query that doesn't return a column class name metadata should work correctly (#12150)"
(is (=? [{:display_name "D"
:base_type :type/Date
@@ -213,7 +205,7 @@
(str/replace #"PUBLIC\." "")))
(deftest ^:parallel do-not-cast-to-date-if-column-is-already-a-date-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(testing "Don't wrap Field in date() if it's already a DATE (#11502)"
(mt/dataset attempted-murders
(let [query (mt/mbql-query attempts
@@ -226,7 +218,7 @@
(some-> (qp.compile/compile query) :query pretty-sql))))))))
(deftest ^:parallel do-not-cast-to-date-binned-by-week-to-datetime
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(testing "Don't cast date binned by week"
(mt/dataset attempted-murders
(let [query (mt/mbql-query attempts
@@ -236,7 +228,7 @@
(is (not (re-find #"CAST\([^)]+\s+AS\s+datetime\)" compiled))))))))
(deftest ^:parallel check-action-commands-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
#_{:clj-kondo/ignore [:equals-true]}
(are [query] (= true (#'h2/every-command-allowed-for-actions? (#'h2/classify-query (mt/id) query)))
"select 1"
@@ -363,7 +355,7 @@
"CALL LINK_SCHEMA('LK','org.h2.Driver','jdbc:h2:mem:t','sa','','PUBLIC')")))
(deftest disallowed-commands-in-action-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(mt/with-actions-test-data-and-actions-enabled
(testing "Should not be able to execute query actions with disallowed commands"
(let [sql "select * from categories; update categories set name = 'stomp';
@@ -379,7 +371,7 @@
(format "action/%s/execute" action-id))))))))))
(deftest disallowed-commands-in-action-test-2
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(mt/with-actions-test-data-and-actions-enabled
(testing "Should be able to execute query actions with allowed commands"
(let [sql "update categories set name = 'stomp' where id = 1; update categories set name = 'stomp' where id = 2;"]
@@ -393,14 +385,14 @@
(format "action/%s/execute" action-id))))))))))
(deftest ^:parallel syncable-schemas-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(testing "`syncable-schemas` should return schemas that should be synced"
(mt/with-empty-db
(is (= #{"PUBLIC"}
(driver/syncable-schemas driver/*driver* (mt/db))))))))
(deftest syncable-audit-db-test
- (mt/test-driver *driver*
+ (mt/test-driver :h2
(when config/ee-available?
(let [audit-db-expected-id 13371337
original-audit-db (t2/select-one :model/Database :is_audit true)]
diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.clj
index 6183700d796..18cd5dbaa37 100644
--- a/test/metabase/driver/postgres_test.clj
+++ b/test/metabase/driver/postgres_test.clj
@@ -67,9 +67,6 @@
(set! *warn-on-reflection* true)
-;; drop this once postgres is mbql5-compliant by default
-(def ^:dynamic *driver* :postgres)
-
(use-fixtures :each (fn [thunk]
;; 1. If sync fails when loading a test dataset, don't swallow the error; throw an Exception so we
;; can debug it. This is much less confusing when trying to fix broken tests.
@@ -77,9 +74,7 @@
;; 2. Make sure we're in Honey SQL 2 mode for all the little SQL snippets we're compiling in these
;; tests.
(binding [sync-util/*log-exceptions-and-continue?* false]
- (mt/with-test-user :rasta (thunk))
- (binding [*driver* :postgres-mbql5]
- (mt/with-test-user :rasta (thunk))))))
+ (mt/with-test-user :rasta (thunk)))))
(deftest ^:parallel extract-test
(is (= ["extract(month from NOW())"]
@@ -106,7 +101,7 @@
")"]
"2021-10-03T09:00:00"
"2021-10-03T09:00:00"]
- (as-> [:datetime-diff "2021-10-03T09:00:00" "2021-10-03T09:00:00" :year] <>
+ (as-> [:datetime-diff {} "2021-10-03T09:00:00" "2021-10-03T09:00:00" :year] <>
(sql.qp/->honeysql :postgres <>)
(sql.qp/format-honeysql :postgres <>)
(update (vec <>) 0 #(str/split-lines (driver/prettify-native-form :postgres %)))))))
@@ -199,7 +194,7 @@
;;; ------------------------------------------- Tests for sync edge cases --------------------------------------------
(deftest ^:sequential edge-case-identifiers-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Make sure that Tables / Fields with dots in their names get escaped properly"
(mt/dataset dots-in-names
(is (= {:columns ["id" "dotted.name"]
@@ -250,7 +245,7 @@
[["Cam" 1]]]])
(deftest duplicate-names-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Make sure that duplicate column names (e.g. caused by using a FK) still return both columns"
(mt/dataset duplicate-names
(is (= {:columns ["name" "name_2"]
@@ -278,7 +273,7 @@
(sort-by :name)))
(deftest materialized-views-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing (str "Check that we properly fetch materialized views. As discussed in #2355 they don't come back from "
"JDBC `DatabaseMetadata` so we have to fetch them manually.")
(tx/drop-if-exists-and-create-db! driver/*driver* "materialized_views_test")
@@ -293,7 +288,7 @@
(describe-database->tables :postgres database))))))))
(deftest foreign-tables-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Check that we properly fetch foreign tables."
(tx/drop-if-exists-and-create-db! driver/*driver* "fdw_test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "fdw_test"})]
@@ -327,7 +322,7 @@
(describe-database->tables :postgres database))))))))
(deftest estimated-row-count-hides-zero-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Check that tables with n_live_tup = 0 return nil for estimated_row_count to avoid confusion with stale stats"
(tx/drop-if-exists-and-create-db! driver/*driver* "estimated_count_test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "estimated_count_test"})]
@@ -339,7 +334,7 @@
(describe-database->tables :postgres database))))))))
(deftest recreated-views-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing (str "make sure that if a view is dropped and recreated that the original Table object is marked active "
"rather than a new one being created (#3331)")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "dropped_views_test"})
@@ -371,7 +366,7 @@
(t2/select [:model/Table :name :active] :db_id (u/the-id database), :name "angry_birds"))))))))))
(deftest partitioned-table-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing (str "Make sure that partitioned tables (in addition to the individual partitions themselves) are"
" synced properly (#15049)")
(let [db-name "partitioned_table_test"
@@ -451,7 +446,7 @@
"rather than on the array path argument:\n " out-sql)))))
(deftest ^:parallel json-field-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Deal with complicated identifier (#22967)"
(qp.store/with-metadata-provider (lib.tu/mock-metadata-provider
{:database (assoc meta/database :engine driver/*driver*, :id 1)
@@ -480,7 +475,7 @@
(defn- ^:private maybe-convert-and-compile [driver query]
(cond-> query
- (= driver :postgres-mbql5) (lib.convert/->mbql5)
+ (= driver :postgres) (lib.convert/->mbql5)
:always qp.compile/compile))
(defn- ^:private json-alias-mock-metadata-provider [driver]
@@ -501,7 +496,7 @@
:database-type "VARCHAR"})]}))
(deftest ^:parallel json-alias-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "json breakouts and order bys have alias coercion"
(qp.store/with-metadata-provider (json-alias-mock-metadata-provider driver/*driver*)
;; need to make this a function to avoid a duplicate `:lib/uuid` error when we use it in `compile-res`
@@ -542,7 +537,7 @@
(:params compile-res))))))))
(deftest ^:parallel json-alias-test-2
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "json breakouts and order bys have alias coercion"
(qp.store/with-metadata-provider (json-alias-mock-metadata-provider driver/*driver*)
(let [field-ordinary (sql.qp/mbql-clause-with-opts driver/*driver* :field nil 1)
@@ -576,7 +571,7 @@
:breakout [[:field 1 nil]]}})}]}))
(deftest ^:parallel json-breakout-in-model-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "JSON columns in inner queries are referenced properly in outer queries #34930"
(qp.store/with-metadata-provider (json-alias-in-model-mock-metadata-provider driver/*driver*)
(let [nested (maybe-convert-and-compile
@@ -608,7 +603,7 @@
;;; `Unterminated string literal started at position N` before the SQL ever reaches the server
;;; (#73721).
(deftest contains-filter-jdbc-parser-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "PGJDBC parses :contains/:starts-with/:ends-with SQL regardless of standard_conforming_strings (#73721)"
(let [mp (mt/metadata-provider)
venues (lib.metadata/table mp (mt/id :venues))
@@ -638,7 +633,7 @@
(str "PGJDBC should prepare the SQL; got SQL: " sql)))))))))))))
(deftest describe-nested-field-columns-identifier-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "sync goes and runs with identifier if there is a schema other than default public one"
(tx/drop-if-exists-and-create-db! driver/*driver* "describe-json-with-schema-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "describe-json-with-schema-test"
@@ -663,7 +658,7 @@
{:schema "bobdobbs" :name "describe_json_table" :id (mt/id "describe_json_table")})))))))))
(deftest describe-funky-name-table-nested-field-columns-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "sync goes and still works with funky schema and table names, including caps and special chars (#23026, #23027)"
(tx/drop-if-exists-and-create-db! driver/*driver* "describe-json-funky-names-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "describe-json-funky-names-test"
@@ -697,7 +692,7 @@
[#uuid "84ed434e-80b4-41cf-9c88-e334427104ae"]]]])
(deftest uuid-columns-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/dataset with-uuid
(testing "Check that we can load a Postgres Database with a :type/UUID"
(is (= [{:name "id", :base_type :type/Integer}
@@ -804,7 +799,7 @@
[[:raw "'10.4.4.15'::inet"]]]]])
(deftest inet-columns-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing (str "Filtering by inet columns should add the appropriate SQL cast, e.g. `cast('192.168.1.1' AS inet)` "
"(otherwise this wouldn't work)")
(mt/dataset ip-addresses
@@ -832,7 +827,7 @@
(thunk)))))
(deftest ^:parallel money-columns-in-results-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "It should be possible to return money column results (#3754)"
(sql-jdbc.execute/do-with-connection-with-options
:postgres
@@ -846,7 +841,7 @@
(row-thunk))))))))))
(deftest money-columns-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "We should support the Postgres MONEY type"
(do-with-money-test-db!
(fn []
@@ -927,14 +922,14 @@
(driver/notify-database-updated :postgres database)))
(deftest ^:parallel enums-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "check that values for enum types get wrapped in appropriate CAST() fn calls in `->honeysql`"
(is (= (h2x/with-database-type-info [:cast "toucan" (h2x/identifier :type-name "bird type")]
"bird type")
(sql.qp/->honeysql driver/*driver* (sql.qp/mbql-clause-with-opts driver/*driver* :value {:database_type "bird type", :base_type :type/PostgresEnum} "toucan")))))))
(deftest enums-test-2
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(do-with-enums-db!
(fn [db]
(testing "check that we can actually fetch the enum types from a DB"
@@ -1014,7 +1009,7 @@
(select-keys [:rows :native_form]))))))))))
(deftest enums-test-3
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(do-with-enums-db!
(fn [db]
(tx/create-view-of-table! driver/*driver* db "birds_m" "birds" true)
@@ -1093,7 +1088,7 @@
(select-keys [:rows :native_form]))))))))))
(deftest enums-actions-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "actions with enums"
(do-with-enums-db!
(fn [enums-db]
@@ -1290,7 +1285,7 @@
;; this contains special tests case for postgres
;; for generic tests, check [[metabase.driver.sql-jdbc.actions-test/action-error-handling-test]]
(deftest check-constraint-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "violate check constraints"
(tx/drop-if-exists-and-create-db! driver/*driver* "check-constraint-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "check-constraint-test"})]
@@ -1320,7 +1315,7 @@
;; this contains special tests case for postgres
;; for generic tests, check [[metabase.driver.sql-jdbc.actions-test/action-error-handling-test]]
(deftest action-error-handling-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "violate not-null constraints with multiple columns"
(tx/drop-if-exists-and-create-db! driver/*driver* "not-null-constraint-on-multiple-cols")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "not-null-constraint-on-multiple-cols"})]
@@ -1366,7 +1361,7 @@
;;; ------------------------------------------------ Timezone-related ------------------------------------------------
(deftest timezone-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(letfn [(get-timezone-with-report-timezone [report-timezone]
(mt/with-temporary-setting-values [report-timezone report-timezone]
(ffirst
@@ -1386,7 +1381,7 @@
(get-timezone-with-report-timezone "Crunk Burger")))))))
(deftest fingerprint-time-fields-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Make sure we're able to fingerprint TIME fields (#5911)"
(tx/drop-if-exists-and-create-db! driver/*driver* "time_field_test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "time_field_test"})]
@@ -1429,7 +1424,7 @@
;;; ----------------------------------------------------- Other ------------------------------------------------------
(deftest ^:parallel exception-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing (str "If the DB throws an exception, is it properly returned by the query processor? Is it status "
":failed? (#9942)")
(is (thrown-with-msg?
@@ -1454,7 +1449,7 @@
;;; see [[metabase.query-processor.middleware.annotate-test/native-query-infer-effective-type-test]] for a test that
;;; just makes sure metadata is calculated correctly.
(deftest ^:parallel pgobject-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Make sure PGobjects are decoded correctly"
(let [results (qp/process-query (mt/native-query {:query "SELECT pg_sleep(0.01) AS sleep;"}))]
(testing "rows"
@@ -1471,7 +1466,7 @@
(mt/cols results))))))))
(deftest ^:parallel id-field-parameter-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "We should be able to filter a PK column with a String value -- should get parsed automatically (#13263)"
(is (= [[2 "Stout Burgers & Beers" 11 34.0996 -118.329 2]]
(mt/rows
@@ -1480,7 +1475,7 @@
(deftest dont-sync-tables-with-no-select-permissions-test
(testing "Make sure we only sync databases for which the current user has SELECT permissions"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(tx/drop-if-exists-and-create-db! driver/*driver* "no-select-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "no-select-test"})
spec (sql-jdbc.conn/connection-details->spec :postgres details)]
@@ -1503,7 +1498,7 @@
(deftest json-operator-?-works
(testing "Make sure the Postgres ? operators (for JSON types) work in native queries"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(tx/drop-if-exists-and-create-db! driver/*driver* "json-test")
(let [details (mt/dbdef->connection-details :postgres :db {:database-name "json-test"})
spec (sql-jdbc.conn/connection-details->spec :postgres details)]
@@ -1542,7 +1537,7 @@
(deftest sync-json-with-composite-pks-test
(testing "Make sure sync a table with json columns that have composite pks works"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(tx/drop-if-exists-and-create-db! driver/*driver* "composite-pks-test")
(with-redefs [table-rows-sample/nested-field-sample-limit 4]
(let [details (mt/dbdef->connection-details driver/*driver* :db {:database-name "composite-pks-test"})
@@ -1578,7 +1573,7 @@
(deftest ^:parallel do-not-cast-to-date-if-column-is-already-a-date-test
(testing "Don't wrap Field in date() if it's already a DATE (#11502)"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/dataset attempted-murders
(let [query (mt/mbql-query attempts
{:aggregation [[:count]]
@@ -1591,7 +1586,7 @@
(deftest ^:parallel do-not-cast-to-timestamp-if-column-if-timestamp-tz-or-date-test
(testing "Don't cast a DATE or TIMESTAMPTZ to TIMESTAMP, it's not necessary (#19816)"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/dataset test-data
(let [query (mt/mbql-query people
{:fields [!month.birth_date
@@ -1613,7 +1608,7 @@
(update :query #(str/split-lines (driver/prettify-native-form :postgres %)))))))))))
(deftest postgres-ssl-connectivity-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(if (config/config-bool :mb-postgres-ssl-test-ssl)
(testing "We should be able to connect to a Postgres instance, providing our own root CA via a secret property"
(mt/with-env-keys-renamed-by #(str/replace-first % "mb-postgres-ssl-test" "mb-postgres-test")
@@ -1628,7 +1623,7 @@
"-----END CERTIFICATE-----"))
(deftest handle-nil-client-ssl-properties-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "Setting only one of the client SSL params doesn't result in an NPE error (#19984)"
(mt/with-temp-file [dummy-root-cert "dummy-root-cert.pem"
dummy-client-cert "dummy-client-cert.pem"]
@@ -1700,7 +1695,7 @@
(str/ends-with? ".p12"))))))
(deftest syncable-schemas-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "`syncable-schemas` should return schemas that should be synced"
(mt/with-empty-db
(is (= #{"public"}
@@ -1720,7 +1715,7 @@
(driver/syncable-schemas driver/*driver* (mt/db))))))))))))
(deftest table-privileges-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "`table-privileges` should return the correct data for current_user and role privileges"
(mt/with-empty-db
(let [conn-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))
@@ -1796,7 +1791,7 @@
(deftest query-canceled?-test
(testing "Recognizes timeout exceptions from postgres"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/dataset test-data
(let [long-sleep-sql "select pg_sleep(5)"]
(sql-jdbc.execute/do-with-connection-with-options
@@ -1812,7 +1807,7 @@
(deftest ^:parallel set-role-statement-test
(testing "set-role-statement should return a SET ROLE command, with the role quoted if it contains special characters"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(sql-jdbc.execute/do-with-connection-with-options
:postgres (mt/id) nil
(fn [conn]
@@ -1830,7 +1825,7 @@
(deftest get-tables-parity-with-jdbc-test
(testing "make sure our get-tables return result consistent with jdbc getTables"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/with-empty-db
(sql-jdbc.execute/do-with-connection-with-options
:postgres
@@ -1868,7 +1863,7 @@
(deftest ^:parallel date-plus-integer-test
(testing "Can we add a {{date}} template tag parameter to an integer in SQL queries? (#40755)"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(is (= [[#t "2024-07-03"]]
(mt/rows
(qp/process-query
@@ -1884,7 +1879,7 @@
:middleware {:format-rows? false}})))))))
(deftest ^:parallel xml-column-is-readable-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(let [xml-str "<abc>abc</abc>"]
(is (= [[xml-str]]
(mt/rows
@@ -1894,7 +1889,7 @@
:native {:query (format "SELECT '%s'::xml" xml-str)}})))))))
(deftest ^:parallel temporal-column-with-binning-keeps-type
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(let [mp (mt/metadata-provider)]
(doseq [[field bins] [[:birth_date [:year :quarter :month :week :day]]
[:created_at [:year :quarter :month :week :day :hour :minute]]]
@@ -1910,7 +1905,7 @@
(->> binned-query qp/process-query mt/cols (map :database_type))))))))))
(deftest ^:parallel datetime-diff-works-for-all-units
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(let [mp (mt/metadata-provider)]
(doseq [[field units] [[:birth_date [:year :quarter :month :week :day]]
[:created_at [:year :quarter :month :week :day :hour :minute :second]]]
@@ -1925,7 +1920,7 @@
(is (->> query qp/process-query mt/rows))))))))
(deftest have-select-privelege?-timeout-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(let [{schema :schema, table-name :name} (t2/select-one :model/Table (mt/id :checkins))]
(qp.store/with-metadata-provider (mt/id)
(testing "checking select privilege defaults to allow on timeout (#56737)"
@@ -1940,7 +1935,7 @@
driver/*driver* conn schema table-name))))))))))))
(deftest sync-writable-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "`sync-tables-and-database!` should set is_writable correctly based on table privileges"
(let [db-name "sync_writable_test"
details (tx/dbdef->connection-details :postgres :db {:database-name db-name})]
@@ -1983,7 +1978,7 @@
(deftest ^:parallel null-array-query-test
(testing "queries with nulls in arrays should be returned in a readable format"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(is (= [[[nil]
[nil nil]
[1 nil 3]
@@ -1999,7 +1994,7 @@
(deftest ^:parallel arrays-have-base-type
(testing "queries with pg arrays have a base type on column metadata (#63909)"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(is (=? [{:name "id"
:database_type "int4"
:base_type :type/Integer}
@@ -2018,7 +2013,7 @@
(deftest can-edit-model-metadata
(testing "queries with pg arrays have a base type on column metadata (#63909)"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(let [query "SELECT *
FROM (
VALUES
@@ -2070,7 +2065,7 @@
(is (= provider (provider-detection/detect-provider-from-database database))))))))
(deftest ^:parallel complex-types-in-notification-payload
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "we handle complex types in notifications"
(let [sql "SELECT
i AS id,
@@ -2132,7 +2127,7 @@
(deftest bytea-column-not-truncated-test
(testing "fix for #30671"
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/dataset (mt/dataset-definition
"bytea_dataset"
[["bytea_table"
@@ -2166,10 +2161,10 @@
(test-pgobject-caching pg-obj-map)))))
(deftest canceled-query-no-stacktrace-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(letfn [(catch-exceptions [run]
(let [query (cond-> {:type :query, :database 1}
- (= driver/*driver* :postgres-mbql5) (lib.convert/->mbql5))
+ (= driver/*driver* :postgres) (lib.convert/->mbql5))
metadata {}
rows []
qp (fn [query rff]
@@ -2222,7 +2217,7 @@
(is (empty? bad-messages)))))))))))
(deftest bit-strings-can-be-filtered
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(mt/dataset (mt/dataset-definition
"bit_string_dataset"
[["bit_string_table"
@@ -2289,36 +2284,32 @@
(mt/rows (qp/process-query query)))))))))))
(deftest set-network-timeout-test
- (mt/test-driver *driver*
- (let [db-name (u/lower-case-en (format "network-timeout-%s-%s" (name driver/*driver*) (mt/random-name)))
- spec (sql-jdbc.conn/connection-details->spec
- driver/*driver*
- (mt/dbdef->connection-details driver/*driver* :db {:database-name db-name}))]
- (tx/with-temp-database! driver/*driver* db-name
- ;; Use a raw spec against a unique DB; the shared test-data DB can be created/dropped by concurrent
- ;; :postgres and :postgres-mbql5 test setup.
- (letfn [(run-pg-sleep []
- (sql-jdbc.execute/do-with-connection-with-options
- driver/*driver* spec nil
- (fn [^Connection conn]
- (with-open [stmt (.createStatement conn)]
- (.execute stmt "SELECT pg_sleep(6)")))))]
- (testing "network hangs are interrupted after *network-timeout-ms*"
- (binding [driver.settings/*network-timeout-ms* 3000]
- (is (thrown-with-msg?
- org.postgresql.util.PSQLException
- #"An I/O error occurred while sending to the backend"
- (try
- (run-pg-sleep)
- (catch Exception e
- (is (true? (some #(instance? java.net.SocketTimeoutException %)
- (u/full-exception-chain e))))
- (throw e)))))))
- (testing "network hangs are not interrupted before *network-timeout-ms*"
- (is (true? (run-pg-sleep)))))))))
+ (mt/test-driver :postgres
+ (testing "network hangs are interrupted after *network-timeout-ms*"
+ (binding [driver.settings/*network-timeout-ms* 3000]
+ (is (thrown-with-msg?
+ org.postgresql.util.PSQLException
+ #"An I/O error occurred while sending to the backend"
+ (try
+ (sql-jdbc.execute/do-with-connection-with-options
+ driver/*driver* (mt/id) nil
+ (fn [^Connection conn]
+ (with-open [stmt (.createStatement conn)]
+ (.execute stmt "SELECT pg_sleep(6)"))))
+ (catch Exception e
+ (is (true? (some #(instance? java.net.SocketTimeoutException %)
+ (u/full-exception-chain e))))
+ (throw e)))))))
+ (testing "network hangs are not interrupted before *network-timeout-ms*"
+ (is (true?
+ (sql-jdbc.execute/do-with-connection-with-options
+ driver/*driver* (mt/id) nil
+ (fn [^Connection conn]
+ (with-open [stmt (.createStatement conn)]
+ (.execute stmt "SELECT pg_sleep(6)")))))))))
(deftest ^:parallel parse-final-identifier-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "`final` is allowed as identifier and parsed correctly"
(mt/with-temp [:model/Database db {:engine "postgres"
:name "final"
@@ -2365,7 +2356,7 @@
(sql.u/quote-name :postgres :field ~role))]))))
(deftest workspace-precondition-usage-grant-option-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "assert-has-usage-grant-option! throws when current_user lacks USAGE WITH GRANT OPTION on the schema"
(mt/with-empty-db
(let [admin-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))
@@ -2396,7 +2387,7 @@
(is (nil? (postgres/assert-has-usage-grant-option! user-spec schema)))))))))))))
(deftest workspace-precondition-table-grant-option-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "assert-has-grant-option! throws when current_user lacks SELECT WITH GRANT OPTION on a schema table"
(mt/with-empty-db
(let [admin-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))
@@ -2433,7 +2424,7 @@
(is (nil? (postgres/assert-has-grant-option! user-spec schema)))))))))))))
(deftest workspace-precondition-alter-default-privileges-test
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "assert-can-alter-default-privileges! throws when an object owner is not a role the current_user belongs to"
(mt/with-empty-db
(let [admin-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))
@@ -2479,7 +2470,7 @@
;; row targeting the iso-user and confirm `destroy-workspace-isolation!`
;; still cleans up without raising "user cannot be dropped because some
;; objects depend on it".
- (mt/test-driver *driver*
+ (mt/test-driver :postgres
(testing "destroy succeeds when a non-current_user grantor seeded a default-priv targeting the iso-user"
(mt/with-empty-db
(let [admin-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))
diff --git a/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj b/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj
index 9fe7a7b2616..7d391056827 100644
--- a/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj
+++ b/test/metabase/driver/sql_jdbc/sync/describe_table_test.clj
@@ -508,26 +508,19 @@
{:short_json {"b" "y"}, :long_json nil}}
(sample)))
(testing "If driver.sql/json-field-length is not implemented for the driver don't omit the long value"
- ;; Temporarily override json-field-length with the default (nyi) implementation.
- ;; We can't just remove-method — for child drivers (e.g. :postgres-mbql5) the
- ;; parent's method would still be inherited.
- (let [default-method (get-method driver.sql/json-field-length :default)
- original-method (get-method driver.sql/json-field-length driver/*driver*)
- had-explicit? (contains? (methods driver.sql/json-field-length) driver/*driver*)]
- (defmethod driver.sql/json-field-length driver/*driver* [driver field]
- (default-method driver field))
- (try
- (is (= #{{:short_json {"a" "x"}, :long_json {"a" "x"}}
- {:short_json {"b" "y"}, :long_json {"b" "yyyyyyyyyy"}}}
- (sample)))
- (finally
- (remove-method driver.sql/json-field-length driver/*driver*)
- ;; Re-install the original if there was an explicit method (not just inherited).
- ;; For inherited methods (e.g. :postgres-mbql5), remove-method is enough —
- ;; the parent's method resumes via hierarchy dispatch.
- (when had-explicit?
- (defmethod driver.sql/json-field-length driver/*driver* [driver field]
- (original-method driver field)))))))
+ (letfn [(do-with-removed-method [thunk]
+ (let [original-method (get-method driver.sql/json-field-length driver/*driver*)]
+ (if (= original-method (get-method driver.sql/json-field-length :default))
+ (thunk)
+ (do (remove-method driver.sql/json-field-length driver/*driver*)
+ (thunk)
+ (defmethod driver.sql/json-field-length driver/*driver* [driver field]
+ (original-method driver field))))))]
+ (do-with-removed-method
+ (fn []
+ (is (= #{{:short_json {"a" "x"}, :long_json {"a" "x"}}
+ {:short_json {"b" "y"}, :long_json {"b" "yyyyyyyyyy"}}}
+ (sample)))))))
(testing "The resulting synced fields exclude the field that corresponds to the long value"
(is (= #{"id"
"short_json"
diff --git a/test/metabase/test/data/h2_mbql5.clj b/test/metabase/test/data/h2_mbql5.clj
deleted file mode 100644
index e43e78486b4..00000000000
--- a/test/metabase/test/data/h2_mbql5.clj
+++ /dev/null
@@ -1,2 +0,0 @@
-(ns metabase.test.data.h2-mbql5
- "Placeholder; delete me once experimental-mbql5-driver goes away.")
diff --git a/test/metabase/test/data/postgres_mbql5.clj b/test/metabase/test/data/postgres_mbql5.clj
deleted file mode 100644
index b04d8725fae..00000000000
--- a/test/metabase/test/data/postgres_mbql5.clj
+++ /dev/null
@@ -1,2 +0,0 @@
-(ns metabase.test.data.postgres-mbql5
- "Placeholder; delete once mainline postgres does mbql5")