@@ -711,6 +711,53 @@ def test_invalid_option_for_sql_dialect(self):
711
711
gbq .read_gbq (sql_statement , project_id = _get_project_id (),
712
712
dialect = 'standard' , private_key = _get_private_key_path ())
713
713
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
+
714
761
715
762
class TestToGBQIntegration (tm .TestCase ):
716
763
# Changes to BigQuery table schema may take up to 2 minutes as of May 2015
0 commit comments