-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: DB API depends on pyarrow when decimal query parameters are used #551
Conversation
DB API should gracefully handle the case when the optional pyarrow dependency is not installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on my latest comment, I think we can remove pyarrow
entirely from this logic.
# NUMERIC values have precision of 38 (number of digits) and scale of 9 (number | ||
# of fractional digits), and their max absolute value must be strictly smaller | ||
# than 1.0E+29. | ||
# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#decimal_types | ||
if ( | ||
len(vtuple.digits) <= 38 # max precision: 38 | ||
and vtuple.exponent >= -9 # max scale: 9 | ||
and _NUMERIC_SERVER_MIN <= value <= _NUMERIC_SERVER_MAX | ||
): | ||
return "NUMERIC" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic differs from the docs, because testing the actual backend response showed that 9.9999999999999999999999999999999999999E+29
is not accepted as a valid NUMERIC value:
SELECT CAST((SELECT "9.9999999999999999999999999999999999999E+29" AS literal) AS NUMERIC); # error
Even 1.0E+29
is too large, but 9.999...9E+28
works, meaning that there's probably an off-by-one error in the docs for the exponent.
Update: Confirmed, the docs are indeed not correct, an internal issue 182900100 has been created to track this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gorgeous!
🤖 I have created a release \*beep\* \*boop\* --- ## [2.12.0](https://www.github.com/googleapis/python-bigquery/compare/v2.11.0...v2.12.0) (2021-03-16) ### Features * make QueryJob.done() method more performant ([#544](https://www.github.com/googleapis/python-bigquery/issues/544)) ([a3ab9ef](https://www.github.com/googleapis/python-bigquery/commit/a3ab9efdd0758829845cfcb6ca0ac1f03ab44f64)) ### Bug Fixes * remove DB-API dependency on pyarrow with decimal query parameters ([#551](https://www.github.com/googleapis/python-bigquery/issues/551)) ([1b946ba](https://www.github.com/googleapis/python-bigquery/commit/1b946ba23ee7df86114c6acb338ec34e6c92af6d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
@@ -71,6 +72,33 @@ def test_scalar_to_query_parameter(self): | |||
self.assertEqual(named_parameter.type_, expected_type, msg=msg) | |||
self.assertEqual(named_parameter.value, value, msg=msg) | |||
|
|||
def test_decimal_to_query_parameter(self): # TODO: merge with previous test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have removed that, it's just a subset of the test_scalar_to_query_parameter
test above it.
Fixes #549.
This PR removes the hard dependency of DB API on the optional
pyarrow
dependency.PR checklist: