Skip to content
Snippets Groups Projects
Unverified Commit 9771eaa2 authored by metamben's avatar metamben Committed by GitHub
Browse files

Migrate druid metrics-inside-aggregation-clauses-test to druid-jdbc (#42653)

* Migrate druid metrics-inside-aggregation-clauses-test to druid-jdbc
* Fix test-runner: druid should not exclude druid-jdbc
* Implement set-parameter and unprepare-value for LocalDateTime for druid-jdbc
parent c69596ab
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@
[metabase.util.log :as log])
(:import
(java.sql ResultSet Types)
(java.time ZonedDateTime)))
(java.time LocalDateTime ZonedDateTime)))
(set! *warn-on-reflection* true)
......@@ -113,13 +113,23 @@
host)
port))
(defn- format-datetime [t] (t/format "yyyy-MM-dd HH:mm:ss.SSS" t))
(defmethod sql-jdbc.execute/set-parameter [:druid-jdbc ZonedDateTime]
[driver ps i t]
(sql-jdbc.execute/set-parameter driver ps i (t/format "yyyy-MM-dd HH:mm:ss.SSS" t)))
(sql-jdbc.execute/set-parameter driver ps i (format-datetime t)))
(defmethod unprepare/unprepare-value [:druid-jdbc ZonedDateTime]
[_driver t]
(format "'%s'" (t/format "yyyy-MM-dd HH:mm:ss.SSS" t)))
(format "'%s'" (format-datetime t)))
(defmethod sql-jdbc.execute/set-parameter [:druid-jdbc LocalDateTime]
[driver ps i t]
(sql-jdbc.execute/set-parameter driver ps i (format-datetime t)))
(defmethod unprepare/unprepare-value [:druid-jdbc LocalDateTime]
[_driver t]
(format "'%s'" (format-datetime t)))
(defmethod sql.qp/json-query :druid-jdbc
[_driver unwrapped-identifier nfc-field]
......
(ns metabase.driver.druid-jdbc.query-processor-test
(:require
[clojure.test :refer :all]
[metabase.models :refer [Card]]
[metabase.test :as mt]
[metabase.timeseries-query-processor-test.util :as tqpt]
[toucan2.tools.with-temp :as t2.with-temp]))
(deftest metrics-inside-aggregation-clauses-test
(mt/test-driver :druid-jdbc
(testing "check that we can handle METRICS inside expression aggregation clauses"
(tqpt/with-flattened-dbdef
(t2.with-temp/with-temp [Card {metric-id :id} {:dataset_query
(mt/mbql-query checkins
{:aggregation [:sum $venue_price]
:filter [:> $venue_price 1]
:source-table (mt/id :checkins)})
:type :metric}]
(is (= [[2 1231]
[3 346]
[4 197]]
(mt/rows
(mt/run-mbql-query checkins
{:aggregation [:+ [:metric metric-id] 1]
:breakout [$venue_price]
:source-table (str "card__" metric-id)})))))))))
......@@ -14,8 +14,7 @@
[metabase.test :as mt]
[metabase.timeseries-query-processor-test.util :as tqpt]
[metabase.util :as u]
[toucan2.core :as t2]
[toucan2.tools.with-temp :as t2.with-temp]))
[toucan2.core :as t2]))
(set! *warn-on-reflection* true)
......@@ -366,21 +365,6 @@
(mt/mbql-query checkins
{:aggregation [[:distinct [:+ $id $venue_price]]]})))))))
(deftest metrics-inside-aggregation-clauses-test
(tqpt/test-timeseries-drivers
(testing "check that we can handle METRICS inside expression aggregation clauses"
(t2.with-temp/with-temp [:model/Metric metric {:definition (mt/$ids checkins
{:aggregation [:sum $venue_price]
:filter [:> $venue_price 1]})
:table_id (mt/id :checkins)}]
(is (= [[2 1231]
[3 346]
[4 197]]
(-> (mt/run-mbql-query checkins
{:aggregation [:+ [:metric (u/the-id metric)] 1]
:breakout [$venue_price]})
mt/rows)))))))
(deftest order-by-aggregation-test
(tqpt/test-timeseries-drivers
(doseq [[direction expected-rows] {:desc [["Bar" "Felipinho Asklepios" 8]
......
......@@ -9,7 +9,7 @@
[metabase.db.metadata-queries :as metadata-queries]
[metabase.driver :as driver]
[metabase.driver.druid.query-processor :as druid.qp]
[metabase.models :refer [#_Card Field Table]]
[metabase.models :refer [Field Table]]
[metabase.query-processor :as qp]
[metabase.query-processor.compile :as qp.compile]
[metabase.test :as mt]
......@@ -542,26 +542,6 @@
(druid-query
{:aggregation [[:distinct [:+ $id $checkins.venue_price]]]}))))))
;; FIXME metrics v2
#_(deftest metrics-inside-aggregation-clauses-test
(mt/test-driver :druid
(testing "check that we can handle METRICS inside expression aggregation clauses"
(tqpt/with-flattened-dbdef
(t2.with-temp/with-temp [Card {metric-id :id} {:dataset_query
(mt/mbql-query checkins
{:aggregation [:sum $venue_price]
:filter [:> $venue_price 1]
:source-table (mt/id :checkins)})
:type :metric}]
(is (= [["2" 1231.0]
["3" 346.0]
["4" 197.0]]
(mt/rows
(mt/run-mbql-query checkins
{:aggregation [:+ [:metric metric-id] 1]
:breakout [$venue_price]
:source-table (str "card__" metric-id)})))))))))
(deftest order-by-aggregation-test
(mt/test-driver :druid
(doseq [[direction expected-rows] {:desc [["Bar" "Felipinho Asklepios" 8]
......
......@@ -58,8 +58,11 @@
(let [excluded-driver-dirs (for [driver (excluded-drivers)]
(format "modules/drivers/%s" (name driver)))
exclude-directory? (fn [dir]
(some (partial str/includes? (str dir))
excluded-driver-dirs))
(let [dir (str dir)]
(some (fn [excluded]
(or (str/ends-with? dir excluded)
(str/includes? dir (str excluded "/"))))
excluded-driver-dirs)))
directories (for [^java.io.File file (classpath/system-classpath)
:when (and (.isDirectory file)
(not (exclude-directory? file)))]
......
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