From aa59023317b1c63720fb717b3544f755652da58d Mon Sep 17 00:00:00 2001 From: Jim Fulton Date: Thu, 29 Apr 2021 10:35:37 -0600 Subject: [PATCH] fix: add DECIMAL and BIGDECIMAL as aliases for NUMERIC and BIGNUMERIC (#638) * Added decimal types to SqlTypeNames and SqlParameterScalarTypes * Go ahead and alias on the client To convey to the observant that these are aliases, even though they could be used (more or less) directly. * Make sure that DECIMAL data are converted when making API calls. This is mainly as a backstop -- DECIMAL requests should be converted to NUMERIC. * blacken --- google/cloud/bigquery/_helpers.py | 5 +++++ google/cloud/bigquery/enums.py | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/google/cloud/bigquery/_helpers.py b/google/cloud/bigquery/_helpers.py index ad8e3f003..4fe29291d 100644 --- a/google/cloud/bigquery/_helpers.py +++ b/google/cloud/bigquery/_helpers.py @@ -363,6 +363,11 @@ def _time_to_json(value): "DATETIME": _datetime_to_json, "DATE": _date_to_json, "TIME": _time_to_json, + # Make sure DECIMAL and BIGDECIMAL are handled, even though + # requests for them should be converted to NUMERIC. Better safe + # than sorry. + "DECIMAL": _decimal_to_json, + "BIGDECIMAL": _decimal_to_json, } diff --git a/google/cloud/bigquery/enums.py b/google/cloud/bigquery/enums.py index b378f091b..787c2449d 100644 --- a/google/cloud/bigquery/enums.py +++ b/google/cloud/bigquery/enums.py @@ -203,8 +203,8 @@ class SqlTypeNames(str, enum.Enum): INT64 = "INTEGER" FLOAT = "FLOAT" FLOAT64 = "FLOAT" - NUMERIC = "NUMERIC" - BIGNUMERIC = "BIGNUMERIC" + DECIMAL = NUMERIC = "NUMERIC" + BIGDECIMAL = BIGNUMERIC = "BIGNUMERIC" BOOLEAN = "BOOLEAN" BOOL = "BOOLEAN" GEOGRAPHY = "GEOGRAPHY" # NOTE: not available in legacy types @@ -227,6 +227,8 @@ class SqlParameterScalarTypes: FLOAT64 = ScalarQueryParameterType("FLOAT64") NUMERIC = ScalarQueryParameterType("NUMERIC") BIGNUMERIC = ScalarQueryParameterType("BIGNUMERIC") + DECIMAL = ScalarQueryParameterType("NUMERIC") + BIGDECIMAL = ScalarQueryParameterType("BIGNUMERIC") BOOLEAN = ScalarQueryParameterType("BOOL") BOOL = ScalarQueryParameterType("BOOL") GEOGRAPHY = ScalarQueryParameterType("GEOGRAPHY")