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

Just use default impl of table-rows-sample for Druid [ci drivers]

parent 7a46cfcb
Branches
Tags
No related merge requests found
......@@ -194,20 +194,25 @@
;; TODO - Not 100% sure we need this method since it seems like we could just use an MBQL query to fetch this info.
(table-rows-sample ^clojure.lang.Sequential [this, ^TableInstance table, fields]
"Return a sample of rows in TABLE with the specified FIELDS. This is used to implement some methods of the
"*OPTIONAL*. Return a sample of rows in TABLE with the specified FIELDS. This is used to implement some methods of the
database sync process which require rows of data during execution. At this time, this should just return a basic
sequence of rows in the fastest way possible, with no special sorting or any sort of randomization done to ensure
a good sample. (Improved sampling is something we plan to add in the future.)
The sample should return up to `max-sample-rows` rows, which is currently `10000`."))
(defn- table-rows-sample-via-qp [_ table fields]
(let [results ((resolve 'metabase.query-processor/process-query) {:database (:db_id table)
:type :query
:query {:source-table (u/get-id table)
:fields (vec (for [field fields]
[:field-id (u/get-id field)]))
:limit max-sample-rows}})]
(defn- table-rows-sample-via-qp
"Default implementation of `table-rows-sample` that just runs a basic MBQL query to fetch values for a Table.
Prefer this to writing your own implementation of `table-rows-sample`; those are around for purely historical
reasons and may be removed in the future."
[_ table fields]
(let [results ((resolve 'metabase.query-processor/process-query)
{:database (:db_id table)
:type :query
:query {:source-table (u/get-id table)
:fields (vec (for [field fields]
[:field-id (u/get-id field)]))
:limit max-sample-rows}})]
(get-in results [:data :rows])))
......
......@@ -63,7 +63,6 @@
(let [message (or (u/ignore-exceptions
(:error (json/parse-string (:body (:object (ex-data e))) keyword)))
(.getMessage e))]
(log/error (u/format-color 'red "Error running query:\n%s" message))
;; Re-throw a new exception with `message` set to the extracted message
(throw (Exception. message e)))))))
......@@ -100,23 +99,6 @@
{:schema nil, :name table-name}))})))
;;; ### table-rows-sample
(defn- table-rows-sample [table fields]
(let [db-details (db/select-one-field :details Database :id (:db_id table))
[results] (do-query db-details {:queryType :select
:dataSource (:name table)
:intervals ["1900-01-01/2100-01-01"]
:granularity :all
:dimensions (map :name fields)
:metrics []
:pagingSpec {:threshold driver/max-sample-rows}})]
;; Unnest the values
(for [event (get-in results [:result :events])]
(for [field fields]
(get-in event [:event (keyword (:name field))])))))
;;; ### DruidrDriver Class Definition
(defrecord DruidDriver []
......@@ -139,10 +121,9 @@
:default 8082}]))
:execute-query (fn [_ query] (qp/execute-query do-query query))
:features (constantly #{:basic-aggregations :set-timezone :expression-aggregations})
:table-rows-sample (u/drop-first-arg table-rows-sample)
:mbql->native (u/drop-first-arg qp/mbql->native)}))
(defn -init-driver
"Register the druid driver1"
"Register the druid driver."
[]
(driver/register-driver! :druid (DruidDriver.)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment