@@ -6290,38 +6290,43 @@ def test_insert_rows_w_numeric(self):
62906290creds = _make_credentials ()
62916291http = object ()
62926292client = self ._make_one (project = project ,credentials = creds ,_http = http )
6293- conn = client ._connection = make_connection ({})
62946293table_ref = DatasetReference (project ,ds_id ).table (table_id )
6295- schema = [SchemaField ("account" ,"STRING" ),SchemaField ("balance" ,"NUMERIC" )]
6296- insert_table = table .Table (table_ref ,schema = schema )
62976294rows = [
62986295 ("Savings" ,decimal .Decimal ("23.47" )),
62996296 ("Checking" ,decimal .Decimal ("1.98" )),
63006297 ("Mortgage" ,decimal .Decimal ("-12345678909.87654321" )),
63016298 ]
6299+ schemas = [
6300+ [SchemaField ("account" ,"STRING" ),SchemaField ("balance" ,"NUMERIC" )],
6301+ [SchemaField ("account" ,"STRING" ),SchemaField ("balance" ,"BIGNUMERIC" )],
6302+ ]
63026303
6303- with mock . patch ( "uuid.uuid4" , side_effect = map ( str , range ( len ( rows )))) :
6304- errors = client .insert_rows ( insert_table , rows )
6304+ for schema in schemas :
6305+ conn = client ._connection = make_connection ({} )
63056306
6306- self . assertEqual ( len ( errors ), 0 )
6307- rows_json = [
6308- { "account" : "Savings" , "balance" : "23.47" },
6309- { "account" : "Checking" , "balance" : "1.98" },
6310- { "account" : "Mortgage" , "balance" : "-12345678909.87654321" },
6311- ]
6312- sent = {
6313- "rows " :[
6314- {"json " :row ,"insertId " :str ( i )} for i , row in enumerate ( rows_json )
6307+ insert_table = table . Table ( table_ref , schema = schema )
6308+ with mock . patch ( "uuid.uuid4" , side_effect = map ( str , range ( len ( rows )))):
6309+ errors = client . insert_rows ( insert_table , rows )
6310+
6311+ self . assertEqual ( len ( errors ), 0 )
6312+ rows_json = [
6313+ { "account" : "Savings" , "balance" : "23.47" },
6314+ { "account " :"Checking" , "balance" : "1.98" },
6315+ {"account " :"Mortgage" ,"balance " :"-12345678909.87654321" },
63156316 ]
6316- }
6317- conn .api_request .assert_called_once_with (
6318- method = "POST" ,
6319- path = "/projects/{}/datasets/{}/tables/{}/insertAll" .format (
6320- project ,ds_id ,table_id
6321- ),
6322- data = sent ,
6323- timeout = None ,
6324- )
6317+ sent = {
6318+ "rows" : [
6319+ {"json" :row ,"insertId" :str (i )}for i ,row in enumerate (rows_json )
6320+ ]
6321+ }
6322+ conn .api_request .assert_called_once_with (
6323+ method = "POST" ,
6324+ path = "/projects/{}/datasets/{}/tables/{}/insertAll" .format (
6325+ project ,ds_id ,table_id
6326+ ),
6327+ data = sent ,
6328+ timeout = None ,
6329+ )
63256330
63266331@unittest .skipIf (pandas is None ,"Requires `pandas`" )
63276332def test_insert_rows_from_dataframe (self ):
@@ -6915,6 +6920,43 @@ def test_list_rows_query_params(self):
69156920test [1 ]["formatOptions.useInt64Timestamp" ]= True
69166921self .assertEqual (req [1 ]["query_params" ],test [1 ],"for kwargs %s" % test [0 ])
69176922
6923+ def test_list_rows_w_numeric (self ):
6924+ from google .cloud .bigquery .schema import SchemaField
6925+ from google .cloud .bigquery .table import Table
6926+
6927+ resource = {
6928+ "totalRows" :3 ,
6929+ "rows" : [
6930+ {"f" : [{"v" :"-1.23456789" }, {"v" :"-123456789.987654321" }]},
6931+ {"f" : [{"v" :None }, {"v" :"3.141592653589793238462643383279502884" }]},
6932+ {"f" : [{"v" :"2718281828459045235360287471.352662497" }, {"v" :None }]},
6933+ ],
6934+ }
6935+ creds = _make_credentials ()
6936+ http = object ()
6937+ client = self ._make_one (project = self .PROJECT ,credentials = creds ,_http = http )
6938+ client ._connection = make_connection (resource )
6939+ schema = [
6940+ SchemaField ("num" ,"NUMERIC" ),
6941+ SchemaField ("bignum" ,"BIGNUMERIC" ),
6942+ ]
6943+ table = Table (self .TABLE_REF ,schema = schema )
6944+
6945+ iterator = client .list_rows (table )
6946+ rows = list (iterator )
6947+
6948+ self .assertEqual (len (rows ),3 )
6949+ self .assertEqual (rows [0 ]["num" ],decimal .Decimal ("-1.23456789" ))
6950+ self .assertEqual (rows [0 ]["bignum" ],decimal .Decimal ("-123456789.987654321" ))
6951+ self .assertIsNone (rows [1 ]["num" ])
6952+ self .assertEqual (
6953+ rows [1 ]["bignum" ],decimal .Decimal ("3.141592653589793238462643383279502884" )
6954+ )
6955+ self .assertEqual (
6956+ rows [2 ]["num" ],decimal .Decimal ("2718281828459045235360287471.352662497" )
6957+ )
6958+ self .assertIsNone (rows [2 ]["bignum" ])
6959+
69186960def test_list_rows_repeated_fields (self ):
69196961from google .cloud .bigquery .schema import SchemaField
69206962