-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
211 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
name: Check | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
paths-ignore: | ||
- "**.md" | ||
pull_request: | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
services: | ||
databend: | ||
image: datafuselabs/databend | ||
env: | ||
QUERY_DEFAULT_USER: databend | ||
QUERY_DEFAULT_PASSWORD: databend | ||
MINIO_ENABLED: true | ||
# options: >- | ||
# --health-cmd "curl -fs http://localhost:8000/v1/health || exit 1" | ||
# --health-interval 10s | ||
# --health-timeout 5s | ||
# --health-retries 5 | ||
ports: | ||
- 8000:8000 | ||
- 9000:9000 | ||
steps: | ||
- name: Verify Service Running | ||
run: | | ||
sleep 30 | ||
cid=$(docker ps -a | grep databend | cut -d' ' -f1) | ||
docker logs ${cid} | ||
curl -v http://localhost:8000/v1/health | ||
- name: Checkout Metabase Repo | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: metabase/metabase | ||
ref: v0.46.0-RC2 | ||
|
||
- name: Checkout Driver Repo | ||
uses: actions/checkout@v2 | ||
with: | ||
path: modules/drivers/databend | ||
|
||
- name: Prepare JDK 17 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: "temurin" | ||
java-version: "17" | ||
|
||
- name: Install Clojure CLI | ||
run: | | ||
curl -O https://download.clojure.org/install/linux-install-1.11.1.1182.sh && | ||
sudo bash ./linux-install-1.11.1.1182.sh | ||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "16" | ||
cache: "yarn" | ||
|
||
- name: Get M2 cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.m2 | ||
~/.gitlibs | ||
key: ${{ runner.os }}-databend-${{ hashFiles('**/deps.edn') }} | ||
|
||
- name: Prepare stuff for pulses | ||
run: yarn build-static-viz | ||
|
||
# Use custom deps.edn containing "user/databend" alias to include driver sources | ||
- name: Run tests | ||
run: | | ||
mkdir -p /home/runner/.config/clojure | ||
cat modules/drivers/databend/.github/deps.edn | sed -e "s|PWD|$PWD|g" > /home/runner/.config/clojure/deps.edn | ||
DRIVERS=databend clojure -X:dev:drivers:drivers-dev:test:user/databend | ||
- name: Build databend driver | ||
run: | | ||
echo "{:deps {metabase/databend {:local/root \"databend\" }}}" > modules/drivers/deps.edn | ||
bin/build-driver.sh databend | ||
ls -lah resources/modules | ||
- name: Archive driver JAR | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: databend.metabase-driver.jar | ||
path: resources/modules/databend.metabase-driver.jar | ||
|
||
- name: Report test results | ||
uses: mikepenz/action-junit-report@v2.8.1 | ||
if: always() | ||
with: | ||
report_paths: "**/target/junit/*.xml" | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{:aliases | ||
{:user/databend | ||
{:extra-paths ["PWD/modules/drivers/databend/test"] | ||
:extra-deps {metabase/databend {:local/root "PWD/modules/drivers/databend"}}}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,91 @@ | ||
(ns metabase.driver.databend-test | ||
(:require [clojure.test :refer :all] | ||
"Tests for specific behavior of the Databend driver." | ||
#_{:clj-kondo/ignore [:unsorted-required-namespaces]} | ||
(:require [cljc.java-time.format.date-time-formatter :as date-time-formatter] | ||
[cljc.java-time.local-date :as local-date] | ||
[cljc.java-time.offset-date-time :as offset-date-time] | ||
[cljc.java-time.temporal.chrono-unit :as chrono-unit] | ||
[clojure.test :refer :all] | ||
[metabase.driver :as driver] | ||
[metabase.driver.sql-jdbc | ||
[connection :as sql-jdbc.conn] | ||
[sync :as sql-jdbc.sync]] | ||
[metabase.driver.common :as driver.common] | ||
[metabase.driver.sql-jdbc.connection :as sql-jdbc.conn] | ||
[metabase.driver.sql-jdbc.sync :as sql-jdbc.sync] | ||
[metabase.models.database :refer [Database]] | ||
[metabase.query-processor :as qp] | ||
[metabase.query-processor-test :as qp.test] | ||
[metabase.test :as mt] | ||
[metabase.test.data :as data] | ||
[metabase.test.data | ||
[datasets :as datasets]] | ||
[metabase.test.data.sql.ddl :as ddl] | ||
[metabase.util.honeysql-extensions :as hx] | ||
[metabase.query-processor-test :as qp.test] | ||
[honeysql.core :as hsql] | ||
[metabase.driver.sql.query-processor :as sql.qp] | ||
[metabase.test.data.sql :as sql.tx] | ||
[metabase.test.data.interface :as tx] | ||
[metabase.test.data.dataset-definitions :as dataset-defs] | ||
[clojure.string :as str] | ||
[metabase.driver.common :as driver.common] | ||
[metabase.driver.sql.util.unprepare :as unprepare] | ||
[metabase | ||
[models :refer [Table]] | ||
[sync :as sync] | ||
[util :as u]] | ||
[clojure.java.jdbc :as jdbc] | ||
[toucan.db :as db] | ||
[metabase.models | ||
[database :refer [Database]]]) | ||
(:import [java.sql DatabaseMetaData Types Connection ResultSet] | ||
[java.time LocalTime OffsetDateTime OffsetTime ZonedDateTime])) | ||
[metabase.test.data [interface :as tx]] | ||
[metabase.test.data.databend :refer [default-connection-params]])) | ||
|
||
(deftest databend-server-timezone | ||
(deftest databend-connection-string | ||
(testing "connection with no additional options" | ||
(is (= default-connection-params | ||
(sql-jdbc.conn/connection-details->spec | ||
:databend | ||
{})))) | ||
(testing "custom connection with additional options" | ||
(is (= (merge | ||
default-connection-params | ||
{:subname "//mydatabend:9999/foo?connection_timeout=42" | ||
:user "bob" | ||
:password "qaz" | ||
:ssl true}) | ||
(sql-jdbc.conn/connection-details->spec | ||
:databend | ||
{:host "mydatabend" | ||
:port 9999 | ||
:user "bob" | ||
:password "qaz" | ||
:dbname "foo" | ||
:additional-options "connection_timeout=42" | ||
:ssl true})))) | ||
(testing "nil dbname handling" | ||
(is (= default-connection-params | ||
(sql-jdbc.conn/connection-details->spec | ||
:databend | ||
{:dbname nil}))))) | ||
|
||
(deftest databend-boolean-result-metadata | ||
(mt/test-driver | ||
:databend | ||
(is (= "UTC" | ||
(let [spec (sql-jdbc.conn/connection-details->spec :databend {})] | ||
(metabase.driver/db-default-timezone :databend spec)))))) | ||
(let [result (-> {:query "SELECT false, 123, true"} mt/native-query qp/process-query) | ||
[[c1 _ c3]] (-> result qp.test/rows)] | ||
(testing "column should be of type :type/Boolean" | ||
(is (= :type/Boolean (-> result :data :results_metadata :columns first :base_type))) | ||
(is (= :type/Boolean (transduce identity (driver.common/values->base-type) [c1, c3]))) | ||
(is (= :type/Boolean (driver.common/class->base-type (class c1)))))))) | ||
|
||
(deftest databend-describe-database | ||
(let [[boolean-table] | ||
[ | ||
{:description nil, | ||
:name "boolean_test", | ||
:schema "metabase_test"}]] | ||
(testing "scanning a single database" | ||
(mt/with-temp Database | ||
[db {:engine :databend | ||
:details {:dbname "metabase_test" | ||
:scan-all-databases nil}}] | ||
(let [describe-result (driver/describe-database :databend db)] | ||
(is (= | ||
{:tables | ||
#{boolean-table}} | ||
describe-result)))) | ||
(testing "scanning all databases" | ||
(mt/with-temp Database | ||
[db {:engine :databend | ||
:details {:dbname "default" | ||
:scan-all-databases true}}] | ||
(let [describe-result (driver/describe-database :databend db)] | ||
;; check the existence of at least some test tables here | ||
|
||
(is (contains? (:tables describe-result) | ||
boolean-table)) | ||
;; should not contain any Databend system tables | ||
(is (not (some #(= (get % :schema) "system") | ||
(:tables describe-result)))) | ||
(is (not (some #(= (get % :schema) "information_schema") | ||
(:tables describe-result)))) | ||
(is (not (some #(= (get % :schema) "INFORMATION_SCHEMA") | ||
(:tables describe-result)))))))))) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
(ns metabase.test.data.databend | ||
"Code for creating / destroying a Databend database from a `DatabaseDefinition`." | ||
(:require | ||
[metabase.driver.ddl.interface :as ddl.i] | ||
[metabase.driver.sql.util :as sql.u] | ||
[metabase.test.data | ||
[interface :as tx] | ||
[sql-jdbc :as sql-jdbc.tx]] | ||
[metabase.test.data.sql :as sql.tx] | ||
[metabase.test.data.sql-jdbc | ||
[execute :as execute] | ||
[load-data :as load-data]])) | ||
|
||
(sql-jdbc.tx/add-test-extensions! :databend) | ||
|
||
(def default-connection-params {:classname "com.databend.jdbc.DatabendDriver" | ||
:subprotocol "databend" | ||
:subname "//localhost:8000/default" | ||
:user "root" | ||
:password "root" | ||
:ssl false | ||
:product_name "metabase/1.1.2"}) |