-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG: Adapt to breaking change in google-cloud-bigquery 0.32.0.dev1 (#152
) * BUG: Update pandas-gbq to latest version of google-cloud-bigquery There was a breaking change in 0.32.0.dev1 which changed the way configuration for the query job gets loaded. Also, it added the 'description' field to the schema resource, so this change updates the schema comparison logic to account for that. Detect google-cloud-bigquery version for backwards compatibility * DOC: Add verbose deprecation to changelog. * TST: MASTER in CI also builds with g-c-bigquery at MASTER.
- Loading branch information
Showing
8 changed files
with
163 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
google-auth | ||
google-auth-oauthlib | ||
mock | ||
google-cloud-bigquery |
This file contains 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 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,25 @@ | ||
|
||
import pkg_resources | ||
from google.cloud import bigquery | ||
|
||
|
||
# Version with query config breaking change. | ||
BIGQUERY_CONFIG_VERSION = pkg_resources.parse_version('0.32.0.dev1') | ||
|
||
|
||
def query_config_old_version(resource): | ||
# Verify that we got a query resource. In newer versions of | ||
# google-cloud-bigquery enough of the configuration is passed on to the | ||
# backend that we can expect a backend validation error instead. | ||
if len(resource) != 1: | ||
raise ValueError("Only one job type must be specified, but " | ||
"given {}".format(','.join(resource.keys()))) | ||
if 'query' not in resource: | ||
raise ValueError("Only 'query' job type is supported") | ||
return bigquery.QueryJobConfig.from_api_repr(resource['query']) | ||
|
||
|
||
def query_config(resource, installed_version): | ||
if installed_version < BIGQUERY_CONFIG_VERSION: | ||
return query_config_old_version(resource) | ||
return bigquery.QueryJobConfig.from_api_repr(resource) |
This file contains 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 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,57 @@ | ||
|
||
import pkg_resources | ||
|
||
import mock | ||
|
||
|
||
@mock.patch('google.cloud.bigquery.QueryJobConfig') | ||
def test_query_config_w_old_bq_version(mock_config): | ||
from pandas_gbq._query import query_config | ||
|
||
old_version = pkg_resources.parse_version('0.29.0') | ||
query_config({'query': {'useLegacySql': False}}, old_version) | ||
mock_config.from_api_repr.assert_called_once_with({'useLegacySql': False}) | ||
|
||
|
||
@mock.patch('google.cloud.bigquery.QueryJobConfig') | ||
def test_query_config_w_dev_bq_version(mock_config): | ||
from pandas_gbq._query import query_config | ||
|
||
dev_version = pkg_resources.parse_version('0.32.0.dev1') | ||
query_config( | ||
{ | ||
'query': { | ||
'useLegacySql': False, | ||
}, | ||
'labels': {'key': 'value'}, | ||
}, | ||
dev_version) | ||
mock_config.from_api_repr.assert_called_once_with( | ||
{ | ||
'query': { | ||
'useLegacySql': False, | ||
}, | ||
'labels': {'key': 'value'}, | ||
}) | ||
|
||
|
||
@mock.patch('google.cloud.bigquery.QueryJobConfig') | ||
def test_query_config_w_new_bq_version(mock_config): | ||
from pandas_gbq._query import query_config | ||
|
||
dev_version = pkg_resources.parse_version('1.0.0') | ||
query_config( | ||
{ | ||
'query': { | ||
'useLegacySql': False, | ||
}, | ||
'labels': {'key': 'value'}, | ||
}, | ||
dev_version) | ||
mock_config.from_api_repr.assert_called_once_with( | ||
{ | ||
'query': { | ||
'useLegacySql': False, | ||
}, | ||
'labels': {'key': 'value'}, | ||
}) |
This file contains 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 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ def readme(): | |
|
||
|
||
INSTALL_REQUIRES = [ | ||
'setuptools', | ||
'pandas', | ||
'google-auth', | ||
'google-auth-oauthlib', | ||
|