From 2999620b9ab4ddb152796970ec3abcb2b7ff563f Mon Sep 17 00:00:00 2001 From: Bryan Maass <bryan.maass@gmail.com> Date: Wed, 21 Sep 2022 17:15:29 -0600 Subject: [PATCH] allow turning off mysql json unwrapping (#25556) * allow turning off mysql json unwrapping - somehow this value was set to always be true, but it should be toggle-able. --- src/metabase/driver/mysql.clj | 5 ++++- test/metabase/driver/mysql_test.clj | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/metabase/driver/mysql.clj b/src/metabase/driver/mysql.clj index 2eb5a0b9349..9c7c8c3555f 100644 --- a/src/metabase/driver/mysql.clj +++ b/src/metabase/driver/mysql.clj @@ -41,7 +41,10 @@ (defmethod driver/display-name :mysql [_] "MySQL") (defmethod driver/database-supports? [:mysql :nested-field-columns] [_ _ database] - (or (get-in database [:details :json-unfolding]) true)) + (let [json-setting (get-in database [:details :json-unfolding])] + (if (nil? json-setting) + true + json-setting))) (defmethod driver/database-supports? [:mysql :persist-models] [_driver _feat _db] true) diff --git a/test/metabase/driver/mysql_test.clj b/test/metabase/driver/mysql_test.clj index d50fd66c41b..f5eea112984 100644 --- a/test/metabase/driver/mysql_test.clj +++ b/test/metabase/driver/mysql_test.clj @@ -495,12 +495,26 @@ (is (= ["((floor(((convert(json_extract(json.json_bit, ?), BIGINT) - 0.75) / 0.75)) * 0.75) + 0.75)" "$.\"1234\""] (hsql/format (sql.qp/->honeysql :mysql field-clause))))))))))))) +(deftest can-shut-off-json-unwrapping + (mt/test-driver :mysql + ;; in here we fiddle with the mysql db details + (let [db (db/select-one Database :id (mt/id))] + (try + (db/update! Database (mt/id) {:details (assoc (:details db) :json-unfolding true)}) + (is (= true (driver/database-supports? :mysql :nested-field-columns (mt/db)))) + (db/update! Database (mt/id) {:details (assoc (:details db) :json-unfolding false)}) + (is (= false (driver/database-supports? :mysql :nested-field-columns (mt/db)))) + (db/update! Database (mt/id) {:details (assoc (:details db) :json-unfolding nil)}) + (is (= true (driver/database-supports? :mysql :nested-field-columns (mt/db)))) + ;; un fiddle with the mysql db details. + (finally (db/update! Database (mt/id) :details (:details db))))))) + (deftest ddl.execute-with-timeout-test (mt/test-driver :mysql (mt/dataset json (let [db-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))] (is (thrown-with-msg? Exception - #"Killed mysql process id \d+ due to timeout." + #"Killed mysql process id [\d,]+ due to timeout." (#'mysql.ddl/execute-with-timeout! db-spec db-spec 10 ["select sleep(5)"]))) (is (= true (#'mysql.ddl/execute-with-timeout! db-spec db-spec 5000 ["select sleep(0.1) as val"]))))))) -- GitLab