-
-
Notifications
You must be signed in to change notification settings - Fork 20k
Added query_config parameter to read_gbq #14742
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
55bf05c
Added udf_resource_uri parameter to read_gbq
necnec dad9288
Change parameter to kwargs
necnec 9a16a8c
Merge branch 'bigquery-udf-resources'
necnec f9fae0c
Fix formatting
necnec 42dc9e6
Merge remote-tracking branch 'origin/bigquery-udf-resources'
necnec c66169d
add read_gbq tests: query parameters and cache
necnec a96811d
add unit tests read_gbq: query parameters, cache
necnec ad35a43
fix whatsnew text
necnec ddb4fd1
Merge branch 'bigquery-udf-resources'
necnec 94fa514
test formatting
necnec d69ed7f
check tests
necnec 834a2ff
Merge branch 'bigquery-udf-resources'
necnec 640be7a
Change whatnew 0.19.0->0.19.2
necnec b849300
Change whatsnew 0.19.2 -> 0.20.0
necnec a952710
Move whatsnew BQ Enhancements -> Enhancements
necnec 0b365da
delete newlines
necnec c199935
Make query configuration more general
necnec 028c8be
Solve formating problems
necnec ce8ebe4
Merge branch 'bigquery-udf-resources'
necnec 146f0f3
Merge branch 'master' into bigquery-udf-resources
necnec 8fe77b2
Merge branch 'bigquery-udf-resources'
necnec c21588a
Merge remote-tracking branch 'pandas-dev/master' into bigquery-udf-re…
necnec 395c0e9
fix formatting
necnec 8a38650
Added example configuration & job_configuration refactoring
necnec 929ad1a
formatting: delete whitespace
necnec 86ed96d
Merge branch 'master' into bigquery-udf-resources
necnec 0ac26a2
added pull request number in whitens
necnec 99521aa
Formatting, documentation, new unit test
necnec df5dec6
configuration->config & formatting
necnec 8720b03
Delete trailing whitespaces
necnec ec590af
Throw exception if more than 1 job type in config
necnec 2e02d76
Merge remote-tracking branch 'pandas-dev/master' into bigquery-udf-re…
necnec e2f801f
hotfix
b97a1be
formatting
necnec 82f4409
Add some documentation & formatting
necnec 3a238a5
config->configuration
necnec 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
add unit tests read_gbq: query parameters, cache
- Loading branch information
commit a96811d778b2bb965e352d0798a5c3c2fe014552
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -711,6 +711,53 @@ def test_invalid_option_for_sql_dialect(self): | |
| gbq.read_gbq(sql_statement, project_id=_get_project_id(), | ||
| dialect='standard', private_key=_get_private_key_path()) | ||
|
|
||
| def test_query_with_parameters(self): | ||
| sql_statement = "SELECT @param1 + @param2 as VALID_RESULT" | ||
| query_config = { | ||
| "useLegacySql":False, | ||
| "parameterMode":"named", | ||
| "queryParameters": [ | ||
| { | ||
| "name": "param1", | ||
| "parameterType": { | ||
| "type": "INTEGER" | ||
| }, | ||
| "parameterValue": { | ||
| "value": 1 | ||
| } | ||
| }, | ||
| { | ||
| "name": "param2", | ||
| "parameterType": { | ||
| "type": "INTEGER" | ||
| }, | ||
| "parameterValue": { | ||
| "value": 2 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| # Test that an invalid query without query_config | ||
| with tm.assertRaises(ValueError): | ||
| gbq.read_gbq(sql_statement, project_id=_get_project_id(), | ||
| private_key=_get_private_key_path()) | ||
|
|
||
| # Test that a correct query with query config | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| df = gbq.read_gbq(sql_statement, project_id=_get_project_id(), | ||
| private_key=_get_private_key_path(), | ||
| query_config=query_config) | ||
| tm.assert_frame_equal(df, DataFrame({'VALID_RESULT': [3]})) | ||
|
|
||
| def test_query_no_cache(self): | ||
| query = 'SELECT "PI" as VALID_STRING' | ||
| query_config = { | ||
| "useQueryCache":False, | ||
| } | ||
| df = gbq.read_gbq(query, project_id=_get_project_id(), | ||
| private_key=_get_private_key_path(), | ||
| query_config=query_config) | ||
| tm.assert_frame_equal(df, DataFrame({'VALID_STRING': ['PI']})) | ||
|
|
||
|
|
||
| class TestToGBQIntegration(tm.TestCase): | ||
| # Changes to BigQuery table schema may take up to 2 minutes as of May 2015 | ||
|
|
||
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.
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.
why is this necessary? I thought
configurationis an optional paramter? when is it neededThere 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.
@jreback Yes, configuration is optional. But this unit test is very special. It processes query with parameters. And in this case you must pass parameters values in configuration.
I've made 2 unit tests. So if you think this test if very special I can remove that.
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.
its fine to test. is it seems that this tests means its required somehow though.
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.
@jreback so I don't need to change anything here?
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.
Could we update the comment to better explain why we expect a failure here?
For example,
# Test that a query that relies on parameters fails when parameters not supplied via configuration.