Skip to content
Permalink
Browse files
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
  • Loading branch information
jimfulton committed Apr 29, 2021
1 parent 5df63fd commit aa59023317b1c63720fb717b3544f755652da58d
Showing with 9 additions and 2 deletions.
  1. +5 −0 google/cloud/bigquery/_helpers.py
  2. +4 −2 google/cloud/bigquery/enums.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,
}


@@ -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")

0 comments on commit aa59023

Please sign in to comment.