From ddaa8be6a6d137c4d2280b6fe1e15e9163c7c879 Mon Sep 17 00:00:00 2001 From: Christoph Pirkl Date: Fri, 15 Dec 2023 15:49:46 +0100 Subject: [PATCH] #75: Upgrade to Metabase v.0.48.0 (#76) Co-authored-by: Christoph Kuhnke --- .github/workflows/ci-build.yml | 6 +- .github/workflows/integration-tests.yml | 12 +- ...ase_droid_upload_github_release_assets.yml | 4 +- deps.edn | 4 +- doc/changes/changelog.md | 1 + doc/changes/changes_1.0.7.md | 11 ++ doc/developer_guide/developer_guide.md | 75 ++++++++---- resources/metabase-plugin.yaml | 2 +- scripts/exclude_tests.diff | 111 +++++++++++++++--- src/metabase/driver/exasol.clj | 5 +- test/metabase/driver/exasol_test.clj | 50 +------- test/metabase/driver/exasol_unit_test.clj | 10 +- test/metabase/test/data/exasol.clj | 39 +----- .../test/data/exasol_dataset_definitions.clj | 7 +- 14 files changed, 198 insertions(+), 139 deletions(-) create mode 100644 doc/changes/changes_1.0.7.md diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index a2ee0d1..b5840eb 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -15,7 +15,7 @@ jobs: cancel-in-progress: true runs-on: ubuntu-latest env: - METABASE_TAG: v0.47.3 + METABASE_TAG: v0.48.0 steps: - name: Checkout the repository uses: actions/checkout@v4 @@ -32,7 +32,7 @@ jobs: ref: ${{ env.METABASE_TAG }} - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 @@ -69,7 +69,7 @@ jobs: run: "$GITHUB_WORKSPACE/metabase-driver/scripts/build.sh" - name: Upload jar - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: exasol.metabase-driver.jar path: metabase-driver/target/exasol.metabase-driver.jar diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 9e3e009..452f19d 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -7,7 +7,7 @@ on: pull_request: jobs: - integration-test: + matrix-integration-test: strategy: fail-fast: true matrix: @@ -18,7 +18,7 @@ jobs: name: "Build with Exasol ${{ matrix.exasol_version }}" runs-on: ubuntu-latest env: - METABASE_TAG: v0.47.3 + METABASE_TAG: v0.48.0 steps: - name: Free Disk Space run: | @@ -47,7 +47,7 @@ jobs: path: 'integration-test-docker-environment' - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: 11 @@ -100,3 +100,9 @@ jobs: EXASOL_PORT=$ITDE_DATABASE_DB_PORT \ EXASOL_USER=sys EXASOL_PASSWORD=exasol \ $GITHUB_WORKSPACE/metabase-driver/scripts/run-integration-tests.sh + + integration-test: + needs: matrix-integration-test + runs-on: ubuntu-latest + steps: + - run: echo "Build successful" diff --git a/.github/workflows/release_droid_upload_github_release_assets.yml b/.github/workflows/release_droid_upload_github_release_assets.yml index 92a1ae8..3326830 100644 --- a/.github/workflows/release_droid_upload_github_release_assets.yml +++ b/.github/workflows/release_droid_upload_github_release_assets.yml @@ -11,7 +11,7 @@ jobs: build: runs-on: ubuntu-latest env: - METABASE_TAG: v0.47.3 + METABASE_TAG: v0.48.0 steps: - name: Checkout the repository uses: actions/checkout@v4 @@ -28,7 +28,7 @@ jobs: ref: ${{ env.METABASE_TAG }} - name: Set up JDK 11 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: temurin java-version: 11 diff --git a/deps.edn b/deps.edn index 24618cd..b6d0e94 100644 --- a/deps.edn +++ b/deps.edn @@ -11,9 +11,9 @@ :aliases {:dev {:extra-deps - {io.github.metabase/metabase {:git/tag "v0.47.3" :git/sha "0ca7df3"}}} + {io.github.metabase/metabase {:git/tag "v0.48.0" :git/sha "0ca7df3"}}} ; clojure -M:clj-kondo --lint src test --debug :clj-kondo - {:replace-deps {clj-kondo/clj-kondo {:mvn/version "2023.03.17"}} + {:replace-deps {clj-kondo/clj-kondo {:mvn/version "2023.10.20"}} :main-opts ["-m" "clj-kondo.main"]}}} diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index 6ad09fa..2ea3f27 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,5 +1,6 @@ # Changes +* [1.0.7](changes_1.0.7.md) * [1.0.6](changes_1.0.6.md) * [1.0.5](changes_1.0.5.md) * [1.0.4](changes_1.0.4.md) diff --git a/doc/changes/changes_1.0.7.md b/doc/changes/changes_1.0.7.md new file mode 100644 index 0000000..d5df946 --- /dev/null +++ b/doc/changes/changes_1.0.7.md @@ -0,0 +1,11 @@ +# metabase-driver 1.0.7, released 2023-12-15 + +Code name: Upgrade to Metabase v0.48.0 + +## Summary + +This release adapts the driver to Metabase v0.48.0. + +## Features + +* #75: Upgraded to Metabase v0.48.0 diff --git a/doc/developer_guide/developer_guide.md b/doc/developer_guide/developer_guide.md index 0bf79c5..39650f3 100644 --- a/doc/developer_guide/developer_guide.md +++ b/doc/developer_guide/developer_guide.md @@ -11,19 +11,19 @@ To build Metabase itself you will need On Ubuntu you can install the dependencies by running -```shell +```sh sudo apt install nodejs yarnpkg ``` Fedora: -```shell +```sh yum install perl-Digest-SHA nodejs yarnpkg ``` On macOS you additionally need `gnu-sed`: -```shell +```sh brew install nodejs yarnpkg clojure gnu-sed # Then add gnubin to your PATH: # export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" @@ -31,7 +31,7 @@ brew install nodejs yarnpkg clojure gnu-sed Run the following commands to check the current versions: -```shell +```sh clojure -M --eval "(clojure-version)" clojure --version ``` @@ -40,37 +40,58 @@ clojure --version 1. Checkout Metabase at `$HOME/git/metabase` (= `$METABASE_DIR`) and build it: - ```bash + ```sh cd $HOME/git git clone https://github.com/metabase/metabase.git cd metabase git fetch --all --tags - export METABASE_VERSION=v0.47.3 + export METABASE_VERSION=v0.48.0 git reset --hard rm -vf target/patch_excluded_test_applied git checkout "tags/${METABASE_VERSION}" -b "${METABASE_VERSION}-branch" # Build (this will take ~15min) ./bin/build.sh - # Run - clojure -M:run ``` 2. Download the Exasol JDBC driver from the [Download Portal](https://downloads.exasol.com/clients-and-drivers) and install it: - ```bash + ```sh cp exajdbc.jar "$METABASE_DIR/plugins" ``` 3. Checkout the Exasol Metabase driver at `$HOME/git/metabase` (= `$METABASE_EXASOL_DRIVER`) - ```bash + ```sh git clone https://github.com/exasol/metabase-driver.git cd metabase-driver ``` -## Run Driver Unit Tests +## Upgrading Metabase -```bash +To ensure compatibility we need to regularly update to the latest Metabase version. You can find the latest Metabase version on the [GitHub release page](https://github.com/metabase/metabase/releases/). + +Metabase publishes two variants: +* OSS: version numbers v0.x.y +* Enterprise: version numbers v1.x.y + +We only use the OSS variant with version numbers v0.x.y. + +To upgrade Metabase follow these steps: +1. Check the Metabase [driver changelog](https://www.metabase.com/docs/latest/developers-guide/driver-changelog.html) for breaking changes +2. Replace the previous version in all files with the new version by searching for `v0.x.y` +3. [Run unit tests](#running-driver-unit-tests) +4. [Run integration tests](#running-integration-tests) + +The following things can go wrong: +* The patch excluding inapproriate tests cannot be applied. See [excluded tests](#excluded-tests) for details. +* Tests fail or abort + * If possible fix the problem in the driver + * If failures are related to Exasol specifics (e.g. missing `TIME` data type etc.) modify the test in Metabase and update the patch file, see [excluded tests](#excluded-tests) for details. + * If failures are unrelated to Exasol or the driver, you might delete it and update the patch file, see [excluded tests](#excluded-tests) for details. + +## Running Driver Unit Tests + +```sh ./scripts/run-unit-tests.sh ``` @@ -78,7 +99,7 @@ clojure --version To start Metabase with the Exasol driver from source: -```bash +```sh export METABASE_DIR="$HOME/git/metabase" export METABASE_EXASOL_DRIVER="$HOME/git/metabase-driver" cd $METABASE_DIR @@ -92,7 +113,7 @@ After startup is complete (log message: `Metabase Initialization COMPLETE`) you To start Metabase with the built Exasol driver: -```bash +```sh export METABASE_DIR="$HOME/git/metabase" export METABASE_EXASOL_DRIVER="$HOME/git/metabase-driver" cd $METABASE_EXASOL_DRIVER @@ -108,19 +129,19 @@ cd $METABASE_DIR clojure -M:run ``` -## Running the Integration Tests +## Running Integration Tests You need to have metabase checked out next to this repository. Start Exasol docker container: -```shell +```sh docker run --publish 8563:8563 --publish 2580:2580 --publish 443:443 --detach --privileged --stop-timeout 120 exasol/docker-db:7.1.23 ``` Start integration tests: -```shell +```sh EXASOL_HOST= EXASOL_PORT=8563 EXASOL_USER=sys EXASOL_PASSWORD=exasol ./scripts/run-integration-tests.sh ``` @@ -128,14 +149,14 @@ This script builds and installs the driver before running the integration tests. To run only a single tests or only tests in a namespace add arguments: -```shell +```sh ./scripts/run-integration-tests.sh :only name.space/single-test ./scripts/run-integration-tests.sh :only name.space ``` ### Using the REPL -```shell +```sh export MB_EXASOL_TEST_HOST= export MB_EXASOL_TEST_PORT=8563 export MB_EXASOL_TEST_USER=sys @@ -173,7 +194,7 @@ In the REPL you can use the following commands: To increase the log level for integration tests, edit file `$METABASE_DIR/test_config/log4j2-test.xml`. -### Unsupported Datasets / Excluded Tests +### Excluded Tests Exasol does not support the `TIME` data type. That is why we can't load the following datasets from the Metabase integration tests: @@ -186,14 +207,24 @@ Script `run-integration-tests.sh` automatically applies this patch when file `$M When the patch file has changed or you updated to a new Metabase release, do the following and re-run the integration tests with `run-integration-tests.sh`. -```shell +```sh cd $METABASE_DIR git reset --hard && rm -vf target/patch_excluded_test_applied ``` +#### Applying Patch Fails + +If applying the patch fails after upgrading to a new Metabase version, follow these steps: + +1. Run `cd $METABASE_DIR && git reset --hard && rm -vf target/patch_excluded_test_applied` +2. Remove the failed part from `exclude_tests.diff` +3. Run integration tests `run-integration-tests.sh`. This will apply the patch. +4. Modify Metabase tests to adapt them to Exasol +5. Update patch by running `cd $METABASE_DIR && git diff > $METABASE_EXASOL_DRIVER/scripts/exclude_tests.diff` + ## Linting -```shell +```sh clojure -M:clj-kondo --lint src test --debug ``` diff --git a/resources/metabase-plugin.yaml b/resources/metabase-plugin.yaml index fd29f44..855228b 100644 --- a/resources/metabase-plugin.yaml +++ b/resources/metabase-plugin.yaml @@ -1,7 +1,7 @@ # Complete list of options here: https://github.com/metabase/metabase/wiki/Metabase-Plugin-Manifest-Reference info: name: Metabase Exasol Driver - version: 1.0.6 + version: 1.0.7 description: Allows Metabase to connect to Exasol databases. contact-info: name: Exasol AG diff --git a/scripts/exclude_tests.diff b/scripts/exclude_tests.diff index 179b94a..3487f75 100644 --- a/scripts/exclude_tests.diff +++ b/scripts/exclude_tests.diff @@ -1,8 +1,8 @@ diff --git a/test/metabase/api/session_test.clj b/test/metabase/api/session_test.clj -index 8db4884433..d2c723d1a5 100644 +index 4e8bed208b..bf6d8aeb67 100644 --- a/test/metabase/api/session_test.clj +++ b/test/metabase/api/session_test.clj -@@ -187,7 +187,7 @@ +@@ -178,7 +178,7 @@ :body json/parse-string (get-in ["errors" "username"])))] @@ -11,12 +11,63 @@ index 8db4884433..d2c723d1a5 100644 (error))) (is (re= #"^Too many attempts! You must wait 4\d seconds before trying again\.$" (error))))))) +diff --git a/test/metabase/db/custom_migrations_test.clj b/test/metabase/db/custom_migrations_test.clj +index 86e8de4f23..0b4b33b07f 100644 +--- a/test/metabase/db/custom_migrations_test.clj ++++ b/test/metabase/db/custom_migrations_test.clj +@@ -1397,45 +1397,7 @@ + (binding [setting/*allow-retired-setting-names* true] + `(call-with-ldap-and-sso-configured ~ldap-group-mappings ~sso-group-mappings (fn [] ~@body)))) + +-;; The `remove-admin-from-group-mapping-if-needed` migration is written to run in OSS version +-;; even though it might make changes to some enterprise-only settings. +-;; In order to write tests that runs in both OSS and EE, we can't use +-;; [[metabase.models.setting/get]] and [[metabase.test.util/with-temporary-setting-values]] +-;; because they require all settings are defined. +-;; That's why we use a set of helper functions that get setting directly from DB during tests +-(deftest migrate-remove-admin-from-group-mapping-if-needed-test +- (let [admin-group-id (u/the-id (perms-group/admin)) +- sso-group-mappings {"group-mapping-a" [admin-group-id (+ 1 admin-group-id)] +- "group-mapping-b" [admin-group-id (+ 1 admin-group-id) (+ 2 admin-group-id)]} +- ldap-group-mappings {"dc=metabase,dc=com" [admin-group-id (+ 1 admin-group-id)]} +- sso-expected-mapping {"group-mapping-a" [(+ 1 admin-group-id)] +- "group-mapping-b" [(+ 1 admin-group-id) (+ 2 admin-group-id)]} +- ldap-expected-mapping {"dc=metabase,dc=com" [(+ 1 admin-group-id)]}] +- +- (testing "Remove admin from group mapping for LDAP, SAML, JWT if they are enabled" +- (with-ldap-and-sso-configured ldap-group-mappings sso-group-mappings +- (#'custom-migrations/migrate-remove-admin-from-group-mapping-if-needed) +- (is (= ldap-expected-mapping (get-json-setting :ldap-group-mappings))) +- (is (= sso-expected-mapping (get-json-setting :jwt-group-mappings))) +- (is (= sso-expected-mapping (get-json-setting :saml-group-mappings))))) +- +- (testing "remove admin from group mapping for LDAP, SAML, JWT even if they are disabled" +- (with-ldap-and-sso-configured ldap-group-mappings sso-group-mappings +- (mt/with-temporary-raw-setting-values +- [ldap-enabled "false" +- saml-enabled "false" +- jwt-enabled "false"] +- (#'custom-migrations/migrate-remove-admin-from-group-mapping-if-needed) +- (is (= ldap-expected-mapping (get-json-setting :ldap-group-mappings))) +- (is (= sso-expected-mapping (get-json-setting :jwt-group-mappings))) +- (is (= sso-expected-mapping (get-json-setting :saml-group-mappings)))))) +- +- (testing "Don't remove admin group if `ldap-sync-admin-group` is enabled" +- (with-ldap-and-sso-configured ldap-group-mappings sso-group-mappings +- (mt/with-temporary-raw-setting-values +- [ldap-sync-admin-group "true"] +- (#'custom-migrations/migrate-remove-admin-from-group-mapping-if-needed) +- (is (= ldap-group-mappings (get-json-setting :ldap-group-mappings)))))))) ++;; Test failure unrelated to Exasol driver + + (deftest check-data-migrations-rollback + ;; We're actually testing `v48.00-024`, but we want the `migrate!` function to run all the migrations in 48 diff --git a/test/metabase/driver/sql/parameters/substitute_test.clj b/test/metabase/driver/sql/parameters/substitute_test.clj -index b7ab05c624..f482f5d9b7 100644 +index bc6f1a3a30..aef97a5627 100644 --- a/test/metabase/driver/sql/parameters/substitute_test.clj +++ b/test/metabase/driver/sql/parameters/substitute_test.clj -@@ -776,7 +776,7 @@ - :value "2015-07-01"}])))))))) +@@ -780,7 +780,7 @@ + :value "2015-07-01"}])))))))) (deftest e2e-parse-native-dates-test - (mt/test-drivers (disj (sql-parameters-engines) :sqlite) @@ -25,7 +76,7 @@ index b7ab05c624..f482f5d9b7 100644 ;; TIMEZONE FIXME — Busted (= driver/*driver* :vertica) diff --git a/test/metabase/driver/sql_jdbc/connection_test.clj b/test/metabase/driver/sql_jdbc/connection_test.clj -index 322be366d1..f750576c4b 100644 +index 4edb14cf98..cba3f0bb67 100644 --- a/test/metabase/driver/sql_jdbc/connection_test.clj +++ b/test/metabase/driver/sql_jdbc/connection_test.clj @@ -1,5 +1,6 @@ @@ -47,6 +98,34 @@ index 322be366d1..f750576c4b 100644 (deftest connection-pool-invalidated-on-details-change (mt/test-drivers (sql-jdbc.tu/sql-jdbc-drivers) +diff --git a/test/metabase/driver_test.clj b/test/metabase/driver_test.clj +index bb3b1bea6a..1746a0f0d0 100644 +--- a/test/metabase/driver_test.clj ++++ b/test/metabase/driver_test.clj +@@ -102,6 +102,7 @@ + details (case driver/*driver* + (:redshift :snowfake :vertica) (assoc details :db (mt/random-name)) + :oracle (assoc details :service-name (mt/random-name)) ++ :exasol (assoc details :certificate-fingerprint (mt/random-name)) + :presto-jdbc (assoc details :catalog (mt/random-name)) + ;; otherwise destroy the db and use the original details + (do +@@ -143,13 +144,14 @@ + ;; release db resources like connection pools so we don't have to wait to finish syncing before destroying the db + (driver/notify-database-updated driver/*driver* db) + ;; destroy the db +- (if (contains? #{:redshift :snowflake :vertica :presto-jdbc :oracle} driver/*driver*) ++ (if (contains? #{:redshift :snowflake :vertica :presto-jdbc :oracle :exasol} driver/*driver*) + ;; in the case of some cloud databases, the test database is never created, and can't or shouldn't be destroyed. + ;; so fake it by changing the database details + (let [details (:details (mt/db)) + new-details (case driver/*driver* + (:redshift :snowflake :vertica) (assoc details :db (mt/random-name)) + :oracle (assoc details :service-name (mt/random-name)) ++ :exasol (assoc details :certificate-fingerprint (mt/random-name)) + :presto-jdbc (assoc details :catalog (mt/random-name)))] + (t2/update! :model/Database (u/the-id db) {:details new-details})) + ;; otherwise destroy the db and use the original details diff --git a/test/metabase/models/setting/cache_test.clj b/test/metabase/models/setting/cache_test.clj index 276ccad5e2..563401fb82 100644 --- a/test/metabase/models/setting/cache_test.clj @@ -124,7 +203,7 @@ index 276ccad5e2..563401fb82 100644 +; Test fails +; IllegalArgumentException: No implementation of method: :-to-bytes of protocol: #'buddy.core.codecs/IByteArray found for class: clojure.lang.PersistentVector diff --git a/test/metabase/query_processor/middleware/format_rows_test.clj b/test/metabase/query_processor/middleware/format_rows_test.clj -index 6f4902e876..65d2359b22 100644 +index 62e8b7fb88..e4049025f5 100644 --- a/test/metabase/query_processor/middleware/format_rows_test.clj +++ b/test/metabase/query_processor/middleware/format_rows_test.clj @@ -19,7 +19,7 @@ @@ -137,13 +216,13 @@ index 6f4902e876..65d2359b22 100644 (deftest format-rows-test (mt/test-drivers (filter mt/supports-time-type? (mt/normal-drivers-except dbs-exempt-from-format-rows-tests)) diff --git a/test/metabase/query_processor_test/alternative_date_test.clj b/test/metabase/query_processor_test/alternative_date_test.clj -index 773092a012..f92dd7e040 100644 +index 4e619b0f20..1adf67d420 100644 --- a/test/metabase/query_processor_test/alternative_date_test.clj +++ b/test/metabase/query_processor_test/alternative_date_test.clj @@ -37,7 +37,7 @@ [0 1433965860000000]]]]) - (deftest microseconds-test + (deftest ^:parallel microseconds-test - (mt/test-drivers (disj (mt/normal-drivers) :sqlite) + (mt/test-drivers (disj (mt/normal-drivers) :sqlite :exasol) ; Timestamp/timezone covered by Exasol specific tests. (let [results (get {:sqlite #{[1 4 "2015-06-06 10:40:00"] [2 0 "2015-06-10 19:51:00"]} @@ -177,10 +256,10 @@ index 773092a012..f92dd7e040 100644 (->> (mt/run-mbql-query times {:filter [:= !day.d "2008-10-19"]}) diff --git a/test/metabase/query_processor_test/explicit_joins_test.clj b/test/metabase/query_processor_test/explicit_joins_test.clj -index 0be99aad8d..401e31eea0 100644 +index 3e59b40630..23449bd2a2 100644 --- a/test/metabase/query_processor_test/explicit_joins_test.clj +++ b/test/metabase/query_processor_test/explicit_joins_test.clj -@@ -786,7 +786,7 @@ +@@ -859,7 +859,7 @@ results)))))))))) (deftest ^:parallel double-quotes-in-join-alias-test @@ -190,10 +269,10 @@ index 0be99aad8d..401e31eea0 100644 (let [expected-rows (mt/rows (mt/run-mbql-query venues diff --git a/test/metabase/query_processor_test/parameters_test.clj b/test/metabase/query_processor_test/parameters_test.clj -index 1b3fe265d9..f0b914d315 100644 +index 2f81bd2f3d..d0dda23bb1 100644 --- a/test/metabase/query_processor_test/parameters_test.clj +++ b/test/metabase/query_processor_test/parameters_test.clj -@@ -254,6 +254,7 @@ +@@ -300,6 +300,7 @@ ;; These do not support ParameterMetadata.getParameterCount (remove #{:athena :bigquery-cloud-sdk @@ -202,10 +281,10 @@ index 1b3fe265d9..f0b914d315 100644 :redshift :snowflake diff --git a/test/metabase/query_processor_test/timezones_test.clj b/test/metabase/query_processor_test/timezones_test.clj -index 677f56a1ad..59e1e4a583 100644 +index fdc7d77a50..c3728e831c 100644 --- a/test/metabase/query_processor_test/timezones_test.clj +++ b/test/metabase/query_processor_test/timezones_test.clj -@@ -24,6 +24,7 @@ +@@ -25,6 +25,7 @@ #{:athena :bigquery-cloud-sdk :oracle @@ -214,7 +293,7 @@ index 677f56a1ad..59e1e4a583 100644 :snowflake :sparksql diff --git a/test/metabase/test/initialize.clj b/test/metabase/test/initialize.clj -index 4b297fd5f1..b89be26588 100644 +index f9b32da937..0cb97eda18 100644 --- a/test/metabase/test/initialize.clj +++ b/test/metabase/test/initialize.clj @@ -22,7 +22,7 @@ diff --git a/src/metabase/driver/exasol.clj b/src/metabase/driver/exasol.clj index 73ef155..83c3cf6 100644 --- a/src/metabase/driver/exasol.clj +++ b/src/metabase/driver/exasol.clj @@ -16,7 +16,8 @@ [metabase.driver.sql.query-processor.empty-string-is-null :as sql.qp.empty-string-is-null] [metabase.driver.sql.util.unprepare :as unprepare] [metabase.util.honey-sql-2 :as h2x] - [metabase.util.i18n :refer [trs]])) + [metabase.util.i18n :refer [trs]]) + (:import (java.sql Connection))) (set! *warn-on-reflection* true) @@ -147,7 +148,7 @@ (defn- set-time-zone! "Set the session timezone for the given connection" - [conn timezone-id] + [^Connection conn timezone-id] (when timezone-id (let [set-timezone-sql (create-set-timezone-sql timezone-id)] (with-open [stmt (.createStatement conn)] diff --git a/test/metabase/driver/exasol_test.clj b/test/metabase/driver/exasol_test.clj index 03d288e..75d9c91 100644 --- a/test/metabase/driver/exasol_test.clj +++ b/test/metabase/driver/exasol_test.clj @@ -3,7 +3,6 @@ [clojure.test :refer [deftest is testing]] [metabase.driver.exasol :as exasol] [metabase.query-processor :as qp] - [metabase.query-processor-test :as qp.test] [metabase.query-processor-test.alternative-date-test :as alt-date-test] [metabase.test :as mt] [metabase.test.data :as td] @@ -11,6 +10,8 @@ [metabase.test.data.exasol-dataset-definitions :as exasol-dataset]) (:import (java.util TimeZone))) +(set! *warn-on-reflection* true) + (deftest get-jdbc-driver-version-test (testing "Getting JDBC driver version succeeds" (is (not (str/blank? (exasol/get-jdbc-driver-version))))) @@ -70,21 +71,6 @@ {:filter [:and [:< $id 24] [:> $id 20] [:!= $id 22]] :order-by [[:asc $id]]}))))))) -(deftest select-fields-test - (testing "Exasol supports selecting defined fields" - (mt/test-driver :exasol - (is (= {:rows [["Red Medicine" 1] - ["Stout Burgers & Beers" 2] - ["The Apple Pan" 3] - ["Wurstküche" 4]] - :cols [(mt/col :venues :name) - (mt/col :venues :id)]} - (mt/format-rows-by [str int] - (qp.test/rows-and-cols - (mt/run-mbql-query venues - {:fields [$name $id] - :limit 4 - :order-by [[:asc $id]]})))))))) (deftest numeric-expression (testing "Exasol supports numeric expressions, e.g. with +" @@ -127,38 +113,8 @@ :limit 2}))))))) -(deftest aggregation - (testing "Exasol supports aggregation" - (mt/test-driver :exasol - (is (= {:cols [(qp.test/breakout-col :venues :price) - (qp.test/aggregate-col :cum-count :venues :id)] - :rows [[1 22] - [2 81] - [3 94] - [4 100]]} - (qp.test/rows-and-cols - (mt/format-rows-by [int int] - (mt/run-mbql-query venues - {:aggregation [[:cum-count $id]] - :breakout [$price]})))))))) - -(deftest nested-query - (testing "Exasol supports nested queries" - (mt/test-driver :exasol - (is (= {:rows [[1 174] [2 474] [3 78] [4 39]] - :cols [(qp.test/breakout-col (qp.test/fk-col :checkins :venue_id :venues :price)) - (qp.test/aggregate-col :count)]} - (qp.test/rows-and-cols - (mt/format-rows-by [int int] - (mt/run-mbql-query checkins - {:source-query {:source-table $$checkins - :filter [:> $date "2014-01-01"]} - :aggregation [:count] - :order-by [[:asc $venue_id->venues.price]] - :breakout [$venue_id->venues.price]})))))))) - (defn- do-with-java-timezone - [timezone-id body] + [^String timezone-id body] (let [org-timezone (TimeZone/getDefault)] (try (TimeZone/setDefault (when (not (nil? timezone-id)) (TimeZone/getTimeZone timezone-id))) diff --git a/test/metabase/driver/exasol_unit_test.clj b/test/metabase/driver/exasol_unit_test.clj index 6e40ad3..d57151f 100644 --- a/test/metabase/driver/exasol_unit_test.clj +++ b/test/metabase/driver/exasol_unit_test.clj @@ -13,6 +13,8 @@ [metabase.driver.sql.util.unprepare :as unprepare] [metabase.util.honey-sql-2 :as h2x])) +(set! *warn-on-reflection* true) + (deftest connection-details->spec-test (doseq [[^String message expected-spec details] [["You should be able to connect with an custom port" @@ -37,7 +39,7 @@ (def ^:private unsupported-features [:nested-fields :nested-field-columns :persist-models :persist-models-enabled :actions :actions/custom :convert-timezone :datetime-diff :now :native-requires-specified-collection :connection-impersonation :connection-impersonation-requires-role - :uploads]) + :uploads :table-privileges]) (deftest database-supports?-test (testing "Driver supports setting timezone" @@ -167,7 +169,9 @@ (is (= :sunday (driver/db-start-of-week :exasol)))) (deftest excluded-schemas-test - (is (= #{"EXA_STATISTICS" "SYS"} (sql-jdbc.sync/excluded-schemas :exasol)))) + (let [excluded-schemas (sql-jdbc.sync/excluded-schemas :exasol)] + (is (and (contains? excluded-schemas "EXA_STATISTICS") + (contains? excluded-schemas "SYS"))))) (deftest unprepare-value-test (doseq [[value expected] [[(java.time.OffsetDateTime/parse "2007-12-03T10:15:30+01:00") "timestamp '2007-12-03 10:15:30.000'"] @@ -181,7 +185,7 @@ (testing "Driver version read from existing resource" (is (not (str/blank? (exasol/get-driver-version))))) (testing "Driver version read from existing resource equal to expected version" - (is (= "1.0.6" (exasol/get-driver-version))))) + (is (= "1.0.7" (exasol/get-driver-version))))) (deftest humanize-connection-error-message-test (testing "Driver translates connection error message" diff --git a/test/metabase/test/data/exasol.clj b/test/metabase/test/data/exasol.clj index 798a0f5..f097bb6 100644 --- a/test/metabase/test/data/exasol.clj +++ b/test/metabase/test/data/exasol.clj @@ -1,20 +1,17 @@ (ns metabase.test.data.exasol (:require [clojure.java.jdbc :as jdbc] [clojure.set :as set] - [clojure.string :as str] - [metabase.db :as mdb] [metabase.driver.sql-jdbc.connection :as sql-jdbc.conn] [metabase.driver.sql-jdbc.execute :as sql-jdbc.execute] [metabase.driver.sql-jdbc.sync :as sql-jdbc.sync] - [metabase.models :as model] - [metabase.test.data.impl :as data.impl] [metabase.test.data.interface :as tx] [metabase.test.data.sql :as sql.tx] [metabase.test.data.sql-jdbc :as sql-jdbc.tx] [metabase.test.data.sql-jdbc.execute :as execute] [metabase.test.data.sql-jdbc.load-data :as load-data] - [metabase.util :as u] - [toucan.db :as db])) + [metabase.util :as u])) + +(set! *warn-on-reflection* true) (sql-jdbc.tx/add-test-extensions! :exasol) @@ -68,34 +65,6 @@ session-schema (tx/db-qualified-table-name database-name table-name))) -(defonce ^:private exasol-test-dbs-created-by-this-instance (atom #{})) - -(defn- destroy-test-database-if-created-in-different-session - [database-name] - (when-not (contains? @exasol-test-dbs-created-by-this-instance database-name) - (locking exasol-test-dbs-created-by-this-instance - (when-not (contains? @exasol-test-dbs-created-by-this-instance database-name) - (mdb/setup-db!) ; if not already setup - (when-let [existing-db (db/select-one model/Database :engine "exasol", :name database-name)] - (let [existing-db-id (u/the-id existing-db) - all-schemas (db/select-field :schema model/Table :db_id existing-db-id)] - (when-not (= all-schemas #{session-schema}) - (println - (str "[exasol] At least one table's schema for the existing '%s' Database" - " (id %d), which include all of [%s], does not match current session-schema" - " of %s; deleting this DB so it can be recreated") - database-name - existing-db-id - (str/join "," all-schemas) - session-schema) - (db/delete! model/Database :id existing-db-id)))) - (swap! exasol-test-dbs-created-by-this-instance conj database-name))))) - -(defmethod data.impl/get-or-create-database! :exasol - [driver dbdef] - (let [{:keys [database-name], :as dbdef} (tx/get-dataset-definition dbdef)] - (destroy-test-database-if-created-in-different-session database-name) - ((get-method data.impl/get-or-create-database! :sql-jdbc) driver dbdef))) (defmethod sql.tx/create-db-sql :exasol [& _] nil) @@ -120,7 +89,7 @@ (sql-jdbc.conn/connection-details->spec :exasol (connection-details))) (defn- non-session-schemas - "Return a set of the names of schemas (users) that are not meant for use in this test session (i.e., ones that should + "Return a set of the names of schemas that are not meant for use in this test session (i.e., ones that should be ignored). (This is used as part of the implementation of `excluded-schemas` for the Exasol driver during tests.)" [] (set (map :schema_name (jdbc/query (dbspec) ["SELECT schema_name FROM SYS.EXA_ALL_SCHEMAS WHERE schema_name <> ?" session-schema])))) diff --git a/test/metabase/test/data/exasol_dataset_definitions.clj b/test/metabase/test/data/exasol_dataset_definitions.clj index 811f2dc..d7e78dc 100644 --- a/test/metabase/test/data/exasol_dataset_definitions.clj +++ b/test/metabase/test/data/exasol_dataset_definitions.clj @@ -1,6 +1,7 @@ (ns metabase.test.data.exasol-dataset-definitions - (:require - [metabase.test.data.interface :as tx])) + (:require [metabase.test.data.interface :as tx])) + +(set! *warn-on-reflection* true) (tx/defdataset exasol-data-types "Test data with all Exasol specific data types" @@ -36,7 +37,7 @@ (tx/defdataset one-timestamp-per-day "Test data for week aggregation bug https://github.com/exasol/metabase-driver/issues/59" - (let [timestamps (map #(.plus (java.time.Instant/parse "2022-12-01T12:00:00.000Z") % java.time.temporal.ChronoUnit/DAYS) (range 0 70)) + (let [timestamps (map #(.plus (java.time.Instant/parse "2022-12-01T12:00:00.000Z") ^int % java.time.temporal.ChronoUnit/DAYS) (range 0 70)) rows (map (fn [timestamp] [timestamp]) timestamps)] [["timestamps"