-
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.
Detect google-cloud-bigquery version for backwards compatibility
- Loading branch information
Showing
4 changed files
with
82 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
google-auth==1.4.1 | ||
google-auth-oauthlib==0.0.1 | ||
mock | ||
google-cloud-bigquery==0.32.0 | ||
google-cloud-bigquery==0.29.0 |
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,13 @@ | ||
|
||
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(resource, installed_version): | ||
if installed_version < BIGQUERY_CONFIG_VERSION: | ||
return bigquery.QueryJobConfig.from_api_repr(resource.get('query', {})) | ||
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'}, | ||
}) |