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

fix: allow underscores in struct field names when passing parameters to DB-API #930

Merged
merged 1 commit into from Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/cloud/bigquery/dbapi/_helpers.py
Expand Up @@ -173,7 +173,7 @@ def _parse_type(
\s*
(ARRAY|STRUCT|RECORD) # Type
\s*
<([A-Z0-9<> ,()]+)> # Subtype(s)
<([A-Z0-9_<> ,()]+)> # Subtype(s)
\s*$
""",
re.IGNORECASE | re.VERBOSE,
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigquery/dbapi/cursor.py
Expand Up @@ -494,7 +494,7 @@ def _extract_types(
([^:)]*) # name
(?:: # ':' introduces type
( # start of type group
[a-zA-Z0-9<>, ]+ # First part, no parens
[a-zA-Z0-9_<>, ]+ # First part, no parens

(?: # start sets of parens + non-paren text
\([0-9 ,]+\) # comma-separated groups of digits in parens
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_dbapi__helpers.py
Expand Up @@ -612,8 +612,8 @@ def test_complex_query_parameter_type_errors(type_, value, expect):
"parameters,parameter_types,expect",
[
(
[[], dict(name="ch1", bdate=datetime.date(2021, 1, 1))],
["ARRAY<INT64>", "struct<name string, bdate date>"],
[[], dict(name="ch1", b_date=datetime.date(2021, 1, 1))],
["ARRAY<INT64>", "struct<name string, b_date date>"],
[
{
"parameterType": {"arrayType": {"type": "INT64"}, "type": "ARRAY"},
Expand All @@ -623,13 +623,13 @@ def test_complex_query_parameter_type_errors(type_, value, expect):
"parameterType": {
"structTypes": [
{"name": "name", "type": {"type": "STRING"}},
{"name": "bdate", "type": {"type": "DATE"}},
{"name": "b_date", "type": {"type": "DATE"}},
],
"type": "STRUCT",
},
"parameterValue": {
"structValues": {
"bdate": {"value": "2021-01-01"},
"b_date": {"value": "2021-01-01"},
"name": {"value": "ch1"},
}
},
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_dbapi_cursor.py
Expand Up @@ -809,6 +809,10 @@ def test__format_operation_no_placeholders(self):
"values(%%%%%(foo:INT64)s, %(bar)s)",
("values(%%%%%(foo)s, %(bar)s)", dict(foo="INT64")),
),
(
"values(%%%%%(foo:struct<x_1 string, y_ int64>)s, %(bar)s)",
("values(%%%%%(foo)s, %(bar)s)", dict(foo="struct<x_1 string, y_ int64>")),
),
(
"values(%%%%%(foo:struct<x string, y int64>)s, %(bar)s)",
("values(%%%%%(foo)s, %(bar)s)", dict(foo="struct<x string, y int64>")),
Expand Down