<s> """<STR_LIT>""" <EOL> import six <EOL> from gcloud . exceptions import NotFound <EOL> from gcloud . _helpers import _datetime_from_microseconds <EOL> from gcloud . bigquery . dataset import Dataset <EOL> from gcloud . bigquery . table import SchemaField <EOL> from gcloud . bigquery . table import Table <EOL> from gcloud . bigquery . table import _build_schema_resource <EOL> from gcloud . bigquery . table import _parse_schema_resource <EOL> from gcloud . bigquery . _helpers import _EnumProperty <EOL> from gcloud . bigquery . _helpers import _TypedProperty <EOL> class Compression ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> GZIP = '<STR_LIT>' <EOL> NONE = '<STR_LIT>' <EOL> ALLOWED = ( GZIP , NONE ) <EOL> class CreateDisposition ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> CREATE_IF_NEEDED = '<STR_LIT>' <EOL> CREATE_NEVER = '<STR_LIT>' <EOL> ALLOWED = ( CREATE_IF_NEEDED , CREATE_NEVER ) <EOL> class DestinationFormat ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> CSV = '<STR_LIT>' <EOL> NEWLINE_DELIMITED_JSON = '<STR_LIT>' <EOL> AVRO = '<STR_LIT>' <EOL> ALLOWED = ( CSV , NEWLINE_DELIMITED_JSON , AVRO ) <EOL> class Encoding ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> UTF_8 = '<STR_LIT>' <EOL> ISO_8559_1 = '<STR_LIT>' <EOL> ALLOWED = ( UTF_8 , ISO_8559_1 ) <EOL> class QueryPriority ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> INTERACTIVE = '<STR_LIT>' <EOL> BATCH = '<STR_LIT>' <EOL> ALLOWED = ( INTERACTIVE , BATCH ) <EOL> class SourceFormat ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> CSV = '<STR_LIT>' <EOL> DATASTORE_BACKUP = '<STR_LIT>' <EOL> NEWLINE_DELIMITED_JSON = '<STR_LIT>' <EOL> ALLOWED = ( CSV , DATASTORE_BACKUP , NEWLINE_DELIMITED_JSON ) <EOL> class WriteDisposition ( _EnumProperty ) : <EOL> """<STR_LIT>""" <EOL> WRITE_APPEND = '<STR_LIT>' <EOL> WRITE_TRUNCATE = '<STR_LIT>' <EOL> WRITE_EMPTY = '<STR_LIT>' <EOL> ALLOWED = ( WRITE_APPEND , WRITE_TRUNCATE , WRITE_EMPTY ) <EOL> class _BaseJob ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , client ) : <EOL> self . _client = client <EOL> self . _properties = { } <EOL> @ property <EOL> def project ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _client . project <EOL> def _require_client ( self , client ) : <EOL> """<STR_LIT>""" <EOL> if client is None : <EOL> client = self . _client <EOL> return client <EOL> class _AsyncJob ( _BaseJob ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , client ) : <EOL> super ( _AsyncJob , self ) . __init__ ( client ) <EOL> self . name = name <EOL> @ property <EOL> def job_type ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _JOB_TYPE <EOL> @ property <EOL> def path ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % ( self . project , self . name ) <EOL> @ property <EOL> def etag ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _properties . get ( '<STR_LIT>' ) <EOL> @ property <EOL> def self_link ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _properties . get ( '<STR_LIT>' ) <EOL> @ property <EOL> def user_email ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _properties . get ( '<STR_LIT>' ) <EOL> @ property <EOL> def created ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> millis = statistics . get ( '<STR_LIT>' ) <EOL> if millis is not None : <EOL> return _datetime_from_microseconds ( millis * <NUM_LIT> ) <EOL> @ property <EOL> def started ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> millis = statistics . get ( '<STR_LIT>' ) <EOL> if millis is not None : <EOL> return _datetime_from_microseconds ( millis * <NUM_LIT> ) <EOL> @ property <EOL> def ended ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> millis = statistics . get ( '<STR_LIT>' ) <EOL> if millis is not None : <EOL> return _datetime_from_microseconds ( millis * <NUM_LIT> ) <EOL> @ property <EOL> def error_result ( self ) : <EOL> """<STR_LIT>""" <EOL> status = self . _properties . get ( '<STR_LIT:status>' ) <EOL> if status is not None : <EOL> return status . get ( '<STR_LIT>' ) <EOL> @ property <EOL> def errors ( self ) : <EOL> """<STR_LIT>""" <EOL> status = self . _properties . get ( '<STR_LIT:status>' ) <EOL> if status is not None : <EOL> return status . get ( '<STR_LIT>' ) <EOL> @ property <EOL> def state ( self ) : <EOL> """<STR_LIT>""" <EOL> status = self . _properties . get ( '<STR_LIT:status>' ) <EOL> if status is not None : <EOL> return status . get ( '<STR_LIT:state>' ) <EOL> def _scrub_local_properties ( self , cleaned ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _set_properties ( self , api_response ) : <EOL> """<STR_LIT>""" <EOL> cleaned = api_response . copy ( ) <EOL> self . _scrub_local_properties ( cleaned ) <EOL> statistics = cleaned . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' in statistics : <EOL> statistics [ '<STR_LIT>' ] = float ( statistics [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in statistics : <EOL> statistics [ '<STR_LIT>' ] = float ( statistics [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in statistics : <EOL> statistics [ '<STR_LIT>' ] = float ( statistics [ '<STR_LIT>' ] ) <EOL> self . _properties . clear ( ) <EOL> self . _properties . update ( cleaned ) <EOL> @ classmethod <EOL> def _get_resource_config ( cls , resource ) : <EOL> """<STR_LIT>""" <EOL> if ( '<STR_LIT>' not in resource or <EOL> '<STR_LIT>' not in resource [ '<STR_LIT>' ] ) : <EOL> raise KeyError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> name = resource [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if ( '<STR_LIT>' not in resource or <EOL> cls . _JOB_TYPE not in resource [ '<STR_LIT>' ] ) : <EOL> raise KeyError ( '<STR_LIT>' <EOL> '<STR_LIT>' % cls . _JOB_TYPE ) <EOL> config = resource [ '<STR_LIT>' ] [ cls . _JOB_TYPE ] <EOL> return name , config <EOL> def begin ( self , client = None ) : <EOL> """<STR_LIT>""" <EOL> client = self . _require_client ( client ) <EOL> path = '<STR_LIT>' % ( self . project , ) <EOL> api_response = client . connection . api_request ( <EOL> method = '<STR_LIT:POST>' , path = path , data = self . _build_resource ( ) ) <EOL> self . _set_properties ( api_response ) <EOL> def exists ( self , client = None ) : <EOL> """<STR_LIT>""" <EOL> client = self . _require_client ( client ) <EOL> try : <EOL> client . connection . api_request ( method = '<STR_LIT:GET>' , path = self . path , <EOL> query_params = { '<STR_LIT>' : '<STR_LIT:id>' } ) <EOL> except NotFound : <EOL> return False <EOL> else : <EOL> return True <EOL> def reload ( self , client = None ) : <EOL> """<STR_LIT>""" <EOL> client = self . _require_client ( client ) <EOL> api_response = client . connection . api_request ( <EOL> method = '<STR_LIT:GET>' , path = self . path ) <EOL> self . _set_properties ( api_response ) <EOL> def cancel ( self , client = None ) : <EOL> """<STR_LIT>""" <EOL> client = self . _require_client ( client ) <EOL> api_response = client . connection . api_request ( <EOL> method = '<STR_LIT:POST>' , path = '<STR_LIT>' % ( self . path , ) ) <EOL> self . _set_properties ( api_response ) <EOL> class _LoadConfiguration ( object ) : <EOL> """<STR_LIT>""" <EOL> _allow_jagged_rows = None <EOL> _allow_quoted_newlines = None <EOL> _create_disposition = None <EOL> _encoding = None <EOL> _field_delimiter = None <EOL> _ignore_unknown_values = None <EOL> _max_bad_records = None <EOL> _quote_character = None <EOL> _skip_leading_rows = None <EOL> _source_format = None <EOL> _write_disposition = None <EOL> class LoadTableFromStorageJob ( _AsyncJob ) : <EOL> """<STR_LIT>""" <EOL> _schema = None <EOL> _JOB_TYPE = '<STR_LIT>' <EOL> def __init__ ( self , name , destination , source_uris , client , schema = ( ) ) : <EOL> super ( LoadTableFromStorageJob , self ) . __init__ ( name , client ) <EOL> self . destination = destination <EOL> self . source_uris = source_uris <EOL> self . schema = schema <EOL> self . _configuration = _LoadConfiguration ( ) <EOL> @ property <EOL> def schema ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . _schema ) <EOL> @ schema . setter <EOL> def schema ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if not all ( isinstance ( field , SchemaField ) for field in value ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . _schema = tuple ( value ) <EOL> @ property <EOL> def input_file_bytes ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> return int ( statistics [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> @ property <EOL> def input_files ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> return int ( statistics [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> @ property <EOL> def output_bytes ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> return int ( statistics [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> @ property <EOL> def output_rows ( self ) : <EOL> """<STR_LIT>""" <EOL> statistics = self . _properties . get ( '<STR_LIT>' ) <EOL> if statistics is not None : <EOL> return int ( statistics [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> allow_jagged_rows = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> allow_quoted_newlines = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> create_disposition = CreateDisposition ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> encoding = Encoding ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> field_delimiter = _TypedProperty ( '<STR_LIT>' , six . string_types ) <EOL> """<STR_LIT>""" <EOL> ignore_unknown_values = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> max_bad_records = _TypedProperty ( '<STR_LIT>' , six . integer_types ) <EOL> """<STR_LIT>""" <EOL> quote_character = _TypedProperty ( '<STR_LIT>' , six . string_types ) <EOL> """<STR_LIT>""" <EOL> skip_leading_rows = _TypedProperty ( '<STR_LIT>' , six . integer_types ) <EOL> """<STR_LIT>""" <EOL> source_format = SourceFormat ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> write_disposition = WriteDisposition ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> def _populate_config_resource ( self , configuration ) : <EOL> """<STR_LIT>""" <EOL> if self . allow_jagged_rows is not None : <EOL> configuration [ '<STR_LIT>' ] = self . allow_jagged_rows <EOL> if self . allow_quoted_newlines is not None : <EOL> configuration [ '<STR_LIT>' ] = self . allow_quoted_newlines <EOL> if self . create_disposition is not None : <EOL> configuration [ '<STR_LIT>' ] = self . create_disposition <EOL> if self . encoding is not None : <EOL> configuration [ '<STR_LIT>' ] = self . encoding <EOL> if self . field_delimiter is not None : <EOL> configuration [ '<STR_LIT>' ] = self . field_delimiter <EOL> if self . ignore_unknown_values is not None : <EOL> configuration [ '<STR_LIT>' ] = self . ignore_unknown_values <EOL> if self . max_bad_records is not None : <EOL> configuration [ '<STR_LIT>' ] = self . max_bad_records <EOL> if self . quote_character is not None : <EOL> configuration [ '<STR_LIT>' ] = self . quote_character <EOL> if self . skip_leading_rows is not None : <EOL> configuration [ '<STR_LIT>' ] = self . skip_leading_rows <EOL> if self . source_format is not None : <EOL> configuration [ '<STR_LIT>' ] = self . source_format <EOL> if self . write_disposition is not None : <EOL> configuration [ '<STR_LIT>' ] = self . write_disposition <EOL> def _build_resource ( self ) : <EOL> """<STR_LIT>""" <EOL> resource = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . project , <EOL> '<STR_LIT>' : self . name , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> self . _JOB_TYPE : { <EOL> '<STR_LIT>' : self . source_uris , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . destination . project , <EOL> '<STR_LIT>' : self . destination . dataset_name , <EOL> '<STR_LIT>' : self . destination . name , <EOL> } , <EOL> } , <EOL> } , <EOL> } <EOL> configuration = resource [ '<STR_LIT>' ] [ self . _JOB_TYPE ] <EOL> self . _populate_config_resource ( configuration ) <EOL> if len ( self . schema ) > <NUM_LIT:0> : <EOL> configuration [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : _build_schema_resource ( self . schema ) } <EOL> return resource <EOL> def _scrub_local_properties ( self , cleaned ) : <EOL> """<STR_LIT>""" <EOL> schema = cleaned . pop ( '<STR_LIT>' , { '<STR_LIT>' : ( ) } ) <EOL> self . schema = _parse_schema_resource ( schema ) <EOL> @ classmethod <EOL> def from_api_repr ( cls , resource , client ) : <EOL> """<STR_LIT>""" <EOL> name , config = cls . _get_resource_config ( resource ) <EOL> dest_config = config [ '<STR_LIT>' ] <EOL> dataset = Dataset ( dest_config [ '<STR_LIT>' ] , client ) <EOL> destination = Table ( dest_config [ '<STR_LIT>' ] , dataset ) <EOL> source_urls = config . get ( '<STR_LIT>' , ( ) ) <EOL> job = cls ( name , destination , source_urls , client = client ) <EOL> job . _set_properties ( resource ) <EOL> return job <EOL> class _CopyConfiguration ( object ) : <EOL> """<STR_LIT>""" <EOL> _create_disposition = None <EOL> _write_disposition = None <EOL> class CopyJob ( _AsyncJob ) : <EOL> """<STR_LIT>""" <EOL> _JOB_TYPE = '<STR_LIT>' <EOL> def __init__ ( self , name , destination , sources , client ) : <EOL> super ( CopyJob , self ) . __init__ ( name , client ) <EOL> self . destination = destination <EOL> self . sources = sources <EOL> self . _configuration = _CopyConfiguration ( ) <EOL> create_disposition = CreateDisposition ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> write_disposition = WriteDisposition ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> def _populate_config_resource ( self , configuration ) : <EOL> """<STR_LIT>""" <EOL> if self . create_disposition is not None : <EOL> configuration [ '<STR_LIT>' ] = self . create_disposition <EOL> if self . write_disposition is not None : <EOL> configuration [ '<STR_LIT>' ] = self . write_disposition <EOL> def _build_resource ( self ) : <EOL> """<STR_LIT>""" <EOL> source_refs = [ { <EOL> '<STR_LIT>' : table . project , <EOL> '<STR_LIT>' : table . dataset_name , <EOL> '<STR_LIT>' : table . name , <EOL> } for table in self . sources ] <EOL> resource = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . project , <EOL> '<STR_LIT>' : self . name , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> self . _JOB_TYPE : { <EOL> '<STR_LIT>' : source_refs , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . destination . project , <EOL> '<STR_LIT>' : self . destination . dataset_name , <EOL> '<STR_LIT>' : self . destination . name , <EOL> } , <EOL> } , <EOL> } , <EOL> } <EOL> configuration = resource [ '<STR_LIT>' ] [ self . _JOB_TYPE ] <EOL> self . _populate_config_resource ( configuration ) <EOL> return resource <EOL> @ classmethod <EOL> def from_api_repr ( cls , resource , client ) : <EOL> """<STR_LIT>""" <EOL> name , config = cls . _get_resource_config ( resource ) <EOL> dest_config = config [ '<STR_LIT>' ] <EOL> dataset = Dataset ( dest_config [ '<STR_LIT>' ] , client ) <EOL> destination = Table ( dest_config [ '<STR_LIT>' ] , dataset ) <EOL> sources = [ ] <EOL> for source_config in config [ '<STR_LIT>' ] : <EOL> dataset = Dataset ( source_config [ '<STR_LIT>' ] , client ) <EOL> sources . append ( Table ( source_config [ '<STR_LIT>' ] , dataset ) ) <EOL> job = cls ( name , destination , sources , client = client ) <EOL> job . _set_properties ( resource ) <EOL> return job <EOL> class _ExtractConfiguration ( object ) : <EOL> """<STR_LIT>""" <EOL> _compression = None <EOL> _destination_format = None <EOL> _field_delimiter = None <EOL> _print_header = None <EOL> class ExtractTableToStorageJob ( _AsyncJob ) : <EOL> """<STR_LIT>""" <EOL> _JOB_TYPE = '<STR_LIT>' <EOL> def __init__ ( self , name , source , destination_uris , client ) : <EOL> super ( ExtractTableToStorageJob , self ) . __init__ ( name , client ) <EOL> self . source = source <EOL> self . destination_uris = destination_uris <EOL> self . _configuration = _ExtractConfiguration ( ) <EOL> compression = Compression ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> destination_format = DestinationFormat ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> field_delimiter = _TypedProperty ( '<STR_LIT>' , six . string_types ) <EOL> """<STR_LIT>""" <EOL> print_header = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> def _populate_config_resource ( self , configuration ) : <EOL> """<STR_LIT>""" <EOL> if self . compression is not None : <EOL> configuration [ '<STR_LIT>' ] = self . compression <EOL> if self . destination_format is not None : <EOL> configuration [ '<STR_LIT>' ] = self . destination_format <EOL> if self . field_delimiter is not None : <EOL> configuration [ '<STR_LIT>' ] = self . field_delimiter <EOL> if self . print_header is not None : <EOL> configuration [ '<STR_LIT>' ] = self . print_header <EOL> def _build_resource ( self ) : <EOL> """<STR_LIT>""" <EOL> source_ref = { <EOL> '<STR_LIT>' : self . source . project , <EOL> '<STR_LIT>' : self . source . dataset_name , <EOL> '<STR_LIT>' : self . source . name , <EOL> } <EOL> resource = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . project , <EOL> '<STR_LIT>' : self . name , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> self . _JOB_TYPE : { <EOL> '<STR_LIT>' : source_ref , <EOL> '<STR_LIT>' : self . destination_uris , <EOL> } , <EOL> } , <EOL> } <EOL> configuration = resource [ '<STR_LIT>' ] [ self . _JOB_TYPE ] <EOL> self . _populate_config_resource ( configuration ) <EOL> return resource <EOL> @ classmethod <EOL> def from_api_repr ( cls , resource , client ) : <EOL> """<STR_LIT>""" <EOL> name , config = cls . _get_resource_config ( resource ) <EOL> source_config = config [ '<STR_LIT>' ] <EOL> dataset = Dataset ( source_config [ '<STR_LIT>' ] , client ) <EOL> source = Table ( source_config [ '<STR_LIT>' ] , dataset ) <EOL> destination_uris = config [ '<STR_LIT>' ] <EOL> job = cls ( name , source , destination_uris , client = client ) <EOL> job . _set_properties ( resource ) <EOL> return job <EOL> class _AsyncQueryConfiguration ( object ) : <EOL> """<STR_LIT>""" <EOL> _allow_large_results = None <EOL> _create_disposition = None <EOL> _default_dataset = None <EOL> _destination = None <EOL> _flatten_results = None <EOL> _priority = None <EOL> _use_query_cache = None <EOL> _write_disposition = None <EOL> class QueryJob ( _AsyncJob ) : <EOL> """<STR_LIT>""" <EOL> _JOB_TYPE = '<STR_LIT>' <EOL> def __init__ ( self , name , query , client ) : <EOL> super ( QueryJob , self ) . __init__ ( name , client ) <EOL> self . query = query <EOL> self . _configuration = _AsyncQueryConfiguration ( ) <EOL> allow_large_results = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> create_disposition = CreateDisposition ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> default_dataset = _TypedProperty ( '<STR_LIT>' , Dataset ) <EOL> """<STR_LIT>""" <EOL> destination = _TypedProperty ( '<STR_LIT>' , Table ) <EOL> """<STR_LIT>""" <EOL> flatten_results = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> priority = QueryPriority ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> use_query_cache = _TypedProperty ( '<STR_LIT>' , bool ) <EOL> """<STR_LIT>""" <EOL> write_disposition = WriteDisposition ( '<STR_LIT>' ) <EOL> """<STR_LIT>""" <EOL> def _destination_table_resource ( self ) : <EOL> if self . destination is not None : <EOL> return { <EOL> '<STR_LIT>' : self . destination . project , <EOL> '<STR_LIT>' : self . destination . dataset_name , <EOL> '<STR_LIT>' : self . destination . name , <EOL> } <EOL> def _populate_config_resource ( self , configuration ) : <EOL> """<STR_LIT>""" <EOL> if self . allow_large_results is not None : <EOL> configuration [ '<STR_LIT>' ] = self . allow_large_results <EOL> if self . create_disposition is not None : <EOL> configuration [ '<STR_LIT>' ] = self . create_disposition <EOL> if self . default_dataset is not None : <EOL> configuration [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : self . default_dataset . project , <EOL> '<STR_LIT>' : self . default_dataset . name , <EOL> } <EOL> if self . destination is not None : <EOL> table_res = self . _destination_table_resource ( ) <EOL> configuration [ '<STR_LIT>' ] = table_res <EOL> if self . flatten_results is not None : <EOL> configuration [ '<STR_LIT>' ] = self . flatten_results <EOL> if self . priority is not None : <EOL> configuration [ '<STR_LIT>' ] = self . priority <EOL> if self . use_query_cache is not None : <EOL> configuration [ '<STR_LIT>' ] = self . use_query_cache <EOL> if self . write_disposition is not None : <EOL> configuration [ '<STR_LIT>' ] = self . write_disposition <EOL> def _build_resource ( self ) : <EOL> """<STR_LIT>""" <EOL> resource = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : self . project , <EOL> '<STR_LIT>' : self . name , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> self . _JOB_TYPE : { <EOL> '<STR_LIT>' : self . query , <EOL> } , <EOL> } , <EOL> } <EOL> configuration = resource [ '<STR_LIT>' ] [ self . _JOB_TYPE ] <EOL> self . _populate_config_resource ( configuration ) <EOL> return resource <EOL> def _scrub_local_properties ( self , cleaned ) : <EOL> """<STR_LIT>""" <EOL> configuration = cleaned [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> dest_remote = configuration . get ( '<STR_LIT>' ) <EOL> if dest_remote is None : <EOL> if self . destination is not None : <EOL> del self . destination <EOL> else : <EOL> dest_local = self . _destination_table_resource ( ) <EOL> if dest_remote != dest_local : <EOL> dataset = self . _client . dataset ( dest_remote [ '<STR_LIT>' ] ) <EOL> self . destination = dataset . table ( dest_remote [ '<STR_LIT>' ] ) <EOL> @ classmethod <EOL> def from_api_repr ( cls , resource , client ) : <EOL> """<STR_LIT>""" <EOL> name , config = cls . _get_resource_config ( resource ) <EOL> query = config [ '<STR_LIT>' ] <EOL> job = cls ( name , query , client = client ) <EOL> job . _set_properties ( resource ) <EOL> return job </s>
