diff --git a/modules/drivers/mongo/src/metabase/driver/mongo/conversion.clj b/modules/drivers/mongo/src/metabase/driver/mongo/conversion.clj index 5a70474f1c6cd427bf31839466d8b236add44573..1125b847ae7f18522989ec6896caa08f30141483 100644 --- a/modules/drivers/mongo/src/metabase/driver/mongo/conversion.clj +++ b/modules/drivers/mongo/src/metabase/driver/mongo/conversion.clj @@ -37,7 +37,11 @@ org.bson.types.Decimal128 (from-document [^org.bson.types.Decimal128 input _opts] - (.bigDecimalValue input)) + ;; As per https://mongodb.github.io/mongo-java-driver/5.1/apidocs/bson/org/bson/types/Decimal128.html#bigDecimalValue() + ;; org.bson.types.Decimal128/POSITIVE_ZERO is convertible to big decimal. + (if (.equals input org.bson.types.Decimal128/NEGATIVE_ZERO) + 0M + (.bigDecimalValue input))) java.util.List (from-document [^java.util.List input opts] diff --git a/modules/drivers/mongo/test/metabase/driver/mongo/conversion_test.clj b/modules/drivers/mongo/test/metabase/driver/mongo/conversion_test.clj index 9ead5932b568157c459d6383952328a6b2deb6af..d01b9e0688555ed46cb174ffaf30d345c88cb769 100644 --- a/modules/drivers/mongo/test/metabase/driver/mongo/conversion_test.clj +++ b/modules/drivers/mongo/test/metabase/driver/mongo/conversion_test.clj @@ -26,3 +26,14 @@ (-> mseqk mongo.conversion/to-document (mongo.conversion/from-document {:keywordize true})))) (is (= mseqs (-> mseqs mongo.conversion/to-document (mongo.conversion/from-document nil)))))))) + +(deftest bson-negative-zero->big-decimal-test + (testing "Bson Decimal128 zero is converted to BigDecimal zero" + (is (= {"negativeZero" 0M} + (mongo.conversion/from-document + (org.bson.Document. "negativeZero" org.bson.types.Decimal128/NEGATIVE_ZERO) + nil))) + (is (= {"positiveZero" 0M} + (mongo.conversion/from-document + (org.bson.Document. "positiveZero" org.bson.types.Decimal128/POSITIVE_ZERO) + nil)))))