Skip to content

Commit c199935

Browse files
committed
Make query configuration more general
1 parent 0b365da commit c199935

File tree

3 files changed

+42
-33
lines changed

3 files changed

+42
-33
lines changed

doc/source/whatsnew/v0.20.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ Performance Improvements
8383
.. _whatsnew_0200.bug_fixes:
8484

8585
Bug Fixes
86-
~~~~~~~~~
86+
~~~~~~~~~

pandas/io/gbq.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,12 @@ def run_query(self, query, **kwargs):
395395
}
396396
}
397397
}
398-
query_config = kwargs.get('query_config')
399-
if query_config is not None:
400-
job_data['configuration']['query'].update(query_config)
398+
configuration = kwargs.get('configuration')
399+
if configuration is not None:
400+
if 'query' in configuration:
401+
job_data['configuration']['query'].update(configuration['query'])
402+
else:
403+
job_data['configuration'] = configuration
401404

402405
self._start_timer()
403406
try:
@@ -687,7 +690,7 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
687690
.. versionadded:: 0.19.0
688691
689692
**kwargs: Arbitrary keyword arguments
690-
query_config (dict): query configuration parameters for job processing.
693+
configuration (dict): query configuration parameters for job processing.
691694
For more information see `BigQuery SQL Reference
692695
<https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query>`
693696

pandas/io/tests/test_gbq.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -713,49 +713,55 @@ def test_invalid_option_for_sql_dialect(self):
713713

714714
def test_query_with_parameters(self):
715715
sql_statement = "SELECT @param1 + @param2 as VALID_RESULT"
716-
query_config = {
717-
"useLegacySql": False,
718-
"parameterMode": "named",
719-
"queryParameters": [
720-
{
721-
"name": "param1",
722-
"parameterType": {
723-
"type": "INTEGER"
716+
config = {
717+
'query': {
718+
"useLegacySql": False,
719+
"parameterMode": "named",
720+
"queryParameters": [
721+
{
722+
"name": "param1",
723+
"parameterType": {
724+
"type": "INTEGER"
725+
},
726+
"parameterValue": {
727+
"value": 1
728+
}
724729
},
725-
"parameterValue": {
726-
"value": 1
730+
{
731+
"name": "param2",
732+
"parameterType": {
733+
"type": "INTEGER"
734+
},
735+
"parameterValue": {
736+
"value": 2
737+
}
727738
}
728-
},
729-
{
730-
"name": "param2",
731-
"parameterType": {
732-
"type": "INTEGER"
733-
},
734-
"parameterValue": {
735-
"value": 2
736-
}
737-
}
738-
]
739+
]
740+
}
739741
}
740-
# Test that an invalid query without query_config
742+
# Test that an invalid query without query config
741743
with tm.assertRaises(ValueError):
742744
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
743745
private_key=_get_private_key_path())
744746

745747
# Test that a correct query with query config
746748
df = gbq.read_gbq(sql_statement, project_id=_get_project_id(),
747749
private_key=_get_private_key_path(),
748-
query_config=query_config)
750+
configuration=config)
749751
tm.assert_frame_equal(df, DataFrame({'VALID_RESULT': [3]}))
750752

751-
def test_query_no_cache(self):
753+
def test_query_inside_configuration(self):
754+
query_no_use = 'SELECT "PI_WRONG" as VALID_STRING'
752755
query = 'SELECT "PI" as VALID_STRING'
753-
query_config = {
754-
"useQueryCache": False,
756+
config = {
757+
'query': {
758+
"query": query,
759+
"useQueryCache": False,
760+
}
755761
}
756-
df = gbq.read_gbq(query, project_id=_get_project_id(),
762+
df = gbq.read_gbq(query_no_use, project_id=_get_project_id(),
757763
private_key=_get_private_key_path(),
758-
query_config=query_config)
764+
configuration=config)
759765
tm.assert_frame_equal(df, DataFrame({'VALID_STRING': ['PI']}))
760766

761767

0 commit comments

Comments
 (0)