Skip to content

Commit

Permalink
Display Arrays (#17)
Browse files Browse the repository at this point in the history
fix for #11
  • Loading branch information
enqueue authored Jun 21, 2019
1 parent 3a38e5d commit 457573b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/metabase/driver/clickhouse.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
[date :as du]
[honeysql-extensions :as hx]]
[schema.core :as sc])
(:import [java.sql DatabaseMetaData ResultSet Time Types]
(:import [ru.yandex.clickhouse.util ClickHouseArrayUtil]
[java.sql DatabaseMetaData ResultSet Time Types]
[java.util Calendar Date]))

(driver/register! :clickhouse, :parent :sql-jdbc)
Expand Down Expand Up @@ -228,6 +229,10 @@
(Time. (.getTime timestamp))
((get-method sql-jdbc.execute/read-column [:sql-jdbc Types/TIMESTAMP]) driver calendar resultset meta i))))

(defmethod sql-jdbc.execute/read-column [:clickhouse Types/ARRAY] [driver calendar resultset meta i]
(when-let [arr (.getArray resultset i)]
(ClickHouseArrayUtil/arrayToString (.getArray arr))))

(defn- get-tables
"Fetch a JDBC Metadata ResultSet of tables in the DB, optionally limited to ones belonging to a given schema."
[^DatabaseMetaData metadata, ^String schema-or-nil, ^String db-name-or-nil]
Expand Down
22 changes: 22 additions & 0 deletions test/metabase/driver/clickhouse_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@
:limit 1}))
first-row last float))

(datasets/expect-with-driver :clickhouse
"['foo','bar']"
(-> (data/with-db-for-dataset
[_
(tx/dataset-definition "ClickHouse with String Array"
["test-data-array"
[{:field-name "my_array", :base-type {:native "Array(String)"}}]
[[(into-array (list "foo" "bar"))]]])]
(data/run-mbql-query test-data-array {:limit 1}))
first-row last))

(datasets/expect-with-driver :clickhouse
"[23,42]"
(-> (data/with-db-for-dataset
[_
(tx/dataset-definition "ClickHouse with UInt64 Array"
["test-data-array"
[{:field-name "my_array", :base-type {:native "Array(UInt64)"}}]
[[(into-array (list 23 42))]]])]
(data/run-mbql-query test-data-array {:limit 1}))
first-row last))

(expect
{:classname "ru.yandex.clickhouse.ClickHouseDriver"
:subprotocol "clickhouse"
Expand Down

0 comments on commit 457573b

Please sign in to comment.