def source(self): """Union[ \ google.cloud.bigquery.table.TableReference, \ google.cloud.bigquery.model.ModelReference \ ]: Table or Model from which data is to be loaded or extracted. """ source_config = _helpers._get_sub_prop( self._properties, ["configuration", "extract", "sourceTable"]) if source_config: return TableReference.from_api_repr(source_config) else: source_config = _helpers._get_sub_prop( self._properties, ["configuration", "extract", "sourceModel"]) return ModelReference.from_api_repr(source_config)
def destination_uris(self): """List[str]: URIs describing where the extracted data will be written in Cloud Storage, using the format ``gs://<bucket_name>/<object_name_or_glob>``. """ return _helpers._get_sub_prop( self._properties, ["configuration", "extract", "destinationUris"])
def _get_sub_prop(self, key, default=None): """Get a value in the ``self._properties[self._job_type]`` dictionary. Most job properties are inside the dictionary related to the job type (e.g. 'copy', 'extract', 'load', 'query'). Use this method to access those properties:: self._get_sub_prop('destinationTable') This is equivalent to using the ``_helpers._get_sub_prop`` function:: _helpers._get_sub_prop( self._properties, ['query', 'destinationTable']) Args: key (str): Key for the value to get in the ``self._properties[self._job_type]`` dictionary. default (Optional[object]): Default value to return if the key is not found. Defaults to :data:`None`. Returns: object: The value if present or the default. """ return _helpers._get_sub_prop(self._properties, [self._job_type, key], default=default)
def source_uris(self): """Optional[Sequence[str]]: URIs of data files to be loaded. See https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.source_uris for supported URI formats. None for jobs that load from a file. """ return _helpers._get_sub_prop(self._properties, ["configuration", "load", "sourceUris"])
def project(self): """Project bound to the job. Returns: str: the project (derived from the client). """ return _helpers._get_sub_prop(self._properties, ["jobReference", "projectId"])
def script_statistics(self): resource = _helpers._get_sub_prop( self._properties, ["statistics", "scriptStatistics"] ) if resource is None: return None return ScriptStatistics(resource)
def destination(self): """google.cloud.bigquery.table.TableReference: Table into which data is to be loaded. """ return TableReference.from_api_repr( _helpers._get_sub_prop( self._properties, ["configuration", "copy", "destinationTable"]))
def input_files(self): """Count of source files. Returns: Optional[int]: the count (None until set from the server). """ return _helpers._int_or_none( _helpers._get_sub_prop(self._properties, ["statistics", "load", "inputFiles"]))
def destination(self): """google.cloud.bigquery.table.TableReference: table where loaded rows are written See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.destination_table """ dest_config = _helpers._get_sub_prop( self._properties, ["configuration", "load", "destinationTable"]) return TableReference.from_api_repr(dest_config)
def output_rows(self): """Count of rows saved to destination table. Returns: Optional[int]: the count (None until set from the server). """ return _helpers._int_or_none( _helpers._get_sub_prop(self._properties, ["statistics", "load", "outputRows"]))
def sources(self): """List[google.cloud.bigquery.table.TableReference]): Table(s) from which data is to be loaded. """ source_configs = _helpers._get_sub_prop( self._properties, ["configuration", "copy", "sourceTables"]) if source_configs is None: single = _helpers._get_sub_prop( self._properties, ["configuration", "copy", "sourceTable"]) if single is None: raise KeyError( "Resource missing 'sourceTables' / 'sourceTable'") source_configs = [single] sources = [] for source_config in source_configs: table_ref = TableReference.from_api_repr(source_config) sources.append(table_ref) return sources
def parent_job_id(self): """Return the ID of the parent job. See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatistics.FIELDS.parent_job_id Returns: Optional[str]: parent job id. """ return _helpers._get_sub_prop(self._properties, ["statistics", "parentJobId"])
def ended(self): """Datetime at which the job finished. Returns: Optional[datetime.datetime]: the end time (None until set from the server). """ millis = _helpers._get_sub_prop(self._properties, ["statistics", "endTime"]) if millis is not None: return _helpers._datetime_from_microseconds(millis * 1000.0)
def num_child_jobs(self): """The number of child jobs executed. See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobStatistics.FIELDS.num_child_jobs Returns: int """ count = _helpers._get_sub_prop(self._properties, ["statistics", "numChildJobs"]) return int(count) if count is not None else 0
def input_file_bytes(self): """Count of bytes loaded from source files. Returns: Optional[int]: the count (None until set from the server). Raises: ValueError: for invalid value types. """ return _helpers._int_or_none( _helpers._get_sub_prop(self._properties, ["statistics", "load", "inputFileBytes"]))
def schema(self): """Optional[Sequence[Union[ \ :class:`~google.cloud.bigquery.schema.SchemaField`, \ Mapping[str, Any] \ ]]]: Schema of the destination table. See: https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationLoad.FIELDS.schema """ schema = _helpers._get_sub_prop(self._properties, ["load", "schema", "fields"]) if schema is None: return return [SchemaField.from_api_repr(field) for field in schema]
def reservation_usage(self): """Job resource usage breakdown by reservation. Returns: List[google.cloud.bigquery.job.ReservationUsage]: Reservation usage stats. Can be empty if not set from the server. """ usage_stats_raw = _helpers._get_sub_prop( self._properties, ["statistics", "reservationUsage"], default=()) return [ ReservationUsage(name=usage["name"], slot_ms=int(usage["slotMs"])) for usage in usage_stats_raw ]
def _call_fut(self, container, keys, **kw): from google.cloud.bigquery._helpers import _get_sub_prop return _get_sub_prop(container, keys, **kw)
def job_id(self): """str: ID of the job.""" return _helpers._get_sub_prop(self._properties, ["jobReference", "jobId"])
def _call_fut(self, container, keys, **kw): from google.cloud.bigquery._helpers import _get_sub_prop return _get_sub_prop(container, keys, **kw)
def location(self): """str: Location where the job runs.""" return _helpers._get_sub_prop(self._properties, ["jobReference", "location"])