#NEWLINE# def _bq_cast( string_field , bq_type ) : #NEWLINE# #INDENT# '\n    Helper method that casts a BigQuery row to the appropriate data types.\n    This is useful because BigQuery returns all fields as strings.\n    ' #NEWLINE# if ( string_field is None ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( bq_type == 'INTEGER' ) or ( bq_type == 'TIMESTAMP' ) ) : #NEWLINE# #INDENT# return int ( string_field ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( string_field == 'FLOAT' ) : #NEWLINE# #INDENT# return float ( string_field ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( bq_type == 'BOOLEAN' ) : #NEWLINE# #INDENT# assert ( string_field in set ( [ 'true' , 'false' ] ) ) #NEWLINE# return ( string_field == 'true' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return string_field