Skip to content
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

feat: Support parameterized NUMERIC, BIGNUMERIC, STRING, and BYTES types #673

Merged
merged 16 commits into from
May 21, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Oops, forgot BIGNUMERIC
jimfulton committed May 20, 2021
commit 9f5cbd5c3dfc72c449221897940c6776cbc6029a
6 changes: 3 additions & 3 deletions google/cloud/bigquery/schema.py
Original file line number Diff line number Diff line change
@@ -238,12 +238,12 @@ def _key(self):
if field_type == "STRING" or field_type == "BYTES":
if self.maxLength is not None:
field_type = f"{field_type}({self.maxLength})"
elif field_type == "NUMERIC":
elif field_type.endswith("NUMERIC"):
if self.precision is not None:
if self.scale is not None:
field_type = f"NUMERIC({self.precision}, {self.scale})"
field_type = f"{field_type}({self.precision}, {self.scale})"
else:
field_type = f"NUMERIC({self.precision})"
field_type = f"{field_type}({self.precision})"
return (
self.name,
field_type,
3 changes: 3 additions & 0 deletions tests/system/test_client.py
Original file line number Diff line number Diff line change
@@ -2180,6 +2180,9 @@ def test_parameterized_types_round_trip(self):
("n", "NUMERIC"),
("n9", "NUMERIC(9)"),
("n92", "NUMERIC(9, 2)"),
("bn", "BIGNUMERIC"),
("bn9", "BIGNUMERIC(38)"),
("bn92", "BIGNUMERIC(38, 22)"),
("s", "STRING"),
("s9", "STRING(9)"),
("b", "BYTES"),
27 changes: 27 additions & 0 deletions tests/unit/test_schema.py
Original file line number Diff line number Diff line change
@@ -736,6 +736,21 @@ def test___hash__not_equals(self):
("n", "NUMERIC", 9, 2, None),
("n", "NUMERIC(9, 2)"),
),
(
dict(name="n", type="BIGNUMERIC"),
("n", "BIGNUMERIC", None, None, None),
("n", "BIGNUMERIC"),
),
(
dict(name="n", type="BIGNUMERIC", precision=40),
("n", "BIGNUMERIC", 40, None, None),
("n", "BIGNUMERIC(40)"),
),
(
dict(name="n", type="BIGNUMERIC", precision=40, scale=2),
("n", "BIGNUMERIC", 40, 2, None),
("n", "BIGNUMERIC(40, 2)"),
),
(
dict(name="n", type="STRING"),
("n", "STRING", None, None, None),
@@ -789,6 +804,18 @@ def test_from_api_repr_parameterized(api, expect, key2):
dict(name="n", field_type="NUMERIC", precision=9, scale=2),
dict(name="n", type="NUMERIC", mode="NULLABLE", precision=9, scale=2),
),
(
dict(name="n", field_type="BIGNUMERIC"),
dict(name="n", type="BIGNUMERIC", mode="NULLABLE"),
),
(
dict(name="n", field_type="BIGNUMERIC", precision=40),
dict(name="n", type="BIGNUMERIC", mode="NULLABLE", precision=40),
),
(
dict(name="n", field_type="BIGNUMERIC", precision=40, scale=2),
dict(name="n", type="BIGNUMERIC", mode="NULLABLE", precision=40, scale=2),
),
(
dict(name="n", field_type="STRING"),
dict(name="n", type="STRING", mode="NULLABLE"),