Skip to content

Commit

Permalink
fix: add DECIMAL and BIGDECIMAL as aliases for NUMERIC and BIGNUMERIC (
Browse files Browse the repository at this point in the history
…#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 authored Apr 29, 2021
1 parent 5df63fd commit aa59023
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions google/cloud/bigquery/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}


Expand Down
6 changes: 4 additions & 2 deletions google/cloud/bigquery/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit aa59023

Please sign in to comment.