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

Easier configuration of custom ClickHouse settings #272

Merged
merged 3 commits into from
Sep 25, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.50.7

### Improvements

* Added a configuration field (under the "advanced options", hidden by default) to override certain ClickHouse settings ([#272](https://github.com/ClickHouse/metabase-clickhouse-driver/pull/272)).

# 1.50.6

### Bug fixes
Expand Down
9 changes: 7 additions & 2 deletions resources/metabase-plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
info:
name: Metabase ClickHouse Driver
version: 1.50.6
version: 1.50.7
description: Allows Metabase to connect to ClickHouse databases.
contact-info:
name: ClickHouse
Expand Down Expand Up @@ -36,9 +36,14 @@ driver:
type: boolean
visible-if:
advanced-options: true
- name: clickhouse-settings
display-name: ClickHouse settings (comma-separated)
placeholder: "allow_experimental_analyzer=1,max_result_rows=100"
visible-if:
advanced-options: true
- merge:
- additional-options
- placeholder: "connection_timeout=1000&max_rows_to_group_by=42"
- placeholder: "connection_timeout=1000&socket_timeout=300000"
- default-advanced-options
connection-properties-include-tunnel-config: true
init:
Expand Down
8 changes: 5 additions & 3 deletions src/metabase/driver/clickhouse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
(driver/register! :clickhouse :parent #{:sql-jdbc})

(defmethod driver/display-name :clickhouse [_] "ClickHouse")
(def ^:private product-name "metabase/1.50.6")
(def ^:private product-name "metabase/1.50.7")

(defmethod driver/prettify-native-form :clickhouse
[_ native-form]
Expand All @@ -55,7 +55,7 @@
details (reduce-kv (fn [m k v] (assoc m k (or v (k default-connection-details))))
default-connection-details
details)
{:keys [user password dbname host port ssl use-no-proxy]} details
{:keys [user password dbname host port ssl use-no-proxy clickhouse-settings]} details
;; if multiple databases were specified for the connection,
;; use only the first dbname as the "main" one
dbname (first (str/split (str/trim dbname) #" "))]
Expand All @@ -74,7 +74,9 @@
;; and https://github.com/ClickHouse/clickhouse-java/issues/1634#issuecomment-2110392634
:databaseTerm "schema"
:remember_last_set_roles true
:http_connection_provider "HTTP_URL_CONNECTION"}
:http_connection_provider "HTTP_URL_CONNECTION"
;; see also: https://clickhouse.com/docs/en/integrations/java#configuration
:custom_http_params (or clickhouse-settings "")}
(sql-jdbc.common/handle-additional-options details :separator-style :url))))

(defmethod sql-jdbc.execute/do-with-connection-with-options :clickhouse
Expand Down
6 changes: 4 additions & 2 deletions test/metabase/driver/clickhouse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
:user "bob"
:password "qaz"
:use_no_proxy true
:ssl true})
:ssl true
:custom_http_params "max_threads=42,allow_experimental_analyzer=0"})
(sql-jdbc.conn/connection-details->spec
:clickhouse
{:host "myclickhouse"
Expand All @@ -65,7 +66,8 @@
:dbname "foo"
:use-no-proxy true
:additional-options "sessionTimeout=42"
:ssl true}))))
:ssl true
:clickhouse-settings "max_threads=42,allow_experimental_analyzer=0"}))))
(testing "nil dbname handling"
(is (= ctd/default-connection-params
(sql-jdbc.conn/connection-details->spec
Expand Down
8 changes: 3 additions & 5 deletions test/metabase/test/data/clickhouse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
:ssl false
:use_no_proxy false
:use_server_time_zone_for_dates true
:product_name "metabase/1.50.6"
:product_name "metabase/1.50.7"
:databaseTerm "schema"
:remember_last_set_roles true
:http_connection_provider "HTTP_URL_CONNECTION"})

;; (def ^:private time-type-comment "COMMENT 'time'")
;; (def ^:private time-type (format "DateTime64(3) %s" time-type-comment))
:http_connection_provider "HTTP_URL_CONNECTION"
:custom_http_params ""})

(defmethod sql.tx/field-base-type->sql-type [:clickhouse :type/Boolean] [_ _] "Boolean")
(defmethod sql.tx/field-base-type->sql-type [:clickhouse :type/BigInteger] [_ _] "Int64")
Expand Down