|
3 | 3 | #_{:clj-kondo/ignore [:unsorted-required-namespaces]}
|
4 | 4 | (:require [clojure.core.memoize :as memoize]
|
5 | 5 | [clojure.string :as str]
|
6 |
| - [honey.sql :as sql] |
7 | 6 | [metabase.config :as config]
|
8 | 7 | [metabase.driver :as driver]
|
9 | 8 | [metabase.driver.clickhouse-introspection]
|
|
12 | 11 | [metabase.driver.clickhouse-version :as clickhouse-version]
|
13 | 12 | [metabase.driver.ddl.interface :as ddl.i]
|
14 | 13 | [metabase.driver.sql :as driver.sql]
|
| 14 | + [metabase.driver.sql-jdbc :as sql-jdbc] |
15 | 15 | [metabase.driver.sql-jdbc.common :as sql-jdbc.common]
|
16 | 16 | [metabase.driver.sql-jdbc.connection :as sql-jdbc.conn]
|
17 | 17 | [metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
|
18 |
| - [metabase.driver.sql.query-processor :as sql.qp] |
19 | 18 | [metabase.driver.sql.util :as sql.u]
|
20 | 19 | [metabase.lib.metadata :as lib.metadata]
|
21 | 20 | [metabase.query-processor.store :as qp.store]
|
|
29 | 28 | (driver/register! :clickhouse :parent #{:sql-jdbc})
|
30 | 29 |
|
31 | 30 | (defmethod driver/display-name :clickhouse [_] "ClickHouse")
|
32 |
| -(def ^:private product-name "metabase/1.50.7") |
| 31 | +(def ^:private product-name "metabase/1.51.0") |
33 | 32 |
|
34 | 33 | (defmethod driver/prettify-native-form :clickhouse
|
35 | 34 | [_ native-form]
|
36 | 35 | (sql.u/format-sql-and-fix-params :mysql native-form))
|
37 | 36 |
|
38 | 37 | (doseq [[feature supported?] {:standard-deviation-aggregations true
|
39 |
| - :foreign-keys (not config/is-test?) |
40 | 38 | :now true
|
41 | 39 | :set-timezone true
|
42 | 40 | :convert-timezone true
|
43 | 41 | :test/jvm-timezone-setting false
|
| 42 | + :test/time-type false |
44 | 43 | :schemas true
|
45 | 44 | :datetime-diff true
|
46 | 45 | :upload-with-auto-pk false
|
47 |
| - :window-functions/offset false}] |
| 46 | + :window-functions/offset false |
| 47 | + :window-functions/cumulative (not config/is-test?) |
| 48 | + :left-join (not config/is-test?) |
| 49 | + :describe-fks false |
| 50 | + :metadata/key-constraints false}] |
48 | 51 | (defmethod driver/database-supports? [:clickhouse feature] [_driver _feature _db] supported?))
|
49 | 52 |
|
50 | 53 | (def ^:private default-connection-details
|
|
190 | 193 |
|
191 | 194 | (defmethod ddl.i/format-name :clickhouse
|
192 | 195 | [_ table-or-field-name]
|
193 |
| - (str/replace table-or-field-name #"-" "_")) |
| 196 | + (when table-or-field-name |
| 197 | + (str/replace table-or-field-name #"-" "_"))) |
194 | 198 |
|
195 | 199 | ;;; ------------------------------------------ Connection Impersonation ------------------------------------------
|
196 | 200 |
|
|
219 | 223 | (defn- create-table!-sql
|
220 | 224 | "Creates a ClickHouse table with the given name and column definitions. It assumes the engine is MergeTree,
|
221 | 225 | so it only works with Clickhouse Cloud and single node on-premise deployments at the moment."
|
222 |
| - [driver table-name column-definitions & {:keys [primary-key]}] |
| 226 | + [_driver table-name column-definitions & {:keys [primary-key] :as opts}] |
223 | 227 | (str/join "\n"
|
224 |
| - [(first (sql/format {:create-table (keyword table-name) |
225 |
| - :with-columns (mapv (fn [[name type-spec]] |
226 |
| - (vec (cons name [[:raw type-spec]]))) |
227 |
| - column-definitions)} |
228 |
| - :quoted true |
229 |
| - :dialect (sql.qp/quote-style driver))) |
| 228 | + [(#'sql-jdbc/create-table!-sql :sql-jdbc table-name column-definitions opts) |
230 | 229 | "ENGINE = MergeTree"
|
231 | 230 | (format "ORDER BY (%s)" (str/join ", " (map quote-name primary-key)))
|
232 | 231 | ;; disable insert idempotency to allow duplicate inserts
|
|
261 | 260 | (when (seq row)
|
262 | 261 | (doseq [[idx v] (map-indexed (fn [x y] [(inc x) y]) row)]
|
263 | 262 | (condp isa? (type v)
|
| 263 | + nil (.setString ps idx nil) |
264 | 264 | java.lang.String (.setString ps idx v)
|
265 | 265 | java.lang.Boolean (.setBoolean ps idx v)
|
266 | 266 | java.lang.Long (.setLong ps idx v)
|
|
293 | 293 | quoted-role (->> (clojure.string/split role #",")
|
294 | 294 | (map quote-if-needed)
|
295 | 295 | (clojure.string/join ","))]
|
296 |
| - (format "SET ROLE %s;" quoted-role)) |
297 |
| - ) |
| 296 | + (format "SET ROLE %s;" quoted-role))) |
298 | 297 |
|
299 | 298 | (defmethod driver.sql/default-database-role :clickhouse
|
300 | 299 | [_ _]
|
|
0 commit comments