diff --git a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj index 74d3927f4381b100d398a362d8edb3c4e9821a0c..d100e80a72f429765e11a8805fc3533ecb45f506 100644 --- a/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj +++ b/enterprise/backend/test/metabase_enterprise/sandbox/query_processor/middleware/row_level_restrictions_test.clj @@ -915,8 +915,6 @@ (deftest pivot-query-test (mt/test-drivers (disj (mt/normal-drivers-with-feature :foreign-keys :nested-queries :left-join) - ;; sample-dataset doesn't work on Redshift yet -- see #14784 - :redshift ;; this test relies on a FK relation between $product_id->products.category, so skip for Presto ;; JDBC, because that driver doesn't support resolving FKs from the JDBC metadata :presto-jdbc) diff --git a/modules/drivers/redshift/test/metabase/test/data/redshift.clj b/modules/drivers/redshift/test/metabase/test/data/redshift.clj index 0ea1b4948ac598899800a6a987f123cc250843b3..20df51a7d52084cd4b2f10584b478b306ee61687 100644 --- a/modules/drivers/redshift/test/metabase/test/data/redshift.clj +++ b/modules/drivers/redshift/test/metabase/test/data/redshift.clj @@ -4,6 +4,7 @@ [metabase.driver.sql-jdbc.sync :as sql-jdbc.sync] [metabase.test.data.interface :as tx] [metabase.test.data.sql :as sql.tx] + [metabase.test.data.sql-jdbc.load-data :as load-data] [metabase.test.data.sql.ddl :as ddl] [metabase.util :as u])) @@ -18,7 +19,11 @@ :type/Decimal "DECIMAL" :type/Float "FLOAT8" :type/Integer "INTEGER" - :type/Text "TEXT"}] + ;; Use VARCHAR because TEXT in Redshift is VARCHAR(256) + ;; https://docs.aws.amazon.com/redshift/latest/dg/r_Character_types.html#r_Character_types-varchar-or-character-varying + ;; But don't use VARCHAR(MAX) either because of performance impact + ;; https://docs.aws.amazon.com/redshift/latest/dg/c_best-practices-smallest-column-size.html + :type/Text "VARCHAR(1024)"}] (defmethod sql.tx/field-base-type->sql-type [:redshift base-type] [_ _] database-type)) ;; If someone tries to run Time column tests with Redshift give them a heads up that Redshift does not support it @@ -65,6 +70,15 @@ [& args] (apply sql.tx/drop-table-if-exists-cascade-sql args)) +(defmethod load-data/load-data! :redshift + [driver {:keys [database-name], :as dbdef} {:keys [table-name], :as tabledef}] + (load-data/load-data-all-at-once! driver dbdef tabledef) + (let [table-identifier (sql.tx/qualify-and-quote :redshift database-name table-name) + spec (sql-jdbc.conn/connection-details->spec :redshift @db-connection-details)] + ;; VACUUM and ANALYZE after insert to improve performance (according to doc) + (jdbc/execute! spec (str "VACUUM " table-identifier) {:transaction? false}) + (jdbc/execute! spec (str "ANALYZE " table-identifier) {:transaction? false}))) + ;;; Create + destroy the schema used for this test session (defn execute! [format-string & args] diff --git a/test/metabase/api/dataset_test.clj b/test/metabase/api/dataset_test.clj index 3c29988debe3fc418f2fbd978666f8e33854bf13..db70dac29b1189c153dcfa846915871de1ccac20 100644 --- a/test/metabase/api/dataset_test.clj +++ b/test/metabase/api/dataset_test.clj @@ -319,7 +319,7 @@ ;; this only works on a handful of databases -- most of them don't allow you to ask for a Field that isn't in ;; the GROUP BY expression - (when (#{:bigquery :mongo :presto :redshift :h2 :sqlite} metabase.driver/*driver*) + (when (#{:bigquery :mongo :presto :h2 :sqlite} metabase.driver/*driver*) (testing "with an added expression" ;; the added expression is coming back in this query because it is explicitly included in `:fields` -- see ;; comments on `metabase.query-processor.pivot-test/pivots-should-not-return-expressions-test`. diff --git a/test/metabase/api/pivots.clj b/test/metabase/api/pivots.clj index efa20cc2e3fbc5267db629ffade54c6acdb04887..8a37c745ae9d8ed6a0441a49b2d0763063234a5e 100644 --- a/test/metabase/api/pivots.clj +++ b/test/metabase/api/pivots.clj @@ -1,14 +1,10 @@ (ns metabase.api.pivots (:require [metabase.test :as mt])) -;; Redshift takes A LONG TIME to insert the sample-dataset, so do not -;; run these tests against Redshift (for now?) -;;TODO: refactor Redshift testing to support a bulk COPY or something -;; other than INSERT INTO statements (defn applicable-drivers "Drivers that these pivot table tests should run on" [] - (disj (mt/normal-drivers-with-feature :expressions :left-join) :redshift)) + (mt/normal-drivers-with-feature :expressions :left-join)) (defn pivot-query "A basic pivot table query" diff --git a/test/metabase/query_processor_test/case_test.clj b/test/metabase/query_processor_test/case_test.clj index 4c9de7ea3ee7f8017ca8045a56b764ea41638b64..a81af764c92844798c68850ea2aea64b60868f8a 100644 --- a/test/metabase/query_processor_test/case_test.clj +++ b/test/metabase/query_processor_test/case_test.clj @@ -86,8 +86,7 @@ (deftest two-case-functions-test (testing "We should support expressions with two case statements (#15107)" - ;; sample-dataset doesn't work on Redshift yet -- see #14784 - (mt/test-drivers (disj (mt/normal-drivers-with-feature :expressions) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :expressions) (mt/dataset sample-dataset (is (= [[1 "1018947080336" diff --git a/test/metabase/query_processor_test/explicit_joins_test.clj b/test/metabase/query_processor_test/explicit_joins_test.clj index d0d59054b7ccdf93a14bec1175d550b9de941d86..83a3d19b418f0a565d859c5955282cc8ba09da5e 100644 --- a/test/metabase/query_processor_test/explicit_joins_test.clj +++ b/test/metabase/query_processor_test/explicit_joins_test.clj @@ -521,8 +521,7 @@ (deftest join-source-queries-with-joins-test (testing "Should be able to join against source queries that themselves contain joins (#12928)" - ;; sample-dataset doesn't work on Redshift yet -- see #14784 - (mt/test-drivers (disj (mt/normal-drivers-with-feature :nested-queries :left-join :foreign-keys) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :nested-queries :left-join :foreign-keys) (mt/dataset sample-dataset (testing "(#12928)" (let [query (mt/mbql-query orders @@ -550,6 +549,8 @@ :alias "P2"}] :aggregation [[:avg $reviews.rating]] :breakout [&P2.products.category]}}] + :order-by [[:asc &P1.products.category] + [:asc [:field %people.source {:join-alias "People"}]]] :limit 2})] (is (= [["Doohickey" "Affiliate" 783 "Doohickey" 3] ["Doohickey" "Facebook" 816 "Doohickey" 3]] diff --git a/test/metabase/query_processor_test/expression_aggregations_test.clj b/test/metabase/query_processor_test/expression_aggregations_test.clj index efcd2022a3a9487094d11012051cc5d05e0570a5..a3e43c699d9a607f2f8487337de3e59778387d1f 100644 --- a/test/metabase/query_processor_test/expression_aggregations_test.clj +++ b/test/metabase/query_processor_test/expression_aggregations_test.clj @@ -275,8 +275,7 @@ :expressions {"double-price" [:* $price 2]}}))))))) #_(deftest multiple-cumulative-sums-test - ;; sample-dataset doesn't work on Redshift yet -- see #14784 - (mt/test-drivers (disj (mt/normal-drivers-with-feature :expression-aggregations) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :expression-aggregations) (testing "The results of divide or multiply two CumulativeSum should be correct (#15118)" (mt/dataset sample-dataset (is (= [["2016-01-01T00:00:00Z" 3236 2458.0 5694.0 1] diff --git a/test/metabase/query_processor_test/expressions_test.clj b/test/metabase/query_processor_test/expressions_test.clj index 5b9a45cb15fd52dc833fc36144ad60e7846a6008..6643cc4f2bfe566d70c52e06fde3fa4e982af443 100644 --- a/test/metabase/query_processor_test/expressions_test.clj +++ b/test/metabase/query_processor_test/expressions_test.clj @@ -373,8 +373,7 @@ [:field "min" {:base-type :type/Number}]]}}))))))) (deftest fk-field-and-duplicate-names-test - ;; Redshift hangs on sample-dataset -- See #14784 - (mt/test-drivers (disj (mt/normal-drivers-with-feature :expressions :foreign-keys) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :expressions :foreign-keys) (testing "Expressions with `fk->` fields and duplicate names should work correctly (#14854)" (mt/dataset sample-dataset (let [results (mt/run-mbql-query orders diff --git a/test/metabase/query_processor_test/implicit_joins_test.clj b/test/metabase/query_processor_test/implicit_joins_test.clj index bb6ad4eb2a796cf0106b549535ac5602ecfa4264..52f6103ab450347c523860a2e5d785ef988c08b8 100644 --- a/test/metabase/query_processor_test/implicit_joins_test.clj +++ b/test/metabase/query_processor_test/implicit_joins_test.clj @@ -139,8 +139,7 @@ :filter [:= $receiver_id->users.name "Rasta Toucan"]})))))))) (deftest implicit-joins-with-expressions-test - ;; Redshift excluded for now since the sample dataset seems to hang for Redshift -- see #14784 - (mt/test-drivers (disj (mt/normal-drivers-with-feature :foreign-keys :expressions) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :foreign-keys :expressions) (testing "Should be able to run query with multiple implicit joins and breakouts" (mt/dataset sample-dataset (is (= [["Doohickey" "Facebook" "2019-01-01T00:00:00Z" 0 263] diff --git a/test/metabase/query_processor_test/nested_queries_test.clj b/test/metabase/query_processor_test/nested_queries_test.clj index bf24725b3c795bcb29c6494106b3ccee25bc148e..656883f043e6e1e2946c20c4184e9067e57aab4e 100644 --- a/test/metabase/query_processor_test/nested_queries_test.clj +++ b/test/metabase/query_processor_test/nested_queries_test.clj @@ -1051,8 +1051,7 @@ :value "Widget"}]}))))))) (deftest nested-queries-with-expressions-and-joins-test - ;; sample-dataset doesn't work on Redshift yet -- see #14784 - (mt/test-drivers (disj (mt/normal-drivers-with-feature :foreign-keys :nested-queries :left-join) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :foreign-keys :nested-queries :left-join) (mt/dataset sample-dataset (testing "Do nested queries in combination with joins and expressions still work correctly? (#14969)" ;; not sure why Snowflake has slightly different results @@ -1104,7 +1103,7 @@ :fk-field-id %product_id}]})))))))) (deftest multi-level-aggregations-with-post-aggregation-filtering-test - (mt/test-drivers (disj (mt/normal-drivers-with-feature :foreign-keys :nested-queries) :redshift) ; sample-dataset doesn't work on Redshift yet -- see #14784 + (mt/test-drivers (mt/normal-drivers-with-feature :foreign-keys :nested-queries) (testing "Multi-level aggregations with filter is the last section (#14872)" (mt/dataset sample-dataset ;; not 100% sure why Snowflake has slightly different results @@ -1133,7 +1132,7 @@ :filter [:> *sum/Float 100]})))))))) (deftest date-range-test - (mt/test-drivers (disj (mt/normal-drivers-with-feature :foreign-keys :nested-queries) :redshift) ; sample-dataset doesn't work on Redshift yet -- see #14784 + (mt/test-drivers (mt/normal-drivers-with-feature :foreign-keys :nested-queries) (testing "Date ranges should work the same in nested queries as is regular queries (#15352)" (mt/dataset sample-dataset (let [q1 (mt/mbql-query orders @@ -1181,13 +1180,11 @@ (deftest nested-query-with-expressions-test (testing "Nested queries with expressions should work in top-level native queries (#12236)" - (mt/test-drivers (disj (mt/normal-drivers-with-feature - :nested-queries - :basic-aggregations - :expression-aggregations - :foreign-keys) - ;; sample-dataset doesn't work on Redshift yet -- see #14784 - :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature + :nested-queries + :basic-aggregations + :expression-aggregations + :foreign-keys) (mt/dataset sample-dataset (mt/with-temp Card [card {:dataset_query (mt/mbql-query orders {:filter [:between $total 30 60] diff --git a/test/metabase/query_processor_test/remapping_test.clj b/test/metabase/query_processor_test/remapping_test.clj index 3882e2fdf754e1ed79773d87945eb1d7017f29e1..70b172130f58abfdf67e7102c8e2b861ca17349e 100644 --- a/test/metabase/query_processor_test/remapping_test.clj +++ b/test/metabase/query_processor_test/remapping_test.clj @@ -202,8 +202,7 @@ )))) (deftest remappings-with-implicit-joins-test - ;; Redshift excluded for now since the sample dataset seems to hang for Redshift. - (mt/test-drivers (disj (mt/normal-drivers-with-feature :foreign-keys :nested-queries) :redshift) + (mt/test-drivers (mt/normal-drivers-with-feature :foreign-keys :nested-queries) (testing "Queries with implicit joins should still work when FK remaps are used (#13641)" (mt/dataset sample-dataset (mt/with-column-remappings [orders.product_id products.title]