diff --git a/src/metabase/driver/sql_jdbc/sync/describe_table.clj b/src/metabase/driver/sql_jdbc/sync/describe_table.clj index 6d09370313d21ab3d9ae84dd3bbd3da560d76b33..5fb965aeb5193a7d1e374b90e4d7c1599a5754f3 100644 --- a/src/metabase/driver/sql_jdbc/sync/describe_table.clj +++ b/src/metabase/driver/sql_jdbc/sync/describe_table.clj @@ -316,7 +316,7 @@ This is the lowest common denominator of types, hopefully, although as of writing this is just geared towards Postgres types" {:type/Text "text" - :type/Integer "integer" + :type/Integer "bigint" ;; You might think that the ordinary 'bigint' type in Postgres and MySQL should be this. ;; However, Bigint in those DB's maxes out at 2 ^ 64. ;; JSON, like Javascript itself, will happily represent 1.8 * (10^308), diff --git a/test/metabase/driver/mysql_test.clj b/test/metabase/driver/mysql_test.clj index 0e6e02036f6fc3685007e6dd43154d9d96de44d5..517adf78a1f91e66178f623ea3527ae4099fe2dd 100644 --- a/test/metabase/driver/mysql_test.clj +++ b/test/metabase/driver/mysql_test.clj @@ -391,7 +391,7 @@ :visibility-type :normal, :nfc-path [:json_bit "genres"]} {:name "json_bit → 1234", - :database-type "integer", + :database-type "bigint", :base-type :type/Integer, :database-position 0, :visibility-type :normal, @@ -445,12 +445,12 @@ (deftest json-query-test (let [boop-identifier (:form (hx/with-type-info (hx/identifier :field "boop" "bleh -> meh") {}))] (testing "Transforming MBQL query with JSON in it to mysql query works" - (let [boop-field {:nfc_path [:bleh :meh] :database_type "integer"}] - (is (= ["convert(json_extract(boop.bleh, ?), SIGNED)" "$.\"meh\""] + (let [boop-field {:nfc_path [:bleh :meh] :database_type "bigint"}] + (is (= ["convert(json_extract(boop.bleh, ?), BIGINT)" "$.\"meh\""] (hsql/format (#'sql.qp/json-query :mysql boop-identifier boop-field)))))) (testing "What if types are weird and we have lists" - (let [weird-field {:nfc_path [:bleh "meh" :foobar 1234] :database_type "integer"}] - (is (= ["convert(json_extract(boop.bleh, ?), SIGNED)" "$.\"meh\".\"foobar\".\"1234\""] + (let [weird-field {:nfc_path [:bleh "meh" :foobar 1234] :database_type "bigint"}] + (is (= ["convert(json_extract(boop.bleh, ?), BIGINT)" "$.\"meh\".\"foobar\".\"1234\""] (hsql/format (#'sql.qp/json-query :mysql boop-identifier weird-field)))))) (testing "Doesn't complain when field is boolean" (let [boolean-boop-field {:database_type "boolean" :nfc_path [:bleh "boop" :foobar 1234]}] @@ -471,9 +471,9 @@ :query {:source-table (u/the-id table) :aggregation [[:count]] :breakout [[:field (u/the-id field) nil]]}})] - (is (= (str "SELECT convert(json_extract(json.json_bit, ?), SIGNED) AS `json_bit → 1234`, " - "count(*) AS `count` FROM `json` GROUP BY convert(json_extract(json.json_bit, ?), SIGNED) " - "ORDER BY convert(json_extract(json.json_bit, ?), SIGNED) ASC") + (is (= (str "SELECT convert(json_extract(json.json_bit, ?), BIGINT) AS `json_bit → 1234`, " + "count(*) AS `count` FROM `json` GROUP BY convert(json_extract(json.json_bit, ?), BIGINT) " + "ORDER BY convert(json_extract(json.json_bit, ?), BIGINT) ASC") (:query compile-res))) (is (= '("$.\"1234\"" "$.\"1234\"" "$.\"1234\"") (:params compile-res)))))))))) @@ -493,7 +493,7 @@ :min-value 0.75, :max-value 54.0, :bin-width 0.75}}]] - (is (= ["((floor(((convert(json_extract(json.json_bit, ?), SIGNED) - 0.75) / 0.75)) * 0.75) + 0.75)" "$.\"1234\""] + (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 ddl.execute-with-timeout-test diff --git a/test/metabase/driver/postgres_test.clj b/test/metabase/driver/postgres_test.clj index bc3d9bf3356cc356d0fbab5bf3dbf29a1e537838..e7caafb21647a18a4bfde839a52d1feb3204a8d6 100644 --- a/test/metabase/driver/postgres_test.clj +++ b/test/metabase/driver/postgres_test.clj @@ -289,12 +289,12 @@ (deftest ^:parallel json-query-test (let [boop-identifier (:form (hx/with-type-info (hx/identifier :field "boop" "bleh -> meh") {}))] (testing "Transforming MBQL query with JSON in it to postgres query works" - (let [boop-field {:nfc_path [:bleh :meh] :database_type "integer"}] - (is (= ["(boop.bleh#>> ?::text[])::integer " "{meh}"] + (let [boop-field {:nfc_path [:bleh :meh] :database_type "bigint"}] + (is (= ["(boop.bleh#>> ?::text[])::bigint " "{meh}"] (hsql/format (#'sql.qp/json-query :postgres boop-identifier boop-field)))))) (testing "What if types are weird and we have lists" - (let [weird-field {:nfc_path [:bleh "meh" :foobar 1234] :database_type "integer"}] - (is (= ["(boop.bleh#>> ?::text[])::integer " "{meh,foobar,1234}"] + (let [weird-field {:nfc_path [:bleh "meh" :foobar 1234] :database_type "bigint"}] + (is (= ["(boop.bleh#>> ?::text[])::bigint " "{meh,foobar,1234}"] (hsql/format (#'sql.qp/json-query :postgres boop-identifier weird-field)))))) (testing "Give us a boolean cast when the field is boolean" (let [boolean-boop-field {:database_type "boolean" :nfc_path [:bleh "boop" :foobar 1234]}] @@ -385,13 +385,13 @@ :nfc-path [:incoherent_json_val "b"] :visibility-type :normal} {:name "coherent_json_val → a", - :database-type "integer", + :database-type "bigint", :base-type :type/Integer, :database-position 0, :nfc-path [:coherent_json_val "a"] :visibility-type :normal} {:name "coherent_json_val → b", - :database-type "integer", + :database-type "bigint", :base-type :type/Integer, :database-position 0, :nfc-path [:coherent_json_val "b"] @@ -409,7 +409,7 @@ :visibility-type :normal, :nfc-path [:incoherent_json_val "c"]} {:name "incoherent_json_val → d", - :database-type "integer", + :database-type "bigint", :base-type :type/Integer, :database-position 0, :visibility-type :normal, @@ -432,7 +432,7 @@ "INSERT INTO bobdobbs.describe_json_table (trivial_json) VALUES ('{\"a\": 1}');")])) (mt/with-temp Database [database {:engine :postgres, :details details}] (is (= #{{:name "trivial_json → a", - :database-type "integer", + :database-type "bigint", :base-type :type/Integer, :database-position 0, :visibility-type :normal, @@ -455,7 +455,7 @@ "INSERT INTO \"AAAH_#\".\"dESCribe_json_table_%\" (trivial_json) VALUES ('{\"a\": 1}');")])) (mt/with-temp Database [database {:engine :postgres, :details details}] (is (= #{{:name "trivial_json → a", - :database-type "integer", + :database-type "bigint", :base-type :type/Integer, :database-position 0, :visibility-type :normal,