Skip to content

Commit a96811d

Browse files
committed
add unit tests read_gbq: query parameters, cache
1 parent f9fae0c commit a96811d

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

pandas/io/tests/test_gbq.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,53 @@ def test_invalid_option_for_sql_dialect(self):
711711
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
712712
dialect='standard', private_key=_get_private_key_path())
713713

714+
def test_query_with_parameters(self):
715+
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"
724+
},
725+
"parameterValue": {
726+
"value": 1
727+
}
728+
},
729+
{
730+
"name": "param2",
731+
"parameterType": {
732+
"type": "INTEGER"
733+
},
734+
"parameterValue": {
735+
"value": 2
736+
}
737+
}
738+
]
739+
}
740+
# Test that an invalid query without query_config
741+
with tm.assertRaises(ValueError):
742+
gbq.read_gbq(sql_statement, project_id=_get_project_id(),
743+
private_key=_get_private_key_path())
744+
745+
# Test that a correct query with query config
746+
df = gbq.read_gbq(sql_statement, project_id=_get_project_id(),
747+
private_key=_get_private_key_path(),
748+
query_config=query_config)
749+
tm.assert_frame_equal(df, DataFrame({'VALID_RESULT': [3]}))
750+
751+
def test_query_no_cache(self):
752+
query = 'SELECT "PI" as VALID_STRING'
753+
query_config = {
754+
"useQueryCache":False,
755+
}
756+
df = gbq.read_gbq(query, project_id=_get_project_id(),
757+
private_key=_get_private_key_path(),
758+
query_config=query_config)
759+
tm.assert_frame_equal(df, DataFrame({'VALID_STRING': ['PI']}))
760+
714761

715762
class TestToGBQIntegration(tm.TestCase):
716763
# Changes to BigQuery table schema may take up to 2 minutes as of May 2015

0 commit comments

Comments
 (0)