Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate redshift flakes by not dropping view in test #41876

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 18 additions & 22 deletions modules/drivers/redshift/test/metabase/driver/redshift_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,25 @@
(t2.with-temp/with-temp [Database database {:engine :redshift, :details db-details}]
(let [view-nm (tx/db-qualified-table-name (:name database) "lbv")
qual-view-nm (format "\"%s\".\"%s\"" (redshift.test/unique-session-schema) view-nm)]
(try
(execute!
(str "CREATE OR REPLACE VIEW %1$s AS ("
"WITH test_data AS (SELECT 'open' AS shop_status UNION ALL SELECT 'closed' AS shop_status) "
"SELECT NULL as raw_null, "
"'hello' as raw_var, "
"CASE WHEN shop_status = 'open' THEN 11387.133 END AS case_when_numeric_inc_nulls "
"FROM test_data) WITH NO SCHEMA BINDING;")
qual-view-nm)
(binding [sync-util/*log-exceptions-and-continue?* false]
(sync/sync-database! database {:scan :schema}))
(is (contains?
(t2/select-fn-set :name Table :db_id (u/the-id database)) ; the new view should have been synced without errors
view-nm))
(let [table-id (t2/select-one-pk Table :db_id (u/the-id database), :name view-nm)]
(execute!
(str "CREATE OR REPLACE VIEW %1$s AS ("
"WITH test_data AS (SELECT 'open' AS shop_status UNION ALL SELECT 'closed' AS shop_status) "
"SELECT NULL as raw_null, "
"'hello' as raw_var, "
"CASE WHEN shop_status = 'open' THEN 11387.133 END AS case_when_numeric_inc_nulls "
"FROM test_data) WITH NO SCHEMA BINDING;")
qual-view-nm)
(binding [sync-util/*log-exceptions-and-continue?* false]
(sync/sync-database! database {:scan :schema}))
(is (contains?
(t2/select-fn-set :name Table :db_id (u/the-id database)) ; the new view should have been synced without errors
view-nm))
(let [table-id (t2/select-one-pk Table :db_id (u/the-id database), :name view-nm)]
;; and its columns' :base_type should have been identified correctly
(is (= [{:name "case_when_numeric_inc_nulls", :database_type "numeric", :base_type :type/Decimal}
{:name "raw_null", :database_type "character varying", :base_type :type/Text}
{:name "raw_var", :database_type "character varying", :base_type :type/Text}]
(t2/select [Field :name :database_type :base_type] :table_id table-id {:order-by [:name]}))))
(finally
(execute! (str "DROP VIEW IF EXISTS %s;")
qual-view-nm)))))))))
(is (= [{:name "case_when_numeric_inc_nulls", :database_type "numeric", :base_type :type/Decimal}
{:name "raw_null", :database_type "character varying", :base_type :type/Text}
{:name "raw_var", :database_type "character varying", :base_type :type/Text}]
(t2/select [Field :name :database_type :base_type] :table_id table-id {:order-by [:name]}))))))))))

(deftest describe-database-privileges-test
(mt/test-driver :redshift
Expand Down