-
Notifications
You must be signed in to change notification settings - Fork 316
feat: Support passing struct data to the DB API #718
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
586a022
Added support for dbi struct parameters with explicit types
13f9107
Make the dataset_id fixture a session fixture
aea7bae
Make the dataset_id fixture a session fixture
6f26130
system test of the struct machinery
c386448
Verify that we can bind non-parameterized types
71c8614
Parse and remove type parameters from explcit types.
6f5b345
Document passing struct data.
e08f6f6
Merge remote-tracking branch 'origin/master' into riversnake-dbi-stru…
411c336
blacken
ef2b323
using match.groups() throws off pytypes, also fix some type hints.
654b108
🦉 Updates from OwlBot
gcf-owl-bot[bot] 525b8fd
blacken
462f2eb
remove type hints -- maybe they broke docs?
904d2ce
merge upstream
a6393e6
Revert "remove type hints -- maybe they broke docs?"
e63e8b7
pin gcp-sphinx-docfx-yaml==0.2.0 so docfx doesn't fail.
2f2bdcd
Merge remote-tracking branch 'origin/master' into riversnake-dbi-stru…
91b0028
Review comments: examples, and guard against large number of fields
35555aa
🦉 Updates from OwlBot
gcf-owl-bot[bot] 0d81b80
Merge remote-tracking branch 'origin/master' into riversnake-dbi-stru…
d3f959c
Merge branch 'riversnake-dbi-struct-types' of github.com:googleapis/p…
5554301
Factored some repeated code in handling complex parameters
8830113
Improved the error for dict (structish) parameter values without expl…
a72cafb
blacken
cba9697
removed repeated word
12bd941
Update google/cloud/bigquery/dbapi/_helpers.py
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import datetime | ||
|
||
import pytest | ||
|
||
from google.cloud.bigquery.dbapi import connect | ||
|
||
person_type = "struct<name string," " children array<struct<name string, bdate date>>>" | ||
person_type_sized = ( | ||
"struct<name string(22)," " children array<struct<name string(22), bdate date>>>" | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("person_type_decl", [person_type, person_type_sized]) | ||
def test_structs(bigquery_client, dataset_id, person_type_decl, table_id): | ||
conn = connect(bigquery_client) | ||
cursor = conn.cursor() | ||
cursor.execute(f"create table {table_id} (person {person_type_decl})") | ||
data = dict( | ||
name="par", | ||
children=[ | ||
dict(name="ch1", bdate=datetime.date(2021, 1, 1)), | ||
dict(name="ch2", bdate=datetime.date(2021, 1, 2)), | ||
], | ||
) | ||
cursor.execute( | ||
f"insert into {table_id} (person) values (%(v:{person_type})s)", dict(v=data), | ||
) | ||
|
||
cursor.execute(f"select * from {table_id}") | ||
[[result]] = list(cursor) | ||
assert result == data |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.