Skip to content
Snippets Groups Projects
Commit edc3443c authored by Cam Saul's avatar Cam Saul
Browse files

some mysql fixes. dataset-case macro

parent 40200784
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,12 @@
:VARCHAR :TextField
:YEAR :IntegerField})
(defn- -cast-timestamp-to-date [_ table-name field-name seconds-or-milliseconds]
(format (case seconds-or-milliseconds
:seconds "CAST(TIMESTAMPADD(SECOND, `%s`.`%s`, DATE '1970-01-01') AS DATE)"
:milliseconds "CAST(TIMESTAMPADD(MICROSECOND, (`%s`.`%s` * 1000), DATE '1970-01-01') AS DATE)" )
table-name field-name))
(defrecord MySQLDriver []
ISqlDriverDatabaseSpecific
(connection-details->connection-spec [_ details]
......@@ -69,11 +75,7 @@
details)
(cast-timestamp-to-date [_ table-name field-name seconds-or-milliseconds]
(format "CAST(TIMESTAMPADD(%s, `%s`.`%s`, DATE '1970-01-01') AS DATE)"
(case seconds-or-milliseconds
:seconds "SECOND"
:milliseconds "MILLISECOND")
table-name field-name))
(-cast-timestamp-to-date _ table-name field-name seconds-or-milliseconds))
(timezone->set-timezone-sql [_ timezone]
;; If this fails you need to load the timezone definitions from your system into MySQL;
......
......@@ -562,19 +562,15 @@
;;; SQL-Only for the time being
;; ## "STDDEV" AGGREGATION
(qp-expect-with-datasets #{:h2}
(qp-expect-with-datasets #{:h2 :postgres :mysql}
{:columns ["stddev"]
:cols [(aggregate-col :stddev (venues-col :latitude))]
:rows [[3.43467255295115]]}
:rows [[(datasets/dataset-case
:h2 3.43467255295115 ; annoying :/
:postgres 3.4346725529512736
:mysql 3.417456040761316)]]}
(Q aggregate stddev latitude of venues))
(qp-expect-with-datasets #{:postgres :mysql}
{:columns ["stddev"]
:cols [(aggregate-col :stddev (venues-col :latitude))]
:rows [[3.4346725529512736]]}
(Q aggregate stddev latitude
of venues))
;; Make sure standard deviation fails for the Mongo driver since its not supported
(datasets/expect-with-dataset :mongo
{:status :failed
......
......@@ -270,3 +270,16 @@
`*dataset*` is bound to the current dataset inside each test."
[expected actual]
`(expect-with-datasets ~all-valid-dataset-names ~expected ~actual))
(defmacro dataset-case
"Case statement that switches off of the current dataset.
(dataset-case
:h2 ...
:postgres ...)"
[& pairs]
`(cond ~@(mapcat (fn [[dataset then]]
(assert (contains? all-valid-dataset-names dataset))
[`(= *dataset* (dataset-name->dataset ~dataset))
then])
(partition 2 pairs))))
......@@ -2,6 +2,7 @@
(:refer-clojure :exclude [or and filter use = != < > <= >=])
(:require [clojure.core :as core]
[clojure.core.match :refer [match]]
[metabase.db :as db]
[metabase.driver :as driver]
[metabase.test.data :as data]
(metabase.test.data [datasets :as datasets]
......@@ -261,11 +262,12 @@
(defmacro Q** [{:keys [driver dataset return table-name]} query]
(assert table-name
"Table name not specified in query, did you include an 'of' clause?")
`(->> (with-driver ~driver
(binding [*table-name* ~table-name]
(with-temp-db ~dataset
(driver/process-query ~query))))
~@return))
`(do (db/setup-db-if-needed)
(->> (with-driver ~driver
(binding [*table-name* ~table-name]
(with-temp-db ~dataset
(driver/process-query ~query))))
~@return)))
(defmacro Q* [q & [form & more]]
(if-not form
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment