Skip to content

Commit 5e488ed

Browse files
authored
Upgrade to Metabase v50 (#50)
1 parent 348222e commit 5e488ed

File tree

10 files changed

+178
-84
lines changed

10 files changed

+178
-84
lines changed

.github/workflows/dockerhub.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/checkout@v3
2121
with:
2222
repository: metabase/metabase
23-
ref: v0.49.12
23+
ref: v0.50.10
2424

2525
- name: Checkout Driver Repo
2626
uses: actions/checkout@v3

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
uses: actions/checkout@v3
1515
with:
1616
repository: metabase/metabase
17-
ref: v0.49.12
17+
ref: v0.50.10
1818

1919
- name: Checkout Driver Repo
2020
uses: actions/checkout@v3

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/checkout@v3
1919
with:
2020
repository: metabase/metabase
21-
ref: v0.49.12
21+
ref: v0.50.10
2222

2323
- name: Checkout Driver Repo
2424
uses: actions/checkout@v3

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The easiest way to set up a development environment is as follows (mostly the sa
2424
```bash
2525
git clone https://github.com/metabase/metabase.git
2626
cd metabase
27-
git checkout v0.49.12
27+
git checkout v0.50.10
2828
git clone https://github.com/MaterializeInc/metabase-materialize-driver.git modules/drivers/materialize
2929
```
3030

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ v0.46.7 | v0.1.0
6060
v0.47.0 | v1.0.0
6161
v0.47.1 | v1.0.1 <br> v1.0.2 <br> v1.0.3
6262
v0.49.12 | v1.1.0
63+
v0.50.10 | v1.2.0
6364

6465
## Contributing
6566

bin/build_docker_image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ usage() {
2323
echo
2424
echo "Example:"
2525
echo
26-
echo "$0 v0.49.12 /some/path/to/materialize.metabase-driver.jar my-metabase-with-materialize:v0.0.1"
26+
echo "$0 v0.50.10 /some/path/to/materialize.metabase-driver.jar my-metabase-with-materialize:v0.0.1"
2727
exit 1
2828
}
2929

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ services:
2222
}
2323

2424
metabase:
25-
image: metabase/metabase:v0.49.12
25+
image: metabase/metabase:v0.50.10
2626
container_name: metabase-with-materialize-driver
2727
environment:
2828
'MB_HTTP_TIMEOUT': '5000'

resources/metabase-plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Reference: https://github.com/metabase/metabase/wiki/Metabase-Plugin-Manifest-Reference
22
info:
33
name: Metabase Materialize Driver
4-
version: 1.1.0
4+
version: 1.2.0
55
description: Allows Metabase to connect to Materialize.
66
contact-info:
77
name: Materialize Inc.

scripts/exclude_tests.diff

Lines changed: 114 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,27 @@
1-
diff --git a/test/metabase/query_processor_test/explicit_joins_test.clj b/test/metabase/query_processor_test/explicit_joins_test.clj
2-
index 166598c4c6..e1bef679f1 100644
3-
--- a/test/metabase/query_processor_test/explicit_joins_test.clj
4-
+++ b/test/metabase/query_processor_test/explicit_joins_test.clj
5-
@@ -267,8 +267,8 @@
6-
7-
(deftest ^:parallel select-*-source-query-test
8-
(mt/test-drivers (disj (mt/normal-drivers-with-feature :left-join)
9-
- ;; mongodb doesn't support foreign keys required by this test
10-
- :mongo)
11-
+ ;; mongodb and materialize don't support foreign keys required by this test
12-
+ :mongo :materialize)
13-
(testing "We should be able to run a query that for whatever reason ends up with a `SELECT *` for the source query"
14-
(let [{:keys [rows columns]} (mt/format-rows-by [int int]
15-
(mt/rows+column-names
16-
@@ -986,6 +986,7 @@
1+
diff --git a/test/metabase/db/metadata_queries_test.clj b/test/metabase/db/metadata_queries_test.clj
2+
index 7373655654..25eb5da352 100644
3+
--- a/test/metabase/db/metadata_queries_test.clj
4+
+++ b/test/metabase/db/metadata_queries_test.clj
5+
@@ -45,13 +45,7 @@
6+
(sort-by first)
7+
(take 5))]
8+
(is (= :type/Text (-> fields first :base_type)))
9+
- (is (= expected (fetch! nil)))
10+
- (testing "truncates text fields (see #13288)"
11+
- (doseq [size [1 4 80]]
12+
- (is (= (mapv (fn [[s]] [(subs (or s "") 0 (min size (count s)))])
13+
- expected)
14+
- (fetch! size))
15+
- "Did not truncate a text field")))))
16+
+ (is (= expected (fetch! nil)))))
1717

18-
(deftest ^:parallel join-with-brakout-and-aggregation-expression
19-
(mt/test-drivers (mt/normal-drivers-with-feature :left-join)
20-
+ (when (not= driver/*driver* :materialize)
21-
(mt/dataset test-data
22-
(let [query (mt/mbql-query orders
23-
{:source-query {:source-table $$orders
24-
@@ -1004,7 +1004,7 @@
25-
["Doohickey" "Balistreri-Ankunding" "2018-02-01T00:00:00Z" 315.36 3.1536]
26-
["Doohickey" "Balistreri-Ankunding" "2018-03-01T00:00:00Z" 315.36 3.1536]]
27-
(mt/formatted-rows [str str str 2.0 4.0]
28-
- (qp/process-query query)))))))))
29-
+ (qp/process-query query))))))))))
30-
31-
(deftest ^:parallel mlv2-references-in-join-conditions-test
32-
(testing "Make sure join conditions that contain MLv2-generated refs with extra info like `:base-type` work correctly (#33083)"
33-
diff --git a/test/metabase/query_processor_test/date_bucketing_test.clj b/test/metabase/query_processor_test/date_bucketing_test.clj
34-
index 87d225f5ae..343eb1f5f5 100644
35-
--- a/test/metabase/query_processor_test/date_bucketing_test.clj
36-
+++ b/test/metabase/query_processor_test/date_bucketing_test.clj
37-
@@ -182,7 +182,7 @@
38-
39-
;; There's a bug here where we are reading in the UTC time as pacific, so we're 7 hours off
40-
;; (This is fixed for Oracle now)
41-
- (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle))
42-
+ (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle) (not= driver/*driver* :materialize))
43-
[["2015-06-01T10:31:00-07:00" 1]
44-
["2015-06-01T16:06:00-07:00" 1]
45-
["2015-06-01T17:23:00-07:00" 1]
46-
@@ -237,7 +237,7 @@
47-
["2015-06-02 08:20:00" 1]
48-
["2015-06-02 11:11:00" 1]]
49-
50-
- (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle))
51-
+ (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle) (not= driver/*driver* :materialize))
52-
[["2015-06-01T10:31:00-04:00" 1]
53-
["2015-06-01T16:06:00-04:00" 1]
54-
["2015-06-01T17:23:00-04:00" 1]
55-
18+
(testing "substring checking"
19+
(with-redefs [driver.u/database->driver (constantly (:engine (mt/db)))
5620
diff --git a/test/metabase/driver_test.clj b/test/metabase/driver_test.clj
57-
index bb3b1bea6a..20e0ab83b4 100644
21+
index a506be0a66..cf358e20b2 100644
5822
--- a/test/metabase/driver_test.clj
5923
+++ b/test/metabase/driver_test.clj
60-
@@ -107,7 +107,7 @@
24+
@@ -106,7 +106,7 @@
6125
(do
6226
(tx/destroy-db! driver/*driver* dbdef)
6327
details))]
@@ -66,7 +30,7 @@ index bb3b1bea6a..20e0ab83b4 100644
6630
(binding [h2/*allow-testing-h2-connections* true]
6731
(driver/can-connect? driver/*driver* details))
6832
(catch Exception _
69-
@@ -148,7 +148,7 @@
33+
@@ -144,7 +144,7 @@
7034
;; so fake it by changing the database details
7135
(let [details (:details (mt/db))
7236
new-details (case driver/*driver*
@@ -75,7 +39,7 @@ index bb3b1bea6a..20e0ab83b4 100644
7539
:oracle (assoc details :service-name (mt/random-name))
7640
:presto-jdbc (assoc details :catalog (mt/random-name)))]
7741
(t2/update! :model/Database (u/the-id db) {:details new-details}))
78-
@@ -156,9 +156,9 @@
42+
@@ -152,9 +152,9 @@
7943
(tx/destroy-db! driver/*driver* dbdef))
8044
(testing "after deleting a database, sync should fail"
8145
(testing "1: sync-and-analyze-database! should log a warning and fail early"
@@ -86,25 +50,98 @@ index bb3b1bea6a..20e0ab83b4 100644
8650
+ (mt/user-http-request :crowberto :post 200 (str "/database/" (u/the-id db) "/sync_schema"))))
8751
;; clean up the database
8852
(t2/delete! :model/Database (u/the-id db))))))))
89-
90-
53+
54+
diff --git a/test/metabase/query_processor_test/date_bucketing_test.clj b/test/metabase/query_processor_test/date_bucketing_test.clj
55+
index 6e469bb152..f5f817715b 100644
56+
--- a/test/metabase/query_processor_test/date_bucketing_test.clj
57+
+++ b/test/metabase/query_processor_test/date_bucketing_test.clj
58+
@@ -184,7 +184,7 @@
59+
60+
;; There's a bug here where we are reading in the UTC time as pacific, so we're 7 hours off
61+
;; (This is fixed for Oracle now)
62+
- (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle))
63+
+ (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle) (not= driver/*driver* :materialize))
64+
[["2015-06-01T10:31:00-07:00" 1]
65+
["2015-06-01T16:06:00-07:00" 1]
66+
["2015-06-01T17:23:00-07:00" 1]
67+
@@ -242,7 +242,7 @@
68+
["2015-06-02 08:20:00" 1]
69+
["2015-06-02 11:11:00" 1]]
70+
71+
- (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle))
72+
+ (and (qp.test-util/tz-shifted-driver-bug? driver/*driver*) (not= driver/*driver* :oracle) (not= driver/*driver* :materialize))
73+
[["2015-06-01T10:31:00-04:00" 1]
74+
["2015-06-01T16:06:00-04:00" 1]
75+
["2015-06-01T17:23:00-04:00" 1]
76+
diff --git a/test/metabase/query_processor_test/explicit_joins_test.clj b/test/metabase/query_processor_test/explicit_joins_test.clj
77+
index ded26c8e97..4608b25854 100644
78+
--- a/test/metabase/query_processor_test/explicit_joins_test.clj
79+
+++ b/test/metabase/query_processor_test/explicit_joins_test.clj
80+
@@ -270,8 +270,8 @@
81+
82+
(deftest ^:parallel select-*-source-query-test
83+
(mt/test-drivers (disj (mt/normal-drivers-with-feature :left-join)
84+
- ;; mongodb doesn't support foreign keys required by this test
85+
- :mongo)
86+
+ ;; mongodb and materialize don't support foreign keys required by this test
87+
+ :mongo :materialize)
88+
(testing "We should be able to run a query that for whatever reason ends up with a `SELECT *` for the source query"
89+
(let [{:keys [rows columns]} (mt/format-rows-by [int int]
90+
(mt/rows+column-names
9191
diff --git a/test/metabase/test/data/dataset_definition_test.clj b/test/metabase/test/data/dataset_definition_test.clj
92-
index 1de46014c9..d44c94cf0a 100644
92+
index 25ead15772..f830d1c2ff 100644
9393
--- a/test/metabase/test/data/dataset_definition_test.clj
9494
+++ b/test/metabase/test/data/dataset_definition_test.clj
95-
@@ -13,6 +13,7 @@
96-
;; creating db for athena is expensive and require some extra steps,
97-
;; so it's not worth testing against, see [[metabase.test.data.athena/*allow-database-creation*]]
98-
:athena
99-
+ :materialize
100-
;; there is no PK in sparksql
101-
:sparksql)
102-
(mt/dataset (mt/dataset-definition "custom-pk"
103-
@@ -53,6 +54,7 @@
104-
;; creating db for athena is expensive and require some extra steps,
105-
;; so it's not worth testing against, see [[metabase.test.data.athena/*allow-database-creation*]]
106-
:athena
107-
+ :materialize
108-
;; there is no PK in sparksql
109-
:sparksql)
110-
(mt/dataset composite-pk
95+
@@ -8,52 +8,8 @@
96+
[metabase.timeseries-query-processor-test.util :as tqpt]
97+
[toucan2.core :as t2]))
98+
99+
-(deftest dataset-with-custom-pk-test
100+
- (mt/test-drivers (->> (mt/normal-drivers-with-feature :metadata/key-constraints)
101+
- (filter (mt/sql-jdbc-drivers))
102+
- ;; Timeseries drivers currently support only testing with pre-loaded dataset
103+
- (remove (tqpt/timeseries-drivers)))
104+
- (mt/dataset (mt/dataset-definition "custom-pk"
105+
- ["user"
106+
- [{:field-name "custom_id" :base-type :type/Integer :pk? true}]
107+
- [[1]]]
108+
- ["group"
109+
- [{:field-name "user_custom_id" :base-type :type/Integer :fk "user"}]
110+
- [[1]]])
111+
- (let [user-fields (t2/select [:model/Field :name :semantic_type :fk_target_field_id] :table_id (mt/id :user))
112+
- group-fields (t2/select [:model/Field :name :semantic_type :fk_target_field_id] :table_id (mt/id :group))
113+
- format-name #(ddl.i/format-name driver/*driver* %)]
114+
- (testing "user.custom_id is a PK"
115+
- (is (= [{:name (format-name "custom_id")
116+
- :fk_target_field_id nil
117+
- :semantic_type :type/PK}]
118+
- user-fields)))
119+
- (when (driver.u/supports? driver/*driver* :foreign-keys (mt/db))
120+
- (testing "user_custom_id is a FK non user.custom_id"
121+
- (is (= #{{:name (format-name "user_custom_id")
122+
- :fk_target_field_id (mt/id :user :custom_id)
123+
- :semantic_type :type/FK}
124+
- {:name (format-name "id")
125+
- :fk_target_field_id nil
126+
- :semantic_type :type/PK}}
127+
- (set group-fields)))))))))
128+
-
129+
(mt/defdataset composite-pk
130+
[["songs"
131+
[{:field-name "artist_id", :base-type :type/Integer, :pk? true}
132+
{:field-name "song_id", :base-type :type/Integer, :pk? true}]
133+
[[1 2]]]])
134+
-
135+
-(deftest dataset-with-custom-composite-pk-test
136+
- (mt/test-drivers (->> (mt/normal-drivers-with-feature :metadata/key-constraints)
137+
- (filter (mt/sql-jdbc-drivers))
138+
- ;; Timeseries drivers currently support only testing with pre-loaded dataset
139+
- (remove (tqpt/timeseries-drivers)))
140+
- (mt/dataset composite-pk
141+
- (let [format-name #(ddl.i/format-name driver/*driver* %)]
142+
- (testing "(artist_id, song_id) is a PK"
143+
- (is (= #{(format-name "artist_id")
144+
- (format-name "song_id")}
145+
- (t2/select-fn-set :name :model/Field
146+
- :table_id (mt/id :songs)
147+
- :semantic_type :type/PK))))))))

src/metabase/driver/materialize.clj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
"Metabase Materialize Driver."
33
(:require [clojure
44
[set :as set]]
5+
[honey.sql :as sql]
6+
[honey.sql.helpers :as sql.helpers]
57
[metabase.db.spec :as db.spec]
68
[metabase.config :as config]
79
[metabase.driver :as driver]
810
[metabase.util :as u]
911
[metabase.driver.sql-jdbc.execute :as sql-jdbc.execute]
1012
[metabase.driver.sql.query-processor :as sql.qp]
1113
[metabase.util.honey-sql-2 :as h2x]
14+
[metabase.driver.sync :as driver.s]
1215
[metabase.driver.sql-jdbc
1316
[common :as sql-jdbc.common]
1417
[connection :as sql-jdbc.conn]
@@ -88,3 +91,56 @@
8891
(sql-jdbc.sync/describe-table driver database table))
8992

9093
(defmethod sql-jdbc.sync/excluded-schemas :materialize [_driver] #{"mz_catalog" "mz_internal" "pg_catalog"})
94+
95+
(defn ^:private get-tables-sql
96+
"Materialize doesn't support the pg_stat_user_tables table
97+
Overriding the default implementation to exclude the pg_stat_user_tables table"
98+
[schemas table-names]
99+
(sql/format
100+
(cond-> {:select [[:n.nspname :schema]
101+
[:c.relname :name]
102+
[[:case-expr :c.relkind
103+
[:inline "r"] [:inline "TABLE"]
104+
[:inline "p"] [:inline "PARTITIONED TABLE"]
105+
[:inline "v"] [:inline "VIEW"]
106+
[:inline "f"] [:inline "FOREIGN TABLE"]
107+
[:inline "m"] [:inline "MATERIALIZED VIEW"]
108+
:else nil]
109+
:type]
110+
[:d.description :description]]
111+
:from [[:pg_catalog.pg_class :c]]
112+
:join [[:pg_catalog.pg_namespace :n] [:= :c.relnamespace :n.oid]]
113+
:left-join [[:pg_catalog.pg_description :d] [:and [:= :c.oid :d.objoid]
114+
[:= :d.objsubid 0]
115+
[:= :d.classoid [:raw "'pg_class'::regclass"]]]]
116+
:where [:and [:= :c.relnamespace :n.oid]
117+
;; filter out system tables (pg_ and mz_)
118+
[:and
119+
[(keyword "!~") :n.nspname "^pg_"]
120+
[(keyword "!~") :n.nspname "^mz_"]
121+
[:<> :n.nspname "information_schema"]]
122+
;; only get tables of type: TABLE, PARTITIONED TABLE, VIEW, FOREIGN TABLE, MATERIALIZED VIEW
123+
[:raw "c.relkind in ('r', 'p', 'v', 'f', 'm')"]]
124+
:order-by [:type :schema :name]}
125+
(seq schemas)
126+
(sql.helpers/where [:in :n.nspname schemas])
127+
128+
(seq table-names)
129+
(sql.helpers/where [:in :c.relname table-names]))
130+
{:dialect :ansi}))
131+
132+
(defn- describe-database-tables
133+
[database]
134+
(let [[inclusion-patterns
135+
exclusion-patterns] (driver.s/db-details->schema-filter-patterns database)
136+
syncable? (fn [schema]
137+
(driver.s/include-schema? inclusion-patterns exclusion-patterns schema))]
138+
(eduction
139+
(comp (filter (comp syncable? :schema))
140+
(map #(dissoc % :type)))
141+
(sql-jdbc.execute/reducible-query database (get-tables-sql nil nil)))))
142+
143+
(defmethod driver/describe-database :materialize
144+
[_driver database]
145+
;; TODO: change this to return a reducible so we don't have to hold 100k tables in memory in a set like this
146+
{:tables (into #{} (describe-database-tables database))})

0 commit comments

Comments
 (0)