@@ -369,8 +369,14 @@ class BigQueryWrapper(object):
369369
370370 HISTOGRAM_METRIC_LOGGER = MetricLogger ()
371371
372- def __init__ (self , client = None , temp_dataset_id = None , temp_table_ref = None ):
373- self .client = client or BigQueryWrapper ._bigquery_client (PipelineOptions ())
372+ def __init__ (
373+ self ,
374+ client = None ,
375+ temp_dataset_id = None ,
376+ temp_table_ref = None ,
377+ pipeline_options = None ):
378+ self .client = client or BigQueryWrapper ._bigquery_client (
379+ pipeline_options or PipelineOptions ())
374380 self .gcp_bq_client = self .client
375381
376382 self ._unique_row_id = 0
@@ -1362,7 +1368,8 @@ def convert_row_to_dict(self, row, schema):
13621368 @staticmethod
13631369 def from_pipeline_options (pipeline_options : PipelineOptions ):
13641370 return BigQueryWrapper (
1365- client = BigQueryWrapper ._bigquery_client (pipeline_options ))
1371+ client = BigQueryWrapper ._bigquery_client (pipeline_options ),
1372+ pipeline_options = pipeline_options )
13661373
13671374 @staticmethod
13681375 def _bigquery_client (pipeline_options : PipelineOptions ):
@@ -1650,6 +1657,8 @@ def table_schema_to_dict(table_schema):
16501657 def get_table_field (field ):
16511658 """Create a dictionary representation of a table field
16521659 """
1660+ if isinstance (field , dict ):
1661+ return field
16531662 result = {}
16541663 result ['name' ] = field .name
16551664 result ['type' ] = getattr (field , 'field_type' , getattr (field , 'type' , None ))
@@ -1705,14 +1714,16 @@ def get_bq_tableschema(schema):
17051714 Returns:
17061715 Sequence[``google.cloud.bigquery.schema.SchemaField``]: The schema as a TableSchema object.
17071716 """
1708- if (isinstance (schema , (tuple , value_provider .ValueProvider )) or
1717+ if (isinstance (schema , (tuple , list , value_provider .ValueProvider )) or
17091718 callable (schema ) or schema is None ):
1710- return schema
1719+ return tuple ( schema ) if isinstance ( schema , list ) else schema
17111720 elif isinstance (schema , str ):
17121721 return get_table_schema_from_string (schema )
17131722 elif isinstance (schema , dict ):
17141723 schema_string = json .dumps (schema )
17151724 return parse_table_schema_from_json (schema_string )
1725+ elif hasattr (schema , 'fields' ):
1726+ return get_bq_tableschema (schema .fields )
17161727 else :
17171728 raise TypeError ('Unexpected schema argument: %s.' % schema )
17181729
0 commit comments