Skip to content
Snippets Groups Projects
Unverified Commit 4eb558a8 authored by Howon Lee's avatar Howon Lee Committed by GitHub
Browse files

Use big types when we have big JSON contents (whacks #22732) (#23221)

Previously we defaulted to integer and float type in all cases for json unfolding type determination, even with bigints and bigdecimals. Now if we encounter a bignum in json unfolding we call it a bignum.
parent 1ac2c8c8
No related branches found
No related tags found
No related merge requests found
......@@ -297,8 +297,10 @@
{java.lang.String :type/Text
;; JSON itself has the single number type, but Java serde of JSON is stricter
java.lang.Long :type/Integer
clojure.lang.BigInt :type/BigInteger
java.lang.Integer :type/Integer
java.lang.Double :type/Float
java.math.BigDecimal :type/Decimal
java.lang.Number :type/Number
java.lang.Boolean :type/Boolean
java.time.LocalDateTime :type/DateTime
......@@ -312,8 +314,10 @@
although as of writing this is just geared towards Postgres types"
{:type/Text "text"
:type/Integer "integer"
:type/BigInteger "bigint"
:type/Float "double precision"
:type/Number "double precision"
:type/Decimal "decimal"
:type/Boolean "boolean"
:type/DateTime "timestamp"
:type/Array "text"
......
......@@ -298,6 +298,10 @@
(testing "Give us a boolean cast when the field is boolean"
(let [boolean-boop-field {:database_type "boolean" :nfc_path [:bleh "boop" :foobar 1234]}]
(is (= ["(boop.bleh#>> ?::text[])::boolean " "{boop,foobar,1234}"]
(hsql/format (#'sql.qp/json-query :postgres boop-identifier boolean-boop-field))))))
(testing "Give us a bigint cast when the field is bigint (#22732)"
(let [boolean-boop-field {:database_type "bigint" :nfc_path [:bleh "boop" :foobar 1234]}]
(is (= ["(boop.bleh#>> ?::text[])::bigint " "{boop,foobar,1234}"]
(hsql/format (#'sql.qp/json-query :postgres boop-identifier boolean-boop-field))))))))
(deftest json-alias-test
......
......@@ -80,7 +80,12 @@
(let [arr-row {:bob [:bob :cob :dob 123 "blob"]}
obj-row {:zlob {"blob" 1323}}]
(is (= {} (#'sql-jdbc.describe-table/row->types arr-row)))
(is (= {[:zlob "blob"] java.lang.Long} (#'sql-jdbc.describe-table/row->types obj-row))))))
(is (= {[:zlob "blob"] java.lang.Long} (#'sql-jdbc.describe-table/row->types obj-row)))))
(testing "JSON row->types handles bigint OK (#21752)"
(let [int-row {:zlob {"blob" 123N}}
float-row {:zlob {"blob" 1234.02M}}]
(is (= {[:zlob "blob"] clojure.lang.BigInt} (#'sql-jdbc.describe-table/row->types int-row)))
(is (= {[:zlob "blob"] java.math.BigDecimal} (#'sql-jdbc.describe-table/row->types float-row))))))
(deftest dont-parse-long-json-xform-test
(testing "obnoxiously long json should not even get parsed (#22636)"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment