|
5 | 5 | [cljc.java-time.local-date :as local-date]
|
6 | 6 | [cljc.java-time.offset-date-time :as offset-date-time]
|
7 | 7 | [cljc.java-time.temporal.chrono-unit :as chrono-unit]
|
| 8 | + [clojure.string :as str] |
8 | 9 | [clojure.test :refer :all]
|
9 | 10 | [metabase.driver :as driver]
|
10 | 11 | [metabase.driver.clickhouse-test-utils :as ctu]
|
|
438 | 439 | {:filter [:= $ipvfour "127.0.0.1"]
|
439 | 440 | :aggregation [:count]})))))))))
|
440 | 441 |
|
| 442 | +(defn- map-as-string [^java.util.LinkedHashMap m] (.toString m)) |
| 443 | +(deftest clickhouse-simple-map-test |
| 444 | + (mt/test-driver |
| 445 | + :clickhouse |
| 446 | + (is (= [["{key1=1, key2=10}"] ["{key1=2, key2=20}"] ["{key1=3, key2=30}"]] |
| 447 | + (qp.test/formatted-rows |
| 448 | + [map-as-string] |
| 449 | + :format-nil-values |
| 450 | + (ctu/do-with-metabase-test-db |
| 451 | + (fn [db] |
| 452 | + (data/with-db db |
| 453 | + (data/run-mbql-query |
| 454 | + maps_test |
| 455 | + {}))))))))) |
| 456 | + |
441 | 457 | (deftest clickhouse-connection-string
|
442 | 458 | (testing "connection with no additional options"
|
443 | 459 | (is (= default-connection-params
|
|
481 | 497 | (deftest clickhouse-boolean-tabledef-metadata
|
482 | 498 | (mt/test-driver
|
483 | 499 | :clickhouse
|
484 |
| - (let [table_md (ctu/do-with-metabase-test-db |
485 |
| - (fn [db] (metabase.driver/describe-table :clickhouse db {:name "boolean_test"}))) |
| 500 | + (let [table_md (ctu/do-with-metabase-test-db |
| 501 | + (fn [db] |
| 502 | + (metabase.driver/describe-table :clickhouse db {:name "boolean_test"}))) |
486 | 503 | colmap (->> (.get table_md :fields)
|
487 | 504 | (filter #(= (:name %) "b1")) first)
|
488 | 505 | database-type (.get colmap :database-type)
|
|
544 | 561 | {})))))))))))
|
545 | 562 |
|
546 | 563 | (deftest clickhouse-describe-database
|
547 |
| - (let [[agg-fn-table boolean-table enum-table ipaddress-table] |
548 |
| - [{:description nil, |
549 |
| - :name "aggregate_functions_filter_test", |
550 |
| - :schema "metabase_test"} |
551 |
| - {:description nil, |
552 |
| - :name "boolean_test", |
553 |
| - :schema "metabase_test"} |
554 |
| - {:description nil, |
555 |
| - :name "enums_test", |
556 |
| - :schema "metabase_test"} |
557 |
| - {:description nil, |
558 |
| - :name "ipaddress_test", |
559 |
| - :schema "metabase_test"}]] |
| 564 | + (let [test-tables |
| 565 | + #{{:description nil, |
| 566 | + :name "aggregate_functions_filter_test", |
| 567 | + :schema "metabase_test"} |
| 568 | + {:description nil, |
| 569 | + :name "boolean_test", |
| 570 | + :schema "metabase_test"} |
| 571 | + {:description nil, |
| 572 | + :name "enums_test", |
| 573 | + :schema "metabase_test"} |
| 574 | + {:description nil, |
| 575 | + :name "ipaddress_test", |
| 576 | + :schema "metabase_test"} |
| 577 | + {:description nil, |
| 578 | + :name "wikistat", |
| 579 | + :schema "metabase_test"} |
| 580 | + {:description nil, |
| 581 | + :name "wikistat_mv", |
| 582 | + :schema "metabase_test"} |
| 583 | + {:description nil, |
| 584 | + :name "maps_test", |
| 585 | + :schema "metabase_test"}}] |
560 | 586 | (testing "scanning a single database"
|
561 | 587 | (mt/with-temp Database
|
562 | 588 | [db {:engine :clickhouse
|
563 | 589 | :details {:dbname "metabase_test"
|
564 | 590 | :scan-all-databases nil}}]
|
565 | 591 | (let [describe-result (driver/describe-database :clickhouse db)]
|
566 | 592 | (is (=
|
567 |
| - {:tables |
568 |
| - #{agg-fn-table boolean-table enum-table ipaddress-table}} |
| 593 | + {:tables test-tables} |
569 | 594 | describe-result)))))
|
570 | 595 | (testing "scanning all databases"
|
571 | 596 | (mt/with-temp Database
|
|
574 | 599 | :scan-all-databases true}}]
|
575 | 600 | (let [describe-result (driver/describe-database :clickhouse db)]
|
576 | 601 | ;; check the existence of at least some test tables here
|
577 |
| - (is (contains? (:tables describe-result) |
578 |
| - agg-fn-table)) |
579 |
| - (is (contains? (:tables describe-result) |
580 |
| - boolean-table)) |
581 |
| - (is (contains? (:tables describe-result) |
582 |
| - enum-table)) |
583 |
| - (is (contains? (:tables describe-result) |
584 |
| - ipaddress-table)) |
| 602 | + (doseq [table test-tables] |
| 603 | + (is (contains? (:tables describe-result) |
| 604 | + table))) |
585 | 605 | ;; should not contain any ClickHouse system tables
|
586 |
| - (is (not (some #(= (get % :schema) "system") |
| 606 | + (is (not (some #(= (:schema %) "system") |
587 | 607 | (:tables describe-result))))
|
588 |
| - (is (not (some #(= (get % :schema) "information_schema") |
| 608 | + (is (not (some #(= (:schema %) "information_schema") |
589 | 609 | (:tables describe-result))))
|
590 |
| - (is (not (some #(= (get % :schema) "INFORMATION_SCHEMA") |
| 610 | + (is (not (some #(= (:schema %) "INFORMATION_SCHEMA") |
591 | 611 | (:tables describe-result)))))))
|
592 | 612 | (testing "scanning multiple databases"
|
593 | 613 | (mt/with-temp Database
|
|
602 | 622 | :description nil
|
603 | 623 | :schema "information_schema"}]
|
604 | 624 |
|
605 |
| - ;; NOTE: tables from `metabase_test` |
606 |
| - (is (contains? tables agg-fn-table)) |
607 |
| - (is (contains? tables boolean-table)) |
608 |
| - (is (contains? tables enum-table)) |
609 |
| - (is (contains? tables ipaddress-table)) |
| 625 | + ;; tables from `metabase_test` |
| 626 | + (doseq [table test-tables] |
| 627 | + (is (contains? tables table))) |
610 | 628 |
|
611 |
| - ;; NOTE: tables from `information_schema` |
| 629 | + ;; tables from `information_schema` |
612 | 630 | (is (contains? tables tables-table))
|
613 | 631 | (is (contains? tables columns-table)))))))
|
0 commit comments