Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for #7435 [ci bigquery] #11060

Merged
merged 3 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/drivers/bigquery/test/metabase/driver/bigquery_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,15 @@
:query {:source-table (data/id view-name)
:order-by [[:asc (data/id view-name :id)]]}})))
"We should be able to run queries against the view (#3414)"))))

(deftest timezones-test
(datasets/test-driver :bigquery
(testing "BigQuery does not support report-timezone, so setting it should not affect results"
(doseq [timezone ["UTC" "US/Pacific"]]
(tu/with-temporary-setting-values [report-timezone timezone]
(is (= [[37 "2015-11-19T00:00:00.000Z"]]
(qp.test/rows
(data/run-mbql-query checkins
{:fields [$id $date]
:filter [:= $date "2015-11-19"]
:order-by [[:asc $id]]})))))))))
23 changes: 16 additions & 7 deletions modules/drivers/vertica/test/metabase/test/data/vertica.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,19 @@
(jdbc/execute! (dbspec) (format "ALTER DATABASE \"%s\" SET MaxClientSessions = 10000;" (db-name))))

(defmethod tx/create-db! :vertica [driver dbdef & options]
(let [m (get-method tx/create-db! :sql-jdbc/test-extensions)]
(try
(apply m driver dbdef options)
(catch Throwable e
(println (colorize/red "\n\nVertica failed to create a DB, again. Let's try again...\n\n"))
(jdbc/query (dbspec) "SELECT CLOSE_ALL_SESSIONS();")
(apply m driver dbdef options)))))
(letfn [(create-with-retries! [retries]
(let [results (try
(apply (get-method tx/create-db! :sql-jdbc/test-extensions) driver dbdef options)
(catch Throwable e
(if (pos? retries)
::retry
(throw e))))]
(if (not= results ::retry)
results
(do
(println (colorize/red "\n\nVertica failed to create a DB, again. Let's try again...\n\n"))
(jdbc/query (dbspec) "SELECT CLOSE_ALL_SESSIONS();")
(recur (dec retries))))))]
;; try a few times to create the DB. Vertica is very fussy and sometimes you need to try a few times to get it to
;; work correctly.
(create-with-retries! 5)))
2 changes: 1 addition & 1 deletion test/metabase/query_processor_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
"Return the result `:cols` from query `results`, or throw an Exception if they're missing."
{:style/indent 0}
[results]
(or (some-> (data results) :cols vec)
(or (some->> (data results) :cols (mapv #(into {} %)))
(throw (ex-info "Query does not have any :cols in results." results))))

(defn rows-and-cols
Expand Down
70 changes: 37 additions & 33 deletions test/metabase/query_processor_test/order_by_test.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns metabase.query-processor-test.order-by-test
"Tests for the `:order-by` clause."
(:require [clojure.math.numeric-tower :as math]
(:require [clojure.test :refer :all]
[metabase
[driver :as driver]
[query-processor-test :as qp.test]]
[query-processor-test :as qp.test :refer :all]]
[metabase.test.data :as data]
[metabase.test.data.datasets :as datasets]))

Expand Down Expand Up @@ -77,35 +77,39 @@
:breakout [$price]
:order-by [[:asc [:aggregation 0]]]}))))

(deftest order-by-average-aggregation-test
(datasets/test-drivers qp.test/non-timeseries-drivers
(let [{:keys [rows cols]} (qp.test/rows-and-cols
(qp.test/format-rows-by [int 1.0]
(data/run-mbql-query venues
{:aggregation [[:avg $category_id]]
:breakout [$price]
:order-by [[:asc [:aggregation 0]]]})))
driver-floors-average? (#{:h2 :redshift :sqlserver} driver/*driver*)]
(is (= [[3 22.0]
[2 (if driver-floors-average? 28.0 28.3)]
[1 (if driver-floors-average? 32.0 32.8)]
[4 (if driver-floors-average? 53.0 53.5)]]
rows))
(is (= [(qp.test/breakout-col :venues :price)
(qp.test/aggregate-col :avg :venues :category_id)]
cols)))))

;;; order-by aggregate ["avg" field-id]
(qp.test/expect-with-non-timeseries-dbs
{:rows [[3 22]
[2 28]
[1 32]
[4 53]]
:cols [(qp.test/breakout-col :venues :price)
(qp.test/aggregate-col :avg :venues :category_id)]}
(qp.test/rows-and-cols
(qp.test/format-rows-by [int int]
(data/run-mbql-query venues
{:aggregation [[:avg $category_id]]
:breakout [$price]
:order-by [[:asc [:aggregation 0]]]}))))

;;; ### order-by aggregate ["stddev" field-id]
;; SQRT calculations are always NOT EXACT (normal behavior) so round everything to the nearest int.
;; Databases might use different versions of SQRT implementations
(datasets/expect-with-drivers (qp.test/non-timeseries-drivers-with-feature :standard-deviation-aggregations)
{:rows [[3 (if (= :mysql driver/*driver*) 25 26)]
[1 24]
[2 21]
[4 (if (= :mysql driver/*driver*) 14 15)]]
:cols [(qp.test/breakout-col :venues :price)
(qp.test/aggregate-col :stddev (qp.test/col :venues :category_id))]}
(qp.test/rows-and-cols
(qp.test/format-rows-by [int (comp int math/round)]
(data/run-mbql-query venues
{:aggregation [[:stddev $category_id]]
:breakout [$price]
:order-by [[:desc [:aggregation 0]]]}))))
(deftest order-by-standard-deviation-aggregation-test
(datasets/test-drivers (qp.test/non-timeseries-drivers-with-feature :standard-deviation-aggregations)
(let [{:keys [rows cols]} (qp.test/rows-and-cols
(qp.test/format-rows-by [int 0.0]
(data/run-mbql-query venues
{:aggregation [[:stddev $category_id]]
:breakout [$price]
:order-by [[:desc [:aggregation 0]]]})))]
;; standard deviation calculations are always NOT EXACT (normal behavior) so round results to nearest whole
;; number.
(is (= [[3 (if (= driver/*driver* :mysql) 25.0 26.0)]
[1 24.0]
[2 21.0]
[4 (if (= driver/*driver* :mysql) 14.0 15.0)]]
rows))
(is (= [(qp.test/breakout-col :venues :price)
(qp.test/aggregate-col :stddev (qp.test/col :venues :category_id))]
cols)))))