text stringlengths 81 112k |
|---|
Construct JSON API representation for the parameter.
:rtype: dict
:returns: JSON mapping
def to_api_repr(self):
"""Construct JSON API representation for the parameter.
:rtype: dict
:returns: JSON mapping
"""
value = self.value
converter = _SCALAR_VALUE_TO_JSON_PARAM.get(self.type_)
if converter is not None:
value = converter(value)
resource = {
"parameterType": {"type": self.type_},
"parameterValue": {"value": value},
}
if self.name is not None:
resource["name"] = self.name
return resource |
Factory: construct parameter from JSON resource.
:type resource: dict
:param resource: JSON mapping of parameter
:rtype: :class:`~google.cloud.bigquery.query.ArrayQueryParameter`
:returns: instance
def from_api_repr(cls, resource):
"""Factory: construct parameter from JSON resource.
:type resource: dict
:param resource: JSON mapping of parameter
:rtype: :class:`~google.cloud.bigquery.query.ArrayQueryParameter`
:returns: instance
"""
array_type = resource["parameterType"]["arrayType"]["type"]
if array_type == "STRUCT":
return cls._from_api_repr_struct(resource)
return cls._from_api_repr_scalar(resource) |
Construct JSON API representation for the parameter.
:rtype: dict
:returns: JSON mapping
def to_api_repr(self):
"""Construct JSON API representation for the parameter.
:rtype: dict
:returns: JSON mapping
"""
values = self.values
if self.array_type == "RECORD" or self.array_type == "STRUCT":
reprs = [value.to_api_repr() for value in values]
a_type = reprs[0]["parameterType"]
a_values = [repr_["parameterValue"] for repr_ in reprs]
else:
a_type = {"type": self.array_type}
converter = _SCALAR_VALUE_TO_JSON_PARAM.get(self.array_type)
if converter is not None:
values = [converter(value) for value in values]
a_values = [{"value": value} for value in values]
resource = {
"parameterType": {"type": "ARRAY", "arrayType": a_type},
"parameterValue": {"arrayValues": a_values},
}
if self.name is not None:
resource["name"] = self.name
return resource |
Factory: construct parameter from JSON resource.
:type resource: dict
:param resource: JSON mapping of parameter
:rtype: :class:`~google.cloud.bigquery.query.StructQueryParameter`
:returns: instance
def from_api_repr(cls, resource):
"""Factory: construct parameter from JSON resource.
:type resource: dict
:param resource: JSON mapping of parameter
:rtype: :class:`~google.cloud.bigquery.query.StructQueryParameter`
:returns: instance
"""
name = resource.get("name")
instance = cls(name)
type_resources = {}
types = instance.struct_types
for item in resource["parameterType"]["structTypes"]:
types[item["name"]] = item["type"]["type"]
type_resources[item["name"]] = item["type"]
struct_values = resource["parameterValue"]["structValues"]
for key, value in struct_values.items():
type_ = types[key]
converted = None
if type_ == "STRUCT":
struct_resource = {
"name": key,
"parameterType": type_resources[key],
"parameterValue": value,
}
converted = StructQueryParameter.from_api_repr(struct_resource)
elif type_ == "ARRAY":
struct_resource = {
"name": key,
"parameterType": type_resources[key],
"parameterValue": value,
}
converted = ArrayQueryParameter.from_api_repr(struct_resource)
else:
value = value["value"]
converted = _QUERY_PARAMS_FROM_JSON[type_](value, None)
instance.struct_values[key] = converted
return instance |
Construct JSON API representation for the parameter.
:rtype: dict
:returns: JSON mapping
def to_api_repr(self):
"""Construct JSON API representation for the parameter.
:rtype: dict
:returns: JSON mapping
"""
s_types = {}
values = {}
for name, value in self.struct_values.items():
type_ = self.struct_types[name]
if type_ in ("STRUCT", "ARRAY"):
repr_ = value.to_api_repr()
s_types[name] = {"name": name, "type": repr_["parameterType"]}
values[name] = repr_["parameterValue"]
else:
s_types[name] = {"name": name, "type": {"type": type_}}
converter = _SCALAR_VALUE_TO_JSON_PARAM.get(type_)
if converter is not None:
value = converter(value)
values[name] = {"value": value}
resource = {
"parameterType": {
"type": "STRUCT",
"structTypes": [s_types[key] for key in self.struct_types],
},
"parameterValue": {"structValues": values},
}
if self.name is not None:
resource["name"] = self.name
return resource |
Update properties from resource in body of ``api_response``
:type api_response: dict
:param api_response: response returned from an API call
def _set_properties(self, api_response):
"""Update properties from resource in body of ``api_response``
:type api_response: dict
:param api_response: response returned from an API call
"""
job_id_present = (
"jobReference" in api_response
and "jobId" in api_response["jobReference"]
and "projectId" in api_response["jobReference"]
)
if not job_id_present:
raise ValueError("QueryResult requires a job reference")
self._properties.clear()
self._properties.update(copy.deepcopy(api_response)) |
Format the message into JSON expected by fluentd.
:type record: :class:`~logging.LogRecord`
:param record: the log record
:rtype: str
:returns: A JSON string formatted for GKE fluentd.
def format(self, record):
"""Format the message into JSON expected by fluentd.
:type record: :class:`~logging.LogRecord`
:param record: the log record
:rtype: str
:returns: A JSON string formatted for GKE fluentd.
"""
message = super(ContainerEngineHandler, self).format(record)
return format_stackdriver_json(record, message) |
Analyzes the sentiment of the provided text.
Example:
>>> from google.cloud import language_v1
>>>
>>> client = language_v1.LanguageServiceClient()
>>>
>>> # TODO: Initialize `document`:
>>> document = {}
>>>
>>> response = client.analyze_sentiment(document)
Args:
document (Union[dict, ~google.cloud.language_v1.types.Document]): Input document.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.language_v1.types.Document`
encoding_type (~google.cloud.language_v1.types.EncodingType): The encoding type used by the API to calculate sentence offsets.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.language_v1.types.AnalyzeSentimentResponse` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def analyze_sentiment(
self,
document,
encoding_type=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Analyzes the sentiment of the provided text.
Example:
>>> from google.cloud import language_v1
>>>
>>> client = language_v1.LanguageServiceClient()
>>>
>>> # TODO: Initialize `document`:
>>> document = {}
>>>
>>> response = client.analyze_sentiment(document)
Args:
document (Union[dict, ~google.cloud.language_v1.types.Document]): Input document.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.language_v1.types.Document`
encoding_type (~google.cloud.language_v1.types.EncodingType): The encoding type used by the API to calculate sentence offsets.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.language_v1.types.AnalyzeSentimentResponse` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "analyze_sentiment" not in self._inner_api_calls:
self._inner_api_calls[
"analyze_sentiment"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.analyze_sentiment,
default_retry=self._method_configs["AnalyzeSentiment"].retry,
default_timeout=self._method_configs["AnalyzeSentiment"].timeout,
client_info=self._client_info,
)
request = language_service_pb2.AnalyzeSentimentRequest(
document=document, encoding_type=encoding_type
)
return self._inner_api_calls["analyze_sentiment"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Call ``Commit`` on the GAPIC client with retry / sleep.
Retries the ``Commit`` RPC on Unavailable. Usually this RPC-level
retry is handled by the underlying GAPICd client, but in this case it
doesn't because ``Commit`` is not always idempotent. But here we know it
is "idempotent"-like because it has a transaction ID. We also need to do
our own retry to special-case the ``INVALID_ARGUMENT`` error.
Args:
client (~.firestore_v1beta1.client.Client): A client with
GAPIC client and configuration details.
write_pbs (List[google.cloud.proto.firestore.v1beta1.\
write_pb2.Write, ...]): A ``Write`` protobuf instance to
be committed.
transaction_id (bytes): ID of an existing transaction that
this commit will run in.
Returns:
google.cloud.firestore_v1beta1.types.CommitResponse:
The protobuf response from ``Commit``.
Raises:
~google.api_core.exceptions.GoogleAPICallError: If a non-retryable
exception is encountered.
def _commit_with_retry(client, write_pbs, transaction_id):
"""Call ``Commit`` on the GAPIC client with retry / sleep.
Retries the ``Commit`` RPC on Unavailable. Usually this RPC-level
retry is handled by the underlying GAPICd client, but in this case it
doesn't because ``Commit`` is not always idempotent. But here we know it
is "idempotent"-like because it has a transaction ID. We also need to do
our own retry to special-case the ``INVALID_ARGUMENT`` error.
Args:
client (~.firestore_v1beta1.client.Client): A client with
GAPIC client and configuration details.
write_pbs (List[google.cloud.proto.firestore.v1beta1.\
write_pb2.Write, ...]): A ``Write`` protobuf instance to
be committed.
transaction_id (bytes): ID of an existing transaction that
this commit will run in.
Returns:
google.cloud.firestore_v1beta1.types.CommitResponse:
The protobuf response from ``Commit``.
Raises:
~google.api_core.exceptions.GoogleAPICallError: If a non-retryable
exception is encountered.
"""
current_sleep = _INITIAL_SLEEP
while True:
try:
return client._firestore_api.commit(
client._database_string,
write_pbs,
transaction=transaction_id,
metadata=client._rpc_metadata,
)
except exceptions.ServiceUnavailable:
# Retry
pass
current_sleep = _sleep(current_sleep) |
Sleep and produce a new sleep time.
.. _Exponential Backoff And Jitter: https://www.awsarchitectureblog.com/\
2015/03/backoff.html
Select a duration between zero and ``current_sleep``. It might seem
counterintuitive to have so much jitter, but
`Exponential Backoff And Jitter`_ argues that "full jitter" is
the best strategy.
Args:
current_sleep (float): The current "max" for sleep interval.
max_sleep (Optional[float]): Eventual "max" sleep time
multiplier (Optional[float]): Multiplier for exponential backoff.
Returns:
float: Newly doubled ``current_sleep`` or ``max_sleep`` (whichever
is smaller)
def _sleep(current_sleep, max_sleep=_MAX_SLEEP, multiplier=_MULTIPLIER):
"""Sleep and produce a new sleep time.
.. _Exponential Backoff And Jitter: https://www.awsarchitectureblog.com/\
2015/03/backoff.html
Select a duration between zero and ``current_sleep``. It might seem
counterintuitive to have so much jitter, but
`Exponential Backoff And Jitter`_ argues that "full jitter" is
the best strategy.
Args:
current_sleep (float): The current "max" for sleep interval.
max_sleep (Optional[float]): Eventual "max" sleep time
multiplier (Optional[float]): Multiplier for exponential backoff.
Returns:
float: Newly doubled ``current_sleep`` or ``max_sleep`` (whichever
is smaller)
"""
actual_sleep = random.uniform(0.0, current_sleep)
time.sleep(actual_sleep)
return min(multiplier * current_sleep, max_sleep) |
Add `Write`` protobufs to this transaction.
Args:
write_pbs (List[google.cloud.proto.firestore.v1beta1.\
write_pb2.Write]): A list of write protobufs to be added.
Raises:
ValueError: If this transaction is read-only.
def _add_write_pbs(self, write_pbs):
"""Add `Write`` protobufs to this transaction.
Args:
write_pbs (List[google.cloud.proto.firestore.v1beta1.\
write_pb2.Write]): A list of write protobufs to be added.
Raises:
ValueError: If this transaction is read-only.
"""
if self._read_only:
raise ValueError(_WRITE_READ_ONLY)
super(Transaction, self)._add_write_pbs(write_pbs) |
Convert the current object to protobuf.
The ``retry_id`` value is used when retrying a transaction that
failed (e.g. due to contention). It is intended to be the "first"
transaction that failed (i.e. if multiple retries are needed).
Args:
retry_id (Union[bytes, NoneType]): Transaction ID of a transaction
to be retried.
Returns:
Optional[google.cloud.firestore_v1beta1.types.TransactionOptions]:
The protobuf ``TransactionOptions`` if ``read_only==True`` or if
there is a transaction ID to be retried, else :data:`None`.
Raises:
ValueError: If ``retry_id`` is not :data:`None` but the
transaction is read-only.
def _options_protobuf(self, retry_id):
"""Convert the current object to protobuf.
The ``retry_id`` value is used when retrying a transaction that
failed (e.g. due to contention). It is intended to be the "first"
transaction that failed (i.e. if multiple retries are needed).
Args:
retry_id (Union[bytes, NoneType]): Transaction ID of a transaction
to be retried.
Returns:
Optional[google.cloud.firestore_v1beta1.types.TransactionOptions]:
The protobuf ``TransactionOptions`` if ``read_only==True`` or if
there is a transaction ID to be retried, else :data:`None`.
Raises:
ValueError: If ``retry_id`` is not :data:`None` but the
transaction is read-only.
"""
if retry_id is not None:
if self._read_only:
raise ValueError(_CANT_RETRY_READ_ONLY)
return types.TransactionOptions(
read_write=types.TransactionOptions.ReadWrite(
retry_transaction=retry_id
)
)
elif self._read_only:
return types.TransactionOptions(
read_only=types.TransactionOptions.ReadOnly()
)
else:
return None |
Begin the transaction.
Args:
retry_id (Optional[bytes]): Transaction ID of a transaction to be
retried.
Raises:
ValueError: If the current transaction has already begun.
def _begin(self, retry_id=None):
"""Begin the transaction.
Args:
retry_id (Optional[bytes]): Transaction ID of a transaction to be
retried.
Raises:
ValueError: If the current transaction has already begun.
"""
if self.in_progress:
msg = _CANT_BEGIN.format(self._id)
raise ValueError(msg)
transaction_response = self._client._firestore_api.begin_transaction(
self._client._database_string,
options_=self._options_protobuf(retry_id),
metadata=self._client._rpc_metadata,
)
self._id = transaction_response.transaction |
Roll back the transaction.
Raises:
ValueError: If no transaction is in progress.
def _rollback(self):
"""Roll back the transaction.
Raises:
ValueError: If no transaction is in progress.
"""
if not self.in_progress:
raise ValueError(_CANT_ROLLBACK)
try:
# NOTE: The response is just ``google.protobuf.Empty``.
self._client._firestore_api.rollback(
self._client._database_string,
self._id,
metadata=self._client._rpc_metadata,
)
finally:
self._clean_up() |
Transactionally commit the changes accumulated.
Returns:
List[google.cloud.proto.firestore.v1beta1.\
write_pb2.WriteResult, ...]: The write results corresponding
to the changes committed, returned in the same order as the
changes were applied to this transaction. A write result contains
an ``update_time`` field.
Raises:
ValueError: If no transaction is in progress.
def _commit(self):
"""Transactionally commit the changes accumulated.
Returns:
List[google.cloud.proto.firestore.v1beta1.\
write_pb2.WriteResult, ...]: The write results corresponding
to the changes committed, returned in the same order as the
changes were applied to this transaction. A write result contains
an ``update_time`` field.
Raises:
ValueError: If no transaction is in progress.
"""
if not self.in_progress:
raise ValueError(_CANT_COMMIT)
commit_response = _commit_with_retry(self._client, self._write_pbs, self._id)
self._clean_up()
return list(commit_response.write_results) |
Begin transaction and call the wrapped callable.
If the callable raises an exception, the transaction will be rolled
back. If not, the transaction will be "ready" for ``Commit`` (i.e.
it will have staged writes).
Args:
transaction (~.firestore_v1beta1.transaction.Transaction): A
transaction to execute the callable within.
args (Tuple[Any, ...]): The extra positional arguments to pass
along to the wrapped callable.
kwargs (Dict[str, Any]): The extra keyword arguments to pass
along to the wrapped callable.
Returns:
Any: result of the wrapped callable.
Raises:
Exception: Any failure caused by ``to_wrap``.
def _pre_commit(self, transaction, *args, **kwargs):
"""Begin transaction and call the wrapped callable.
If the callable raises an exception, the transaction will be rolled
back. If not, the transaction will be "ready" for ``Commit`` (i.e.
it will have staged writes).
Args:
transaction (~.firestore_v1beta1.transaction.Transaction): A
transaction to execute the callable within.
args (Tuple[Any, ...]): The extra positional arguments to pass
along to the wrapped callable.
kwargs (Dict[str, Any]): The extra keyword arguments to pass
along to the wrapped callable.
Returns:
Any: result of the wrapped callable.
Raises:
Exception: Any failure caused by ``to_wrap``.
"""
# Force the ``transaction`` to be not "in progress".
transaction._clean_up()
transaction._begin(retry_id=self.retry_id)
# Update the stored transaction IDs.
self.current_id = transaction._id
if self.retry_id is None:
self.retry_id = self.current_id
try:
return self.to_wrap(transaction, *args, **kwargs)
except: # noqa
# NOTE: If ``rollback`` fails this will lose the information
# from the original failure.
transaction._rollback()
raise |
Try to commit the transaction.
If the transaction is read-write and the ``Commit`` fails with the
``ABORTED`` status code, it will be retried. Any other failure will
not be caught.
Args:
transaction (~.firestore_v1beta1.transaction.Transaction): The
transaction to be ``Commit``-ed.
Returns:
bool: Indicating if the commit succeeded.
def _maybe_commit(self, transaction):
"""Try to commit the transaction.
If the transaction is read-write and the ``Commit`` fails with the
``ABORTED`` status code, it will be retried. Any other failure will
not be caught.
Args:
transaction (~.firestore_v1beta1.transaction.Transaction): The
transaction to be ``Commit``-ed.
Returns:
bool: Indicating if the commit succeeded.
"""
try:
transaction._commit()
return True
except exceptions.GoogleAPICallError as exc:
if transaction._read_only:
raise
if isinstance(exc, exceptions.Aborted):
# If a read-write transaction returns ABORTED, retry.
return False
else:
raise |
Return a fully-qualified profile string.
def profile_path(cls, project, tenant, profile):
"""Return a fully-qualified profile string."""
return google.api_core.path_template.expand(
"projects/{project}/tenants/{tenant}/profiles/{profile}",
project=project,
tenant=tenant,
profile=profile,
) |
Creates and returns a new profile.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> parent = client.tenant_path('[PROJECT]', '[TENANT]')
>>>
>>> # TODO: Initialize `profile`:
>>> profile = {}
>>>
>>> response = client.create_profile(parent, profile)
Args:
parent (str): Required.
The name of the tenant this profile belongs to.
The format is "projects/{project\_id}/tenants/{tenant\_id}", for
example, "projects/api-test-project/tenants/foo".
profile (Union[dict, ~google.cloud.talent_v4beta1.types.Profile]): Required.
The profile to be created.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.Profile`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Profile` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def create_profile(
self,
parent,
profile,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates and returns a new profile.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> parent = client.tenant_path('[PROJECT]', '[TENANT]')
>>>
>>> # TODO: Initialize `profile`:
>>> profile = {}
>>>
>>> response = client.create_profile(parent, profile)
Args:
parent (str): Required.
The name of the tenant this profile belongs to.
The format is "projects/{project\_id}/tenants/{tenant\_id}", for
example, "projects/api-test-project/tenants/foo".
profile (Union[dict, ~google.cloud.talent_v4beta1.types.Profile]): Required.
The profile to be created.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.Profile`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Profile` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "create_profile" not in self._inner_api_calls:
self._inner_api_calls[
"create_profile"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.create_profile,
default_retry=self._method_configs["CreateProfile"].retry,
default_timeout=self._method_configs["CreateProfile"].timeout,
client_info=self._client_info,
)
request = profile_service_pb2.CreateProfileRequest(
parent=parent, profile=profile
)
return self._inner_api_calls["create_profile"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Gets the specified profile.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> name = client.profile_path('[PROJECT]', '[TENANT]', '[PROFILE]')
>>>
>>> response = client.get_profile(name)
Args:
name (str): Required.
Resource name of the profile to get.
The format is
"projects/{project\_id}/tenants/{tenant\_id}/profiles/{profile\_id}",
for example, "projects/api-test-project/tenants/foo/profiles/bar".
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Profile` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def get_profile(
self,
name,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Gets the specified profile.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> name = client.profile_path('[PROJECT]', '[TENANT]', '[PROFILE]')
>>>
>>> response = client.get_profile(name)
Args:
name (str): Required.
Resource name of the profile to get.
The format is
"projects/{project\_id}/tenants/{tenant\_id}/profiles/{profile\_id}",
for example, "projects/api-test-project/tenants/foo/profiles/bar".
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Profile` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "get_profile" not in self._inner_api_calls:
self._inner_api_calls[
"get_profile"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.get_profile,
default_retry=self._method_configs["GetProfile"].retry,
default_timeout=self._method_configs["GetProfile"].timeout,
client_info=self._client_info,
)
request = profile_service_pb2.GetProfileRequest(name=name)
return self._inner_api_calls["get_profile"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Updates the specified profile and returns the updated result.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> # TODO: Initialize `profile`:
>>> profile = {}
>>>
>>> response = client.update_profile(profile)
Args:
profile (Union[dict, ~google.cloud.talent_v4beta1.types.Profile]): Required.
Profile to be updated.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.Profile`
update_mask (Union[dict, ~google.cloud.talent_v4beta1.types.FieldMask]): Optional.
A field mask to specify the profile fields to update.
A full update is performed if it is unset.
Valid values are:
- externalId
- source
- uri
- isHirable
- createTime
- updateTime
- resumeHrxml
- personNames
- addresses
- emailAddresses
- phoneNumbers
- personalUris
- additionalContactInfo
- employmentRecords
- educationRecords
- skills
- projects
- publications
- patents
- certifications
- jobApplications
- recruitingNotes
- customAttributes
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.FieldMask`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Profile` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def update_profile(
self,
profile,
update_mask=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Updates the specified profile and returns the updated result.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> # TODO: Initialize `profile`:
>>> profile = {}
>>>
>>> response = client.update_profile(profile)
Args:
profile (Union[dict, ~google.cloud.talent_v4beta1.types.Profile]): Required.
Profile to be updated.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.Profile`
update_mask (Union[dict, ~google.cloud.talent_v4beta1.types.FieldMask]): Optional.
A field mask to specify the profile fields to update.
A full update is performed if it is unset.
Valid values are:
- externalId
- source
- uri
- isHirable
- createTime
- updateTime
- resumeHrxml
- personNames
- addresses
- emailAddresses
- phoneNumbers
- personalUris
- additionalContactInfo
- employmentRecords
- educationRecords
- skills
- projects
- publications
- patents
- certifications
- jobApplications
- recruitingNotes
- customAttributes
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.FieldMask`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Profile` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "update_profile" not in self._inner_api_calls:
self._inner_api_calls[
"update_profile"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.update_profile,
default_retry=self._method_configs["UpdateProfile"].retry,
default_timeout=self._method_configs["UpdateProfile"].timeout,
client_info=self._client_info,
)
request = profile_service_pb2.UpdateProfileRequest(
profile=profile, update_mask=update_mask
)
return self._inner_api_calls["update_profile"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Searches for profiles within a tenant.
For example, search by raw queries "software engineer in Mountain View"
or search by structured filters (location filter, education filter,
etc.).
See ``SearchProfilesRequest`` for more information.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> parent = client.tenant_path('[PROJECT]', '[TENANT]')
>>>
>>> # TODO: Initialize `request_metadata`:
>>> request_metadata = {}
>>>
>>> # Iterate over all results
>>> for element in client.search_profiles(parent, request_metadata):
... # process element
... pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.search_profiles(parent, request_metadata).pages:
... for element in page:
... # process element
... pass
Args:
parent (str): Required.
The resource name of the tenant to search within.
The format is "projects/{project\_id}/tenants/{tenant\_id}", for
example, "projects/api-test-project/tenants/foo".
request_metadata (Union[dict, ~google.cloud.talent_v4beta1.types.RequestMetadata]): Required.
The meta information collected about the profile search user. This is used
to improve the search quality of the service. These values are provided by
users, and must be precise and consistent.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.RequestMetadata`
profile_query (Union[dict, ~google.cloud.talent_v4beta1.types.ProfileQuery]): Optional.
Search query to execute. See ``ProfileQuery`` for more details.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.ProfileQuery`
page_size (int): The maximum number of resources contained in the
underlying API response. If page streaming is performed per-
resource, this parameter does not affect the return value. If page
streaming is performed per-page, this determines the maximum number
of resources in a page.
offset (int): Optional.
An integer that specifies the current offset (that is, starting result)
in search results. This field is only considered if ``page_token`` is
unset.
The maximum allowed value is 5000. Otherwise an error is thrown.
For example, 0 means to search from the first profile, and 10 means to
search from the 11th profile. This can be used for pagination, for
example pageSize = 10 and offset = 10 means to search from the second
page.
disable_spell_check (bool): Optional.
This flag controls the spell-check feature. If ``false``, the service
attempts to correct a misspelled query.
For example, "enginee" is corrected to "engineer".
order_by (str): Optional.
The criteria that determines how search results are sorted. Defaults is
"relevance desc" if no value is specified.
Supported options are:
- "relevance desc": By descending relevance, as determined by the API
algorithms.
- "update\_date desc": Sort by ``Profile.update_date`` in descending
order (recently updated profiles first).
- "create\_date desc": Sort by ``Profile.create_date`` in descending
order (recently created profiles first).
- "first\_name": Sort by ``PersonStrcuturedName.given_name`` in
ascending order.
- "first\_name desc": Sort by ``PersonStrcuturedName.given_name`` in
descending order.
- "last\_name": Sort by ``PersonStrcuturedName.family_name`` in
ascending order.
- "last\_name desc": Sort by ``PersonStrcuturedName.family_name`` in
ascending order.
case_sensitive_sort (bool): Optional.
When sort by field is based on alphabetical order, sort values case
sensitively (based on ASCII) when the value is set to true. Default value
is case in-sensitive sort (false).
histogram_queries (list[Union[dict, ~google.cloud.talent_v4beta1.types.HistogramQuery]]): Optional.
A list of expressions specifies histogram requests against matching
profiles for ``SearchProfilesRequest``.
The expression syntax looks like a function definition with optional
parameters.
Function syntax: function\_name(histogram\_facet[, list of buckets])
Data types:
- Histogram facet: facet names with format [a-zA-Z][a-zA-Z0-9\_]+.
- String: string like "any string with backslash escape for quote(")."
- Number: whole number and floating point number like 10, -1 and -0.01.
- List: list of elements with comma(,) separator surrounded by square
brackets. For example, [1, 2, 3] and ["one", "two", "three"].
Built-in constants:
- MIN (minimum number similar to java Double.MIN\_VALUE)
- MAX (maximum number similar to java Double.MAX\_VALUE)
Built-in functions:
- bucket(start, end[, label]) Bucket build-in function creates a bucket
with range of \`start, end). Note that the end is exclusive. For
example, bucket(1, MAX, "positive number") or bucket(1, 10).
Histogram Facets:
- admin1: Admin1 is a global placeholder for referring to state,
province, or the particular term a country uses to define the
geographic structure below the country level. Examples include states
codes such as "CA", "IL", "NY", and provinces, such as "BC".
- locality: Locality is a global placeholder for referring to city,
town, or the particular term a country uses to define the geographic
structure below the admin1 level. Examples include city names such as
"Mountain View" and "New York".
- extended\_locality: Extended locality is concatenated version of
admin1 and locality with comma separator. For example, "Mountain
View, CA" and "New York, NY".
- postal\_code: Postal code of profile which follows locale code.
- country: Country code (ISO-3166-1 alpha-2 code) of profile, such as
US, JP, GB.
- job\_title: Normalized job titles specified in EmploymentHistory.
- company\_name: Normalized company name of profiles to match on.
- institution: The school name. For example, "MIT", "University of
California, Berkeley"
- degree: Highest education degree in ISCED code. Each value in degree
covers specific level of education, without any expansion to upper
nor lower levels of education degree.
- experience\_in\_months: experience in months. 0 means 0 month to 1
month (exclusive).
- application\_date: The application date specifies application start
dates. See [ApplicationDateFilter\` for more details.
- application\_outcome\_reason: The application outcome reason
specifies the outcome reasons of job application. See
``ApplicationOutcomeReasonFilter`` for more details.
- application\_last\_stage: The application last stage specifies the
last stage of job application. See ``ApplicationLastStageFilter`` for
more details.
- application\_job\_title: The application job title specifies the job
applied for in the application. See ``ApplicationJobFilter`` for more
details.
- application\_status: The application status specifies the status of
job application. See ``ApplicationStatusFilter`` for more details.
- hirable\_status: Hirable status specifies the profile's hirable
status.
- string\_custom\_attribute: String custom attributes. Values can be
accessed via square bracket notation like
string\_custom\_attribute["key1"].
- numeric\_custom\_attribute: Numeric custom attributes. Values can be
accessed via square bracket notation like
numeric\_custom\_attribute["key1"].
Example expressions:
- count(admin1)
- count(experience\_in\_months, [bucket(0, 12, "1 year"), bucket(12,
36, "1-3 years"), bucket(36, MAX, "3+ years")])
- count(string\_custom\_attribute["assigned\_recruiter"])
- count(numeric\_custom\_attribute["favorite\_number"], [bucket(MIN, 0,
"negative"), bucket(0, MAX, "non-negative")])
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.HistogramQuery`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.talent_v4beta1.types.HistogramQueryResult` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def search_profiles(
self,
parent,
request_metadata,
profile_query=None,
page_size=None,
offset=None,
disable_spell_check=None,
order_by=None,
case_sensitive_sort=None,
histogram_queries=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Searches for profiles within a tenant.
For example, search by raw queries "software engineer in Mountain View"
or search by structured filters (location filter, education filter,
etc.).
See ``SearchProfilesRequest`` for more information.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.ProfileServiceClient()
>>>
>>> parent = client.tenant_path('[PROJECT]', '[TENANT]')
>>>
>>> # TODO: Initialize `request_metadata`:
>>> request_metadata = {}
>>>
>>> # Iterate over all results
>>> for element in client.search_profiles(parent, request_metadata):
... # process element
... pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.search_profiles(parent, request_metadata).pages:
... for element in page:
... # process element
... pass
Args:
parent (str): Required.
The resource name of the tenant to search within.
The format is "projects/{project\_id}/tenants/{tenant\_id}", for
example, "projects/api-test-project/tenants/foo".
request_metadata (Union[dict, ~google.cloud.talent_v4beta1.types.RequestMetadata]): Required.
The meta information collected about the profile search user. This is used
to improve the search quality of the service. These values are provided by
users, and must be precise and consistent.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.RequestMetadata`
profile_query (Union[dict, ~google.cloud.talent_v4beta1.types.ProfileQuery]): Optional.
Search query to execute. See ``ProfileQuery`` for more details.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.ProfileQuery`
page_size (int): The maximum number of resources contained in the
underlying API response. If page streaming is performed per-
resource, this parameter does not affect the return value. If page
streaming is performed per-page, this determines the maximum number
of resources in a page.
offset (int): Optional.
An integer that specifies the current offset (that is, starting result)
in search results. This field is only considered if ``page_token`` is
unset.
The maximum allowed value is 5000. Otherwise an error is thrown.
For example, 0 means to search from the first profile, and 10 means to
search from the 11th profile. This can be used for pagination, for
example pageSize = 10 and offset = 10 means to search from the second
page.
disable_spell_check (bool): Optional.
This flag controls the spell-check feature. If ``false``, the service
attempts to correct a misspelled query.
For example, "enginee" is corrected to "engineer".
order_by (str): Optional.
The criteria that determines how search results are sorted. Defaults is
"relevance desc" if no value is specified.
Supported options are:
- "relevance desc": By descending relevance, as determined by the API
algorithms.
- "update\_date desc": Sort by ``Profile.update_date`` in descending
order (recently updated profiles first).
- "create\_date desc": Sort by ``Profile.create_date`` in descending
order (recently created profiles first).
- "first\_name": Sort by ``PersonStrcuturedName.given_name`` in
ascending order.
- "first\_name desc": Sort by ``PersonStrcuturedName.given_name`` in
descending order.
- "last\_name": Sort by ``PersonStrcuturedName.family_name`` in
ascending order.
- "last\_name desc": Sort by ``PersonStrcuturedName.family_name`` in
ascending order.
case_sensitive_sort (bool): Optional.
When sort by field is based on alphabetical order, sort values case
sensitively (based on ASCII) when the value is set to true. Default value
is case in-sensitive sort (false).
histogram_queries (list[Union[dict, ~google.cloud.talent_v4beta1.types.HistogramQuery]]): Optional.
A list of expressions specifies histogram requests against matching
profiles for ``SearchProfilesRequest``.
The expression syntax looks like a function definition with optional
parameters.
Function syntax: function\_name(histogram\_facet[, list of buckets])
Data types:
- Histogram facet: facet names with format [a-zA-Z][a-zA-Z0-9\_]+.
- String: string like "any string with backslash escape for quote(")."
- Number: whole number and floating point number like 10, -1 and -0.01.
- List: list of elements with comma(,) separator surrounded by square
brackets. For example, [1, 2, 3] and ["one", "two", "three"].
Built-in constants:
- MIN (minimum number similar to java Double.MIN\_VALUE)
- MAX (maximum number similar to java Double.MAX\_VALUE)
Built-in functions:
- bucket(start, end[, label]) Bucket build-in function creates a bucket
with range of \`start, end). Note that the end is exclusive. For
example, bucket(1, MAX, "positive number") or bucket(1, 10).
Histogram Facets:
- admin1: Admin1 is a global placeholder for referring to state,
province, or the particular term a country uses to define the
geographic structure below the country level. Examples include states
codes such as "CA", "IL", "NY", and provinces, such as "BC".
- locality: Locality is a global placeholder for referring to city,
town, or the particular term a country uses to define the geographic
structure below the admin1 level. Examples include city names such as
"Mountain View" and "New York".
- extended\_locality: Extended locality is concatenated version of
admin1 and locality with comma separator. For example, "Mountain
View, CA" and "New York, NY".
- postal\_code: Postal code of profile which follows locale code.
- country: Country code (ISO-3166-1 alpha-2 code) of profile, such as
US, JP, GB.
- job\_title: Normalized job titles specified in EmploymentHistory.
- company\_name: Normalized company name of profiles to match on.
- institution: The school name. For example, "MIT", "University of
California, Berkeley"
- degree: Highest education degree in ISCED code. Each value in degree
covers specific level of education, without any expansion to upper
nor lower levels of education degree.
- experience\_in\_months: experience in months. 0 means 0 month to 1
month (exclusive).
- application\_date: The application date specifies application start
dates. See [ApplicationDateFilter\` for more details.
- application\_outcome\_reason: The application outcome reason
specifies the outcome reasons of job application. See
``ApplicationOutcomeReasonFilter`` for more details.
- application\_last\_stage: The application last stage specifies the
last stage of job application. See ``ApplicationLastStageFilter`` for
more details.
- application\_job\_title: The application job title specifies the job
applied for in the application. See ``ApplicationJobFilter`` for more
details.
- application\_status: The application status specifies the status of
job application. See ``ApplicationStatusFilter`` for more details.
- hirable\_status: Hirable status specifies the profile's hirable
status.
- string\_custom\_attribute: String custom attributes. Values can be
accessed via square bracket notation like
string\_custom\_attribute["key1"].
- numeric\_custom\_attribute: Numeric custom attributes. Values can be
accessed via square bracket notation like
numeric\_custom\_attribute["key1"].
Example expressions:
- count(admin1)
- count(experience\_in\_months, [bucket(0, 12, "1 year"), bucket(12,
36, "1-3 years"), bucket(36, MAX, "3+ years")])
- count(string\_custom\_attribute["assigned\_recruiter"])
- count(numeric\_custom\_attribute["favorite\_number"], [bucket(MIN, 0,
"negative"), bucket(0, MAX, "non-negative")])
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.HistogramQuery`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.talent_v4beta1.types.HistogramQueryResult` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "search_profiles" not in self._inner_api_calls:
self._inner_api_calls[
"search_profiles"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.search_profiles,
default_retry=self._method_configs["SearchProfiles"].retry,
default_timeout=self._method_configs["SearchProfiles"].timeout,
client_info=self._client_info,
)
request = profile_service_pb2.SearchProfilesRequest(
parent=parent,
request_metadata=request_metadata,
profile_query=profile_query,
page_size=page_size,
offset=offset,
disable_spell_check=disable_spell_check,
order_by=order_by,
case_sensitive_sort=case_sensitive_sort,
histogram_queries=histogram_queries,
)
iterator = google.api_core.page_iterator.GRPCIterator(
client=None,
method=functools.partial(
self._inner_api_calls["search_profiles"],
retry=retry,
timeout=timeout,
metadata=metadata,
),
request=request,
items_field="histogram_query_results",
request_token_field="page_token",
response_token_field="next_page_token",
)
return iterator |
Perform an online prediction. The prediction result will be directly
returned in the response. Available for following ML problems, and their
expected request payloads:
- Image Classification - Image in .JPEG, .GIF or .PNG format,
image\_bytes up to 30MB.
- Image Object Detection - Image in .JPEG, .GIF or .PNG format,
image\_bytes up to 30MB.
- Text Classification - TextSnippet, content up to 10,000 characters,
UTF-8 encoded.
- Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8
NFC encoded. \* Translation - TextSnippet, content up to 25,000
characters, UTF-8 encoded.
- Tables - Row, with column values matching the columns of the model,
up to 5MB.
- Text Sentiment - TextSnippet, content up 500 characters, UTF-8
encoded.
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.PredictionServiceClient()
>>>
>>> name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')
>>>
>>> # TODO: Initialize `payload`:
>>> payload = {}
>>>
>>> response = client.predict(name, payload)
Args:
name (str): Name of the model requested to serve the prediction.
payload (Union[dict, ~google.cloud.automl_v1beta1.types.ExamplePayload]): Required.
Payload to perform a prediction on. The payload must match the
problem type that the model was trained to solve.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.automl_v1beta1.types.ExamplePayload`
params (dict[str -> str]): Additional domain-specific parameters, any string must be up to 25000
characters long.
- For Image Classification:
``score_threshold`` - (float) A value from 0.0 to 1.0. When the model
makes predictions for an image, it will only produce results that
have at least this confidence score. The default is 0.5.
- For Image Object Detection: ``score_threshold`` - (float) When Model
detects objects on the image, it will only produce bounding boxes
which have at least this confidence score. Value in 0 to 1 range,
default is 0.5. ``max_bounding_box_count`` - (int64) No more than
this number of bounding boxes will be returned in the response.
Default is 100, the requested value may be limited by server.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.automl_v1beta1.types.PredictResponse` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def predict(
self,
name,
payload,
params=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Perform an online prediction. The prediction result will be directly
returned in the response. Available for following ML problems, and their
expected request payloads:
- Image Classification - Image in .JPEG, .GIF or .PNG format,
image\_bytes up to 30MB.
- Image Object Detection - Image in .JPEG, .GIF or .PNG format,
image\_bytes up to 30MB.
- Text Classification - TextSnippet, content up to 10,000 characters,
UTF-8 encoded.
- Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8
NFC encoded. \* Translation - TextSnippet, content up to 25,000
characters, UTF-8 encoded.
- Tables - Row, with column values matching the columns of the model,
up to 5MB.
- Text Sentiment - TextSnippet, content up 500 characters, UTF-8
encoded.
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.PredictionServiceClient()
>>>
>>> name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')
>>>
>>> # TODO: Initialize `payload`:
>>> payload = {}
>>>
>>> response = client.predict(name, payload)
Args:
name (str): Name of the model requested to serve the prediction.
payload (Union[dict, ~google.cloud.automl_v1beta1.types.ExamplePayload]): Required.
Payload to perform a prediction on. The payload must match the
problem type that the model was trained to solve.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.automl_v1beta1.types.ExamplePayload`
params (dict[str -> str]): Additional domain-specific parameters, any string must be up to 25000
characters long.
- For Image Classification:
``score_threshold`` - (float) A value from 0.0 to 1.0. When the model
makes predictions for an image, it will only produce results that
have at least this confidence score. The default is 0.5.
- For Image Object Detection: ``score_threshold`` - (float) When Model
detects objects on the image, it will only produce bounding boxes
which have at least this confidence score. Value in 0 to 1 range,
default is 0.5. ``max_bounding_box_count`` - (int64) No more than
this number of bounding boxes will be returned in the response.
Default is 100, the requested value may be limited by server.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.automl_v1beta1.types.PredictResponse` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "predict" not in self._inner_api_calls:
self._inner_api_calls[
"predict"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.predict,
default_retry=self._method_configs["Predict"].retry,
default_timeout=self._method_configs["Predict"].timeout,
client_info=self._client_info,
)
request = prediction_service_pb2.PredictRequest(
name=name, payload=payload, params=params
)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("name", name)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)
return self._inner_api_calls["predict"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Perform a batch prediction. Unlike the online ``Predict``, batch
prediction result won't be immediately available in the response.
Instead, a long running operation object is returned. User can poll the
operation result via ``GetOperation`` method. Once the operation is
done, ``BatchPredictResult`` is returned in the ``response`` field.
Available for following ML problems:
- Video Classification
- Text Extraction
- Tables
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.PredictionServiceClient()
>>>
>>> name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')
>>>
>>> # TODO: Initialize `input_config`:
>>> input_config = {}
>>>
>>> # TODO: Initialize `output_config`:
>>> output_config = {}
>>>
>>> response = client.batch_predict(name, input_config, output_config)
>>>
>>> def callback(operation_future):
... # Handle result.
... result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Args:
name (str): Name of the model requested to serve the batch prediction.
input_config (Union[dict, ~google.cloud.automl_v1beta1.types.BatchPredictInputConfig]): Required. The input configuration for batch prediction.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.automl_v1beta1.types.BatchPredictInputConfig`
output_config (Union[dict, ~google.cloud.automl_v1beta1.types.BatchPredictOutputConfig]): Required. The Configuration specifying where output predictions should
be written.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.automl_v1beta1.types.BatchPredictOutputConfig`
params (dict[str -> str]): Additional domain-specific parameters for the predictions, any string
must be up to 25000 characters long.
- For Video Classification : ``score_threshold`` - (float) A value from
0.0 to 1.0. When the model makes predictions for a video, it will
only produce results that have at least this confidence score. The
default is 0.5. ``segment_classification`` - (boolean) Set to true to
request segment-level classification. AutoML Video Intelligence
returns labels and their confidence scores for the entire segment of
the video that user specified in the request configuration. The
default is "true". ``shot_classification`` - (boolean) Set to true to
request shot-level classification. AutoML Video Intelligence
determines the boundaries for each camera shot in the entire segment
of the video that user specified in the request configuration. AutoML
Video Intelligence then returns labels and their confidence scores
for each detected shot, along with the start and end time of the
shot. WARNING: Model evaluation is not done for this classification
type, the quality of it depends on training data, but there are no
metrics provided to describe that quality. The default is "false".
``1s_interval_classification`` - (boolean) Set to true to request
classification for a video at one-second intervals. AutoML Video
Intelligence returns labels and their confidence scores for each
second of the entire segment of the video that user specified in the
request configuration. WARNING: Model evaluation is not done for this
classification type, the quality of it depends on training data, but
there are no metrics provided to describe that quality. The default
is "false".
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.automl_v1beta1.types._OperationFuture` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def batch_predict(
self,
name,
input_config,
output_config,
params=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Perform a batch prediction. Unlike the online ``Predict``, batch
prediction result won't be immediately available in the response.
Instead, a long running operation object is returned. User can poll the
operation result via ``GetOperation`` method. Once the operation is
done, ``BatchPredictResult`` is returned in the ``response`` field.
Available for following ML problems:
- Video Classification
- Text Extraction
- Tables
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.PredictionServiceClient()
>>>
>>> name = client.model_path('[PROJECT]', '[LOCATION]', '[MODEL]')
>>>
>>> # TODO: Initialize `input_config`:
>>> input_config = {}
>>>
>>> # TODO: Initialize `output_config`:
>>> output_config = {}
>>>
>>> response = client.batch_predict(name, input_config, output_config)
>>>
>>> def callback(operation_future):
... # Handle result.
... result = operation_future.result()
>>>
>>> response.add_done_callback(callback)
>>>
>>> # Handle metadata.
>>> metadata = response.metadata()
Args:
name (str): Name of the model requested to serve the batch prediction.
input_config (Union[dict, ~google.cloud.automl_v1beta1.types.BatchPredictInputConfig]): Required. The input configuration for batch prediction.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.automl_v1beta1.types.BatchPredictInputConfig`
output_config (Union[dict, ~google.cloud.automl_v1beta1.types.BatchPredictOutputConfig]): Required. The Configuration specifying where output predictions should
be written.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.automl_v1beta1.types.BatchPredictOutputConfig`
params (dict[str -> str]): Additional domain-specific parameters for the predictions, any string
must be up to 25000 characters long.
- For Video Classification : ``score_threshold`` - (float) A value from
0.0 to 1.0. When the model makes predictions for a video, it will
only produce results that have at least this confidence score. The
default is 0.5. ``segment_classification`` - (boolean) Set to true to
request segment-level classification. AutoML Video Intelligence
returns labels and their confidence scores for the entire segment of
the video that user specified in the request configuration. The
default is "true". ``shot_classification`` - (boolean) Set to true to
request shot-level classification. AutoML Video Intelligence
determines the boundaries for each camera shot in the entire segment
of the video that user specified in the request configuration. AutoML
Video Intelligence then returns labels and their confidence scores
for each detected shot, along with the start and end time of the
shot. WARNING: Model evaluation is not done for this classification
type, the quality of it depends on training data, but there are no
metrics provided to describe that quality. The default is "false".
``1s_interval_classification`` - (boolean) Set to true to request
classification for a video at one-second intervals. AutoML Video
Intelligence returns labels and their confidence scores for each
second of the entire segment of the video that user specified in the
request configuration. WARNING: Model evaluation is not done for this
classification type, the quality of it depends on training data, but
there are no metrics provided to describe that quality. The default
is "false".
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.automl_v1beta1.types._OperationFuture` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "batch_predict" not in self._inner_api_calls:
self._inner_api_calls[
"batch_predict"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.batch_predict,
default_retry=self._method_configs["BatchPredict"].retry,
default_timeout=self._method_configs["BatchPredict"].timeout,
client_info=self._client_info,
)
request = prediction_service_pb2.BatchPredictRequest(
name=name,
input_config=input_config,
output_config=output_config,
params=params,
)
if metadata is None:
metadata = []
metadata = list(metadata)
try:
routing_header = [("name", name)]
except AttributeError:
pass
else:
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
routing_header
)
metadata.append(routing_metadata)
operation = self._inner_api_calls["batch_predict"](
request, retry=retry, timeout=timeout, metadata=metadata
)
return google.api_core.operation.from_gapic(
operation,
self.transport._operations_client,
prediction_service_pb2.BatchPredictResult,
metadata_type=proto_operations_pb2.OperationMetadata,
) |
Factory to retrieve JSON credentials while creating client.
:type json_credentials_path: str
:param json_credentials_path: The path to a private key file (this file
was given to you when you created the
service account). This file must contain
a JSON object with a private key and
other credentials information (downloaded
from the Google APIs console).
:type args: tuple
:param args: Remaining positional arguments to pass to constructor.
:type kwargs: dict
:param kwargs: Remaining keyword arguments to pass to constructor.
:rtype: :class:`_ClientFactoryMixin`
:returns: The client created with the retrieved JSON credentials.
:raises TypeError: if there is a conflict with the kwargs
and the credentials created by the factory.
def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
"""Factory to retrieve JSON credentials while creating client.
:type json_credentials_path: str
:param json_credentials_path: The path to a private key file (this file
was given to you when you created the
service account). This file must contain
a JSON object with a private key and
other credentials information (downloaded
from the Google APIs console).
:type args: tuple
:param args: Remaining positional arguments to pass to constructor.
:type kwargs: dict
:param kwargs: Remaining keyword arguments to pass to constructor.
:rtype: :class:`_ClientFactoryMixin`
:returns: The client created with the retrieved JSON credentials.
:raises TypeError: if there is a conflict with the kwargs
and the credentials created by the factory.
"""
if "credentials" in kwargs:
raise TypeError("credentials must not be in keyword arguments")
with io.open(json_credentials_path, "r", encoding="utf-8") as json_fi:
credentials_info = json.load(json_fi)
credentials = service_account.Credentials.from_service_account_info(
credentials_info
)
if cls._SET_PROJECT:
if "project" not in kwargs:
kwargs["project"] = credentials_info.get("project_id")
kwargs["credentials"] = credentials
return cls(*args, **kwargs) |
Getter for object used for HTTP transport.
:rtype: :class:`~requests.Session`
:returns: An HTTP object.
def _http(self):
"""Getter for object used for HTTP transport.
:rtype: :class:`~requests.Session`
:returns: An HTTP object.
"""
if self._http_internal is None:
self._http_internal = google.auth.transport.requests.AuthorizedSession(
self._credentials
)
return self._http_internal |
Return a fully-qualified alert_policy string.
def alert_policy_path(cls, project, alert_policy):
"""Return a fully-qualified alert_policy string."""
return google.api_core.path_template.expand(
"projects/{project}/alertPolicies/{alert_policy}",
project=project,
alert_policy=alert_policy,
) |
Return a fully-qualified alert_policy_condition string.
def alert_policy_condition_path(cls, project, alert_policy, condition):
"""Return a fully-qualified alert_policy_condition string."""
return google.api_core.path_template.expand(
"projects/{project}/alertPolicies/{alert_policy}/conditions/{condition}",
project=project,
alert_policy=alert_policy,
condition=condition,
) |
Get multiple items from a Queue.
Gets at least one (blocking) and at most ``max_items`` items
(non-blocking) from a given Queue. Does not mark the items as done.
Args:
queue_ (~queue.Queue`): The Queue to get items from.
max_items (int): The maximum number of items to get. If ``None``, then
all available items in the queue are returned.
max_latency (float): The maximum number of seconds to wait for more
than one item from a queue. This number includes the time required
to retrieve the first item.
Returns:
Sequence[Any]: A sequence of items retrieved from the queue.
def _get_many(queue_, max_items=None, max_latency=0):
"""Get multiple items from a Queue.
Gets at least one (blocking) and at most ``max_items`` items
(non-blocking) from a given Queue. Does not mark the items as done.
Args:
queue_ (~queue.Queue`): The Queue to get items from.
max_items (int): The maximum number of items to get. If ``None``, then
all available items in the queue are returned.
max_latency (float): The maximum number of seconds to wait for more
than one item from a queue. This number includes the time required
to retrieve the first item.
Returns:
Sequence[Any]: A sequence of items retrieved from the queue.
"""
start = time.time()
# Always return at least one item.
items = [queue_.get()]
while max_items is None or len(items) < max_items:
try:
elapsed = time.time() - start
timeout = max(0, max_latency - elapsed)
items.append(queue_.get(timeout=timeout))
except queue.Empty:
break
return items |
Maps BigQuery error reasons to an exception.
The reasons and their matching HTTP status codes are documented on
the `troubleshooting errors`_ page.
.. _troubleshooting errors: https://cloud.google.com/bigquery\
/troubleshooting-errors
:type error_result: Mapping[str, str]
:param error_result: The error result from BigQuery.
:rtype google.cloud.exceptions.GoogleCloudError:
:returns: The mapped exception.
def _error_result_to_exception(error_result):
"""Maps BigQuery error reasons to an exception.
The reasons and their matching HTTP status codes are documented on
the `troubleshooting errors`_ page.
.. _troubleshooting errors: https://cloud.google.com/bigquery\
/troubleshooting-errors
:type error_result: Mapping[str, str]
:param error_result: The error result from BigQuery.
:rtype google.cloud.exceptions.GoogleCloudError:
:returns: The mapped exception.
"""
reason = error_result.get("reason")
status_code = _ERROR_REASON_TO_EXCEPTION.get(
reason, http_client.INTERNAL_SERVER_ERROR
)
return exceptions.from_http_status(
status_code, error_result.get("message", ""), errors=[error_result]
) |
Returns a job reference for an API resource representation.
def _from_api_repr(cls, resource):
"""Returns a job reference for an API resource representation."""
job_id = resource.get("jobId")
project = resource.get("projectId")
location = resource.get("location")
job_ref = cls(job_id, project, location)
return job_ref |
Datetime at which the job was created.
:rtype: ``datetime.datetime``, or ``NoneType``
:returns: the creation time (None until set from the server).
def created(self):
"""Datetime at which the job was created.
:rtype: ``datetime.datetime``, or ``NoneType``
:returns: the creation time (None until set from the server).
"""
statistics = self._properties.get("statistics")
if statistics is not None:
millis = statistics.get("creationTime")
if millis is not None:
return _helpers._datetime_from_microseconds(millis * 1000.0) |
Datetime at which the job was started.
:rtype: ``datetime.datetime``, or ``NoneType``
:returns: the start time (None until set from the server).
def started(self):
"""Datetime at which the job was started.
:rtype: ``datetime.datetime``, or ``NoneType``
:returns: the start time (None until set from the server).
"""
statistics = self._properties.get("statistics")
if statistics is not None:
millis = statistics.get("startTime")
if millis is not None:
return _helpers._datetime_from_microseconds(millis * 1000.0) |
Datetime at which the job finished.
:rtype: ``datetime.datetime``, or ``NoneType``
:returns: the end time (None until set from the server).
def ended(self):
"""Datetime at which the job finished.
:rtype: ``datetime.datetime``, or ``NoneType``
:returns: the end time (None until set from the server).
"""
statistics = self._properties.get("statistics")
if statistics is not None:
millis = statistics.get("endTime")
if millis is not None:
return _helpers._datetime_from_microseconds(millis * 1000.0) |
Helper for job-type specific statistics-based properties.
def _job_statistics(self):
"""Helper for job-type specific statistics-based properties."""
statistics = self._properties.get("statistics", {})
return statistics.get(self._JOB_TYPE, {}) |
Update properties from resource in body of ``api_response``
:type api_response: dict
:param api_response: response returned from an API call
def _set_properties(self, api_response):
"""Update properties from resource in body of ``api_response``
:type api_response: dict
:param api_response: response returned from an API call
"""
cleaned = api_response.copy()
self._scrub_local_properties(cleaned)
statistics = cleaned.get("statistics", {})
if "creationTime" in statistics:
statistics["creationTime"] = float(statistics["creationTime"])
if "startTime" in statistics:
statistics["startTime"] = float(statistics["startTime"])
if "endTime" in statistics:
statistics["endTime"] = float(statistics["endTime"])
self._properties.clear()
self._properties.update(cleaned)
self._copy_configuration_properties(cleaned.get("configuration", {}))
# For Future interface
self._set_future_result() |
Helper for :meth:`from_api_repr`
:type resource: dict
:param resource: resource for the job
:rtype: dict
:returns: tuple (string, dict), where the first element is the
job ID and the second contains job-specific configuration.
:raises: :class:`KeyError` if the resource has no identifier, or
is missing the appropriate configuration.
def _get_resource_config(cls, resource):
"""Helper for :meth:`from_api_repr`
:type resource: dict
:param resource: resource for the job
:rtype: dict
:returns: tuple (string, dict), where the first element is the
job ID and the second contains job-specific configuration.
:raises: :class:`KeyError` if the resource has no identifier, or
is missing the appropriate configuration.
"""
if "jobReference" not in resource or "jobId" not in resource["jobReference"]:
raise KeyError(
"Resource lacks required identity information: "
'["jobReference"]["jobId"]'
)
job_id = resource["jobReference"]["jobId"]
if (
"configuration" not in resource
or cls._JOB_TYPE not in resource["configuration"]
):
raise KeyError(
"Resource lacks required configuration: "
'["configuration"]["%s"]' % cls._JOB_TYPE
)
return job_id, resource["configuration"] |
API call: begin the job via a POST request
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:raises: :exc:`ValueError` if the job has already begin.
def _begin(self, client=None, retry=DEFAULT_RETRY):
"""API call: begin the job via a POST request
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/insert
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:raises: :exc:`ValueError` if the job has already begin.
"""
if self.state is not None:
raise ValueError("Job already begun.")
client = self._require_client(client)
path = "/projects/%s/jobs" % (self.project,)
# jobs.insert is idempotent because we ensure that every new
# job has an ID.
api_response = client._call_api(
retry, method="POST", path=path, data=self.to_api_repr()
)
self._set_properties(api_response) |
API call: test for the existence of the job via a GET request
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:rtype: bool
:returns: Boolean indicating existence of the job.
def exists(self, client=None, retry=DEFAULT_RETRY):
"""API call: test for the existence of the job via a GET request
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:rtype: bool
:returns: Boolean indicating existence of the job.
"""
client = self._require_client(client)
extra_params = {"fields": "id"}
if self.location:
extra_params["location"] = self.location
try:
client._call_api(
retry, method="GET", path=self.path, query_params=extra_params
)
except NotFound:
return False
else:
return True |
API call: refresh job properties via a GET request.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
def reload(self, client=None, retry=DEFAULT_RETRY):
"""API call: refresh job properties via a GET request.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/get
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
"""
client = self._require_client(client)
extra_params = {}
if self.location:
extra_params["location"] = self.location
api_response = client._call_api(
retry, method="GET", path=self.path, query_params=extra_params
)
self._set_properties(api_response) |
API call: cancel job via a POST request
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/cancel
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:rtype: bool
:returns: Boolean indicating that the cancel request was sent.
def cancel(self, client=None):
"""API call: cancel job via a POST request
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/cancel
:type client: :class:`~google.cloud.bigquery.client.Client` or
``NoneType``
:param client: the client to use. If not passed, falls back to the
``client`` stored on the current dataset.
:rtype: bool
:returns: Boolean indicating that the cancel request was sent.
"""
client = self._require_client(client)
extra_params = {}
if self.location:
extra_params["location"] = self.location
api_response = client._connection.api_request(
method="POST", path="%s/cancel" % (self.path,), query_params=extra_params
)
self._set_properties(api_response["job"])
# The Future interface requires that we return True if the *attempt*
# to cancel was successful.
return True |
Set the result or exception from the job if it is complete.
def _set_future_result(self):
"""Set the result or exception from the job if it is complete."""
# This must be done in a lock to prevent the polling thread
# and main thread from both executing the completion logic
# at the same time.
with self._completion_lock:
# If the operation isn't complete or if the result has already been
# set, do not call set_result/set_exception again.
# Note: self._result_set is set to True in set_result and
# set_exception, in case those methods are invoked directly.
if self.state != _DONE_STATE or self._result_set:
return
if self.error_result is not None:
exception = _error_result_to_exception(self.error_result)
self.set_exception(exception)
else:
self.set_result(self) |
Refresh the job and checks if it is complete.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:rtype: bool
:returns: True if the job is complete, False otherwise.
def done(self, retry=DEFAULT_RETRY):
"""Refresh the job and checks if it is complete.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:rtype: bool
:returns: True if the job is complete, False otherwise.
"""
# Do not refresh is the state is already done, as the job will not
# change once complete.
if self.state != _DONE_STATE:
self.reload(retry=retry)
return self.state == _DONE_STATE |
Start the job and wait for it to complete and get the result.
:type timeout: float
:param timeout:
How long (in seconds) to wait for job to complete before raising
a :class:`concurrent.futures.TimeoutError`.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:rtype: _AsyncJob
:returns: This instance.
:raises:
:class:`~google.cloud.exceptions.GoogleCloudError` if the job
failed or :class:`concurrent.futures.TimeoutError` if the job did
not complete in the given timeout.
def result(self, timeout=None, retry=DEFAULT_RETRY):
"""Start the job and wait for it to complete and get the result.
:type timeout: float
:param timeout:
How long (in seconds) to wait for job to complete before raising
a :class:`concurrent.futures.TimeoutError`.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the RPC.
:rtype: _AsyncJob
:returns: This instance.
:raises:
:class:`~google.cloud.exceptions.GoogleCloudError` if the job
failed or :class:`concurrent.futures.TimeoutError` if the job did
not complete in the given timeout.
"""
if self.state is None:
self._begin(retry=retry)
# TODO: modify PollingFuture so it can pass a retry argument to done().
return super(_AsyncJob, self).result(timeout=timeout) |
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'])
Arguments:
key (str):
Key for the value to get in the
``self._properties[self._job_type]`` dictionary.
default (object):
(Optional) Default value to return if the key is not found.
Defaults to :data:`None`.
Returns:
object: The value if present or the default.
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'])
Arguments:
key (str):
Key for the value to get in the
``self._properties[self._job_type]`` dictionary.
default (object):
(Optional) 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
) |
Set 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 set
those properties::
self._set_sub_prop('useLegacySql', False)
This is equivalent to using the ``_helper._set_sub_prop`` function::
_helper._set_sub_prop(
self._properties, ['query', 'useLegacySql'], False)
Arguments:
key (str):
Key to set in the ``self._properties[self._job_type]``
dictionary.
value (object): Value to set.
def _set_sub_prop(self, key, value):
"""Set 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 set
those properties::
self._set_sub_prop('useLegacySql', False)
This is equivalent to using the ``_helper._set_sub_prop`` function::
_helper._set_sub_prop(
self._properties, ['query', 'useLegacySql'], False)
Arguments:
key (str):
Key to set in the ``self._properties[self._job_type]``
dictionary.
value (object): Value to set.
"""
_helpers._set_sub_prop(self._properties, [self._job_type, key], value) |
Remove ``key`` from the ``self._properties[self._job_type]`` dict.
Most job properties are inside the dictionary related to the job type
(e.g. 'copy', 'extract', 'load', 'query'). Use this method to clear
those properties::
self._del_sub_prop('useLegacySql')
This is equivalent to using the ``_helper._del_sub_prop`` function::
_helper._del_sub_prop(
self._properties, ['query', 'useLegacySql'])
Arguments:
key (str):
Key to remove in the ``self._properties[self._job_type]``
dictionary.
def _del_sub_prop(self, key):
"""Remove ``key`` from the ``self._properties[self._job_type]`` dict.
Most job properties are inside the dictionary related to the job type
(e.g. 'copy', 'extract', 'load', 'query'). Use this method to clear
those properties::
self._del_sub_prop('useLegacySql')
This is equivalent to using the ``_helper._del_sub_prop`` function::
_helper._del_sub_prop(
self._properties, ['query', 'useLegacySql'])
Arguments:
key (str):
Key to remove in the ``self._properties[self._job_type]``
dictionary.
"""
_helpers._del_sub_prop(self._properties, [self._job_type, key]) |
Merge this job config with a default job config.
The keys in this object take precedence over the keys in the default
config. The merge is done at the top-level as well as for keys one
level below the job type.
Arguments:
default_job_config (google.cloud.bigquery.job._JobConfig):
The default job config that will be used to fill in self.
Returns:
google.cloud.bigquery.job._JobConfig A new (merged) job config.
def _fill_from_default(self, default_job_config):
"""Merge this job config with a default job config.
The keys in this object take precedence over the keys in the default
config. The merge is done at the top-level as well as for keys one
level below the job type.
Arguments:
default_job_config (google.cloud.bigquery.job._JobConfig):
The default job config that will be used to fill in self.
Returns:
google.cloud.bigquery.job._JobConfig A new (merged) job config.
"""
if self._job_type != default_job_config._job_type:
raise TypeError(
"attempted to merge two incompatible job types: "
+ repr(self._job_type)
+ ", "
+ repr(default_job_config._job_type)
)
new_job_config = self.__class__()
default_job_properties = copy.deepcopy(default_job_config._properties)
for key in self._properties:
if key != self._job_type:
default_job_properties[key] = self._properties[key]
default_job_properties[self._job_type].update(self._properties[self._job_type])
new_job_config._properties = default_job_properties
return new_job_config |
Factory: construct a job configuration given its API representation
:type resource: dict
:param resource:
An extract job configuration in the same representation as is
returned from the API.
:rtype: :class:`google.cloud.bigquery.job._JobConfig`
:returns: Configuration parsed from ``resource``.
def from_api_repr(cls, resource):
"""Factory: construct a job configuration given its API representation
:type resource: dict
:param resource:
An extract job configuration in the same representation as is
returned from the API.
:rtype: :class:`google.cloud.bigquery.job._JobConfig`
:returns: Configuration parsed from ``resource``.
"""
config = cls()
config._properties = copy.deepcopy(resource)
return config |
google.cloud.bigquery.table.EncryptionConfiguration: Custom
encryption configuration for the destination table.
Custom encryption configuration (e.g., Cloud KMS keys) or :data:`None`
if using default encryption.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.destinationEncryptionConfiguration
def destination_encryption_configuration(self):
"""google.cloud.bigquery.table.EncryptionConfiguration: Custom
encryption configuration for the destination table.
Custom encryption configuration (e.g., Cloud KMS keys) or :data:`None`
if using default encryption.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.destinationEncryptionConfiguration
"""
prop = self._get_sub_prop("destinationEncryptionConfiguration")
if prop is not None:
prop = EncryptionConfiguration.from_api_repr(prop)
return prop |
List[google.cloud.bigquery.schema.SchemaField]: Schema of the
destination table.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.schema
def schema(self):
"""List[google.cloud.bigquery.schema.SchemaField]: Schema of the
destination table.
See
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load.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] |
google.cloud.bigquery.table.TimePartitioning: Specifies time-based
partitioning for the destination table.
def time_partitioning(self):
"""google.cloud.bigquery.table.TimePartitioning: Specifies time-based
partitioning for the destination table.
"""
prop = self._get_sub_prop("timePartitioning")
if prop is not None:
prop = TimePartitioning.from_api_repr(prop)
return prop |
Generate a resource for :meth:`_begin`.
def to_api_repr(self):
"""Generate a resource for :meth:`_begin`."""
configuration = self._configuration.to_api_repr()
if self.source_uris is not None:
_helpers._set_sub_prop(
configuration, ["load", "sourceUris"], self.source_uris
)
_helpers._set_sub_prop(
configuration, ["load", "destinationTable"], self.destination.to_api_repr()
)
return {
"jobReference": self._properties["jobReference"],
"configuration": configuration,
} |
Factory: construct a job given its API representation
.. note:
This method assumes that the project found in the resource matches
the client's project.
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.LoadJob`
:returns: Job parsed from ``resource``.
def from_api_repr(cls, resource, client):
"""Factory: construct a job given its API representation
.. note:
This method assumes that the project found in the resource matches
the client's project.
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.LoadJob`
:returns: Job parsed from ``resource``.
"""
config_resource = resource.get("configuration", {})
config = LoadJobConfig.from_api_repr(config_resource)
# A load job requires a destination table.
dest_config = config_resource["load"]["destinationTable"]
ds_ref = DatasetReference(dest_config["projectId"], dest_config["datasetId"])
destination = TableReference(ds_ref, dest_config["tableId"])
# sourceUris will be absent if this is a file upload.
source_uris = _helpers._get_sub_prop(config_resource, ["load", "sourceUris"])
job_ref = _JobReference._from_api_repr(resource["jobReference"])
job = cls(job_ref, source_uris, destination, client, config)
job._set_properties(resource)
return job |
Generate a resource for :meth:`_begin`.
def to_api_repr(self):
"""Generate a resource for :meth:`_begin`."""
source_refs = [
{
"projectId": table.project,
"datasetId": table.dataset_id,
"tableId": table.table_id,
}
for table in self.sources
]
configuration = self._configuration.to_api_repr()
_helpers._set_sub_prop(configuration, ["copy", "sourceTables"], source_refs)
_helpers._set_sub_prop(
configuration,
["copy", "destinationTable"],
{
"projectId": self.destination.project,
"datasetId": self.destination.dataset_id,
"tableId": self.destination.table_id,
},
)
return {
"jobReference": self._properties["jobReference"],
"configuration": configuration,
} |
Factory: construct a job given its API representation
.. note:
This method assumes that the project found in the resource matches
the client's project.
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.CopyJob`
:returns: Job parsed from ``resource``.
def from_api_repr(cls, resource, client):
"""Factory: construct a job given its API representation
.. note:
This method assumes that the project found in the resource matches
the client's project.
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.CopyJob`
:returns: Job parsed from ``resource``.
"""
job_id, config_resource = cls._get_resource_config(resource)
config = CopyJobConfig.from_api_repr(config_resource)
# Copy required fields to the job.
copy_resource = config_resource["copy"]
destination = TableReference.from_api_repr(copy_resource["destinationTable"])
sources = []
source_configs = copy_resource.get("sourceTables")
if source_configs is None:
single = copy_resource.get("sourceTable")
if single is None:
raise KeyError("Resource missing 'sourceTables' / 'sourceTable'")
source_configs = [single]
for source_config in source_configs:
table_ref = TableReference.from_api_repr(source_config)
sources.append(table_ref)
job = cls(job_id, sources, destination, client=client, job_config=config)
job._set_properties(resource)
return job |
Return file counts from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.extract.destinationUriFileCounts
Returns:
a list of integer counts, each representing the number of files
per destination URI or URI pattern specified in the extract
configuration. These values will be in the same order as the URIs
specified in the 'destinationUris' field. Returns None if job is
not yet complete.
def destination_uri_file_counts(self):
"""Return file counts from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.extract.destinationUriFileCounts
Returns:
a list of integer counts, each representing the number of files
per destination URI or URI pattern specified in the extract
configuration. These values will be in the same order as the URIs
specified in the 'destinationUris' field. Returns None if job is
not yet complete.
"""
counts = self._job_statistics().get("destinationUriFileCounts")
if counts is not None:
return [int(count) for count in counts]
return None |
Generate a resource for :meth:`_begin`.
def to_api_repr(self):
"""Generate a resource for :meth:`_begin`."""
source_ref = {
"projectId": self.source.project,
"datasetId": self.source.dataset_id,
"tableId": self.source.table_id,
}
configuration = self._configuration.to_api_repr()
_helpers._set_sub_prop(configuration, ["extract", "sourceTable"], source_ref)
_helpers._set_sub_prop(
configuration, ["extract", "destinationUris"], self.destination_uris
)
return {
"jobReference": self._properties["jobReference"],
"configuration": configuration,
} |
Factory: construct a job given its API representation
.. note:
This method assumes that the project found in the resource matches
the client's project.
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.ExtractJob`
:returns: Job parsed from ``resource``.
def from_api_repr(cls, resource, client):
"""Factory: construct a job given its API representation
.. note:
This method assumes that the project found in the resource matches
the client's project.
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.ExtractJob`
:returns: Job parsed from ``resource``.
"""
job_id, config_resource = cls._get_resource_config(resource)
config = ExtractJobConfig.from_api_repr(config_resource)
source_config = _helpers._get_sub_prop(
config_resource, ["extract", "sourceTable"]
)
dataset = DatasetReference(
source_config["projectId"], source_config["datasetId"]
)
source = dataset.table(source_config["tableId"])
destination_uris = _helpers._get_sub_prop(
config_resource, ["extract", "destinationUris"]
)
job = cls(job_id, source, destination_uris, client=client, job_config=config)
job._set_properties(resource)
return job |
google.cloud.bigquery.dataset.DatasetReference: the default dataset
to use for unqualified table names in the query or :data:`None` if not
set.
The ``default_dataset`` setter accepts:
- a :class:`~google.cloud.bigquery.dataset.Dataset`, or
- a :class:`~google.cloud.bigquery.dataset.DatasetReference`, or
- a :class:`str` of the fully-qualified dataset ID in standard SQL
format. The value must included a project ID and dataset ID
separated by ``.``. For example: ``your-project.your_dataset``.
See
https://g.co/cloud/bigquery/docs/reference/v2/jobs#configuration.query.defaultDataset
def default_dataset(self):
"""google.cloud.bigquery.dataset.DatasetReference: the default dataset
to use for unqualified table names in the query or :data:`None` if not
set.
The ``default_dataset`` setter accepts:
- a :class:`~google.cloud.bigquery.dataset.Dataset`, or
- a :class:`~google.cloud.bigquery.dataset.DatasetReference`, or
- a :class:`str` of the fully-qualified dataset ID in standard SQL
format. The value must included a project ID and dataset ID
separated by ``.``. For example: ``your-project.your_dataset``.
See
https://g.co/cloud/bigquery/docs/reference/v2/jobs#configuration.query.defaultDataset
"""
prop = self._get_sub_prop("defaultDataset")
if prop is not None:
prop = DatasetReference.from_api_repr(prop)
return prop |
google.cloud.bigquery.table.TableReference: table where results are
written or :data:`None` if not set.
The ``destination`` setter accepts:
- a :class:`~google.cloud.bigquery.table.Table`, or
- a :class:`~google.cloud.bigquery.table.TableReference`, or
- a :class:`str` of the fully-qualified table ID in standard SQL
format. The value must included a project ID, dataset ID, and table
ID, each separated by ``.``. For example:
``your-project.your_dataset.your_table``.
See
https://g.co/cloud/bigquery/docs/reference/rest/v2/jobs#configuration.query.destinationTable
def destination(self):
"""google.cloud.bigquery.table.TableReference: table where results are
written or :data:`None` if not set.
The ``destination`` setter accepts:
- a :class:`~google.cloud.bigquery.table.Table`, or
- a :class:`~google.cloud.bigquery.table.TableReference`, or
- a :class:`str` of the fully-qualified table ID in standard SQL
format. The value must included a project ID, dataset ID, and table
ID, each separated by ``.``. For example:
``your-project.your_dataset.your_table``.
See
https://g.co/cloud/bigquery/docs/reference/rest/v2/jobs#configuration.query.destinationTable
"""
prop = self._get_sub_prop("destinationTable")
if prop is not None:
prop = TableReference.from_api_repr(prop)
return prop |
Dict[str, google.cloud.bigquery.external_config.ExternalConfig]:
Definitions for external tables or :data:`None` if not set.
See
https://g.co/cloud/bigquery/docs/reference/rest/v2/jobs#configuration.query.tableDefinitions
def table_definitions(self):
"""Dict[str, google.cloud.bigquery.external_config.ExternalConfig]:
Definitions for external tables or :data:`None` if not set.
See
https://g.co/cloud/bigquery/docs/reference/rest/v2/jobs#configuration.query.tableDefinitions
"""
prop = self._get_sub_prop("tableDefinitions")
if prop is not None:
prop = _from_api_repr_table_defs(prop)
return prop |
Build an API representation of the query job config.
Returns:
dict: A dictionary in the format used by the BigQuery API.
def to_api_repr(self):
"""Build an API representation of the query job config.
Returns:
dict: A dictionary in the format used by the BigQuery API.
"""
resource = copy.deepcopy(self._properties)
# Query parameters have an addition property associated with them
# to indicate if the query is using named or positional parameters.
query_parameters = resource["query"].get("queryParameters")
if query_parameters:
if query_parameters[0].get("name") is None:
resource["query"]["parameterMode"] = "POSITIONAL"
else:
resource["query"]["parameterMode"] = "NAMED"
return resource |
Generate a resource for :meth:`_begin`.
def to_api_repr(self):
"""Generate a resource for :meth:`_begin`."""
configuration = self._configuration.to_api_repr()
resource = {
"jobReference": self._properties["jobReference"],
"configuration": configuration,
}
configuration["query"]["query"] = self.query
return resource |
Factory: construct a job given its API representation
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.QueryJob`
:returns: Job parsed from ``resource``.
def from_api_repr(cls, resource, client):
"""Factory: construct a job given its API representation
:type resource: dict
:param resource: dataset job representation returned from the API
:type client: :class:`google.cloud.bigquery.client.Client`
:param client: Client which holds credentials and project
configuration for the dataset.
:rtype: :class:`google.cloud.bigquery.job.QueryJob`
:returns: Job parsed from ``resource``.
"""
job_id, config = cls._get_resource_config(resource)
query = config["query"]["query"]
job = cls(job_id, query, client=client)
job._set_properties(resource)
return job |
Return query plan from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.queryPlan
:rtype: list of :class:`QueryPlanEntry`
:returns: mappings describing the query plan, or an empty list
if the query has not yet completed.
def query_plan(self):
"""Return query plan from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.queryPlan
:rtype: list of :class:`QueryPlanEntry`
:returns: mappings describing the query plan, or an empty list
if the query has not yet completed.
"""
plan_entries = self._job_statistics().get("queryPlan", ())
return [QueryPlanEntry.from_api_repr(entry) for entry in plan_entries] |
List(TimelineEntry): Return the query execution timeline
from job statistics.
def timeline(self):
"""List(TimelineEntry): Return the query execution timeline
from job statistics.
"""
raw = self._job_statistics().get("timeline", ())
return [TimelineEntry.from_api_repr(entry) for entry in raw] |
Return total bytes processed from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.totalBytesProcessed
:rtype: int or None
:returns: total bytes processed by the job, or None if job is not
yet complete.
def total_bytes_processed(self):
"""Return total bytes processed from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.totalBytesProcessed
:rtype: int or None
:returns: total bytes processed by the job, or None if job is not
yet complete.
"""
result = self._job_statistics().get("totalBytesProcessed")
if result is not None:
result = int(result)
return result |
Return total bytes billed from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.totalBytesBilled
:rtype: int or None
:returns: total bytes processed by the job, or None if job is not
yet complete.
def total_bytes_billed(self):
"""Return total bytes billed from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.totalBytesBilled
:rtype: int or None
:returns: total bytes processed by the job, or None if job is not
yet complete.
"""
result = self._job_statistics().get("totalBytesBilled")
if result is not None:
result = int(result)
return result |
Optional[TableReference]: Return the DDL target table, present
for CREATE/DROP TABLE/VIEW queries.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.ddlTargetTable
def ddl_target_table(self):
"""Optional[TableReference]: Return the DDL target table, present
for CREATE/DROP TABLE/VIEW queries.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.ddlTargetTable
"""
prop = self._job_statistics().get("ddlTargetTable")
if prop is not None:
prop = TableReference.from_api_repr(prop)
return prop |
Return the number of DML rows affected by the job.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.numDmlAffectedRows
:rtype: int or None
:returns: number of DML rows affected by the job, or None if job is not
yet complete.
def num_dml_affected_rows(self):
"""Return the number of DML rows affected by the job.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.numDmlAffectedRows
:rtype: int or None
:returns: number of DML rows affected by the job, or None if job is not
yet complete.
"""
result = self._job_statistics().get("numDmlAffectedRows")
if result is not None:
result = int(result)
return result |
Return referenced tables from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.referencedTables
:rtype: list of dict
:returns: mappings describing the query plan, or an empty list
if the query has not yet completed.
def referenced_tables(self):
"""Return referenced tables from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.referencedTables
:rtype: list of dict
:returns: mappings describing the query plan, or an empty list
if the query has not yet completed.
"""
tables = []
datasets_by_project_name = {}
for table in self._job_statistics().get("referencedTables", ()):
t_project = table["projectId"]
ds_id = table["datasetId"]
t_dataset = datasets_by_project_name.get((t_project, ds_id))
if t_dataset is None:
t_dataset = DatasetReference(t_project, ds_id)
datasets_by_project_name[(t_project, ds_id)] = t_dataset
t_name = table["tableId"]
tables.append(t_dataset.table(t_name))
return tables |
Return undeclared query parameters from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.undeclaredQueryParameters
:rtype:
list of
:class:`~google.cloud.bigquery.ArrayQueryParameter`,
:class:`~google.cloud.bigquery.ScalarQueryParameter`, or
:class:`~google.cloud.bigquery.StructQueryParameter`
:returns: undeclared parameters, or an empty list if the query has
not yet completed.
def undeclared_query_parameters(self):
"""Return undeclared query parameters from job statistics, if present.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.undeclaredQueryParameters
:rtype:
list of
:class:`~google.cloud.bigquery.ArrayQueryParameter`,
:class:`~google.cloud.bigquery.ScalarQueryParameter`, or
:class:`~google.cloud.bigquery.StructQueryParameter`
:returns: undeclared parameters, or an empty list if the query has
not yet completed.
"""
parameters = []
undeclared = self._job_statistics().get("undeclaredQueryParameters", ())
for parameter in undeclared:
p_type = parameter["parameterType"]
if "arrayType" in p_type:
klass = ArrayQueryParameter
elif "structTypes" in p_type:
klass = StructQueryParameter
else:
klass = ScalarQueryParameter
parameters.append(klass.from_api_repr(parameter))
return parameters |
Return the estimated number of bytes processed by the query.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.estimatedBytesProcessed
:rtype: int or None
:returns: number of DML rows affected by the job, or None if job is not
yet complete.
def estimated_bytes_processed(self):
"""Return the estimated number of bytes processed by the query.
See:
https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#statistics.query.estimatedBytesProcessed
:rtype: int or None
:returns: number of DML rows affected by the job, or None if job is not
yet complete.
"""
result = self._job_statistics().get("estimatedBytesProcessed")
if result is not None:
result = int(result)
return result |
Refresh the job and checks if it is complete.
:rtype: bool
:returns: True if the job is complete, False otherwise.
def done(self, retry=DEFAULT_RETRY):
"""Refresh the job and checks if it is complete.
:rtype: bool
:returns: True if the job is complete, False otherwise.
"""
# Since the API to getQueryResults can hang up to the timeout value
# (default of 10 seconds), set the timeout parameter to ensure that
# the timeout from the futures API is respected. See:
# https://github.com/GoogleCloudPlatform/google-cloud-python/issues/4135
timeout_ms = None
if self._done_timeout is not None:
# Subtract a buffer for context switching, network latency, etc.
timeout = self._done_timeout - _TIMEOUT_BUFFER_SECS
timeout = max(min(timeout, 10), 0)
self._done_timeout -= timeout
self._done_timeout = max(0, self._done_timeout)
timeout_ms = int(timeout * 1000)
# Do not refresh is the state is already done, as the job will not
# change once complete.
if self.state != _DONE_STATE:
self._query_results = self._client._get_query_results(
self.job_id,
retry,
project=self.project,
timeout_ms=timeout_ms,
location=self.location,
)
# Only reload the job once we know the query is complete.
# This will ensure that fields such as the destination table are
# correctly populated.
if self._query_results.complete:
self.reload(retry=retry)
return self.state == _DONE_STATE |
Start the job and wait for it to complete and get the result.
:type timeout: float
:param timeout:
How long (in seconds) to wait for job to complete before raising
a :class:`concurrent.futures.TimeoutError`.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the call that retrieves rows.
:rtype: :class:`~google.cloud.bigquery.table.RowIterator`
:returns:
Iterator of row data :class:`~google.cloud.bigquery.table.Row`-s.
During each page, the iterator will have the ``total_rows``
attribute set, which counts the total number of rows **in the
result set** (this is distinct from the total number of rows in
the current page: ``iterator.page.num_items``).
:raises:
:class:`~google.cloud.exceptions.GoogleCloudError` if the job
failed or :class:`concurrent.futures.TimeoutError` if the job did
not complete in the given timeout.
def result(self, timeout=None, retry=DEFAULT_RETRY):
"""Start the job and wait for it to complete and get the result.
:type timeout: float
:param timeout:
How long (in seconds) to wait for job to complete before raising
a :class:`concurrent.futures.TimeoutError`.
:type retry: :class:`google.api_core.retry.Retry`
:param retry: (Optional) How to retry the call that retrieves rows.
:rtype: :class:`~google.cloud.bigquery.table.RowIterator`
:returns:
Iterator of row data :class:`~google.cloud.bigquery.table.Row`-s.
During each page, the iterator will have the ``total_rows``
attribute set, which counts the total number of rows **in the
result set** (this is distinct from the total number of rows in
the current page: ``iterator.page.num_items``).
:raises:
:class:`~google.cloud.exceptions.GoogleCloudError` if the job
failed or :class:`concurrent.futures.TimeoutError` if the job did
not complete in the given timeout.
"""
super(QueryJob, self).result(timeout=timeout)
# Return an iterator instead of returning the job.
if not self._query_results:
self._query_results = self._client._get_query_results(
self.job_id, retry, project=self.project, location=self.location
)
# If the query job is complete but there are no query results, this was
# special job, such as a DDL query. Return an empty result set to
# indicate success and avoid calling tabledata.list on a table which
# can't be read (such as a view table).
if self._query_results.total_rows is None:
return _EmptyRowIterator()
schema = self._query_results.schema
dest_table_ref = self.destination
dest_table = Table(dest_table_ref, schema=schema)
dest_table._properties["numRows"] = self._query_results.total_rows
return self._client.list_rows(dest_table, retry=retry) |
Return a pandas DataFrame from a QueryJob
Args:
bqstorage_client ( \
google.cloud.bigquery_storage_v1beta1.BigQueryStorageClient \
):
**Alpha Feature** Optional. A BigQuery Storage API client. If
supplied, use the faster BigQuery Storage API to fetch rows
from BigQuery. This API is a billable API.
This method requires the ``fastavro`` and
``google-cloud-bigquery-storage`` libraries.
Reading from a specific partition or snapshot is not
currently supported by this method.
**Caution**: There is a known issue reading small anonymous
query result tables with the BQ Storage API. Write your query
results to a destination table to work around this issue.
dtypes ( \
Map[str, Union[str, pandas.Series.dtype]] \
):
Optional. A dictionary of column names pandas ``dtype``s. The
provided ``dtype`` is used when constructing the series for
the column specified. Otherwise, the default pandas behavior
is used.
progress_bar_type (Optional[str]):
If set, use the `tqdm <https://tqdm.github.io/>`_ library to
display a progress bar while the data downloads. Install the
``tqdm`` package to use this feature.
See
:func:`~google.cloud.bigquery.table.RowIterator.to_dataframe`
for details.
..versionadded:: 1.11.0
Returns:
A :class:`~pandas.DataFrame` populated with row data and column
headers from the query results. The column headers are derived
from the destination table's schema.
Raises:
ValueError: If the `pandas` library cannot be imported.
def to_dataframe(self, bqstorage_client=None, dtypes=None, progress_bar_type=None):
"""Return a pandas DataFrame from a QueryJob
Args:
bqstorage_client ( \
google.cloud.bigquery_storage_v1beta1.BigQueryStorageClient \
):
**Alpha Feature** Optional. A BigQuery Storage API client. If
supplied, use the faster BigQuery Storage API to fetch rows
from BigQuery. This API is a billable API.
This method requires the ``fastavro`` and
``google-cloud-bigquery-storage`` libraries.
Reading from a specific partition or snapshot is not
currently supported by this method.
**Caution**: There is a known issue reading small anonymous
query result tables with the BQ Storage API. Write your query
results to a destination table to work around this issue.
dtypes ( \
Map[str, Union[str, pandas.Series.dtype]] \
):
Optional. A dictionary of column names pandas ``dtype``s. The
provided ``dtype`` is used when constructing the series for
the column specified. Otherwise, the default pandas behavior
is used.
progress_bar_type (Optional[str]):
If set, use the `tqdm <https://tqdm.github.io/>`_ library to
display a progress bar while the data downloads. Install the
``tqdm`` package to use this feature.
See
:func:`~google.cloud.bigquery.table.RowIterator.to_dataframe`
for details.
..versionadded:: 1.11.0
Returns:
A :class:`~pandas.DataFrame` populated with row data and column
headers from the query results. The column headers are derived
from the destination table's schema.
Raises:
ValueError: If the `pandas` library cannot be imported.
"""
return self.result().to_dataframe(
bqstorage_client=bqstorage_client,
dtypes=dtypes,
progress_bar_type=progress_bar_type,
) |
Factory: construct instance from the JSON repr.
:type resource: dict
:param resource: JSON representation of the entry
:rtype: :class:`QueryPlanEntryStep`
:return: new instance built from the resource
def from_api_repr(cls, resource):
"""Factory: construct instance from the JSON repr.
:type resource: dict
:param resource: JSON representation of the entry
:rtype: :class:`QueryPlanEntryStep`
:return: new instance built from the resource
"""
return cls(kind=resource.get("kind"), substeps=resource.get("substeps", ())) |
Union[Datetime, None]: Datetime when the stage started.
def start(self):
"""Union[Datetime, None]: Datetime when the stage started."""
if self._properties.get("startMs") is None:
return None
return _helpers._datetime_from_microseconds(
int(self._properties.get("startMs")) * 1000.0
) |
Union[Datetime, None]: Datetime when the stage ended.
def end(self):
"""Union[Datetime, None]: Datetime when the stage ended."""
if self._properties.get("endMs") is None:
return None
return _helpers._datetime_from_microseconds(
int(self._properties.get("endMs")) * 1000.0
) |
List(int): Entry IDs for stages that were inputs for this stage.
def input_stages(self):
"""List(int): Entry IDs for stages that were inputs for this stage."""
if self._properties.get("inputStages") is None:
return []
return [
_helpers._int_or_none(entry)
for entry in self._properties.get("inputStages")
] |
Construct an UnknownJob from the JSON representation.
Args:
resource (dict): JSON representation of a job.
client (google.cloud.bigquery.client.Client):
Client connected to BigQuery API.
Returns:
UnknownJob: Job corresponding to the resource.
def from_api_repr(cls, resource, client):
"""Construct an UnknownJob from the JSON representation.
Args:
resource (dict): JSON representation of a job.
client (google.cloud.bigquery.client.Client):
Client connected to BigQuery API.
Returns:
UnknownJob: Job corresponding to the resource.
"""
job_ref_properties = resource.get("jobReference", {"projectId": client.project})
job_ref = _JobReference._from_api_repr(job_ref_properties)
job = cls(job_ref, client)
# Populate the job reference with the project, even if it has been
# redacted, because we know it should equal that of the request.
resource["jobReference"] = job_ref_properties
job._properties = resource
return job |
Factory: construct a zone given its API representation
:type resource: dict
:param resource: zone resource representation returned from the API
:type client: :class:`google.cloud.dns.client.Client`
:param client: Client which holds credentials and project
configuration for the zone.
:rtype: :class:`google.cloud.dns.zone.ManagedZone`
:returns: Zone parsed from ``resource``.
def from_api_repr(cls, resource, client):
"""Factory: construct a zone given its API representation
:type resource: dict
:param resource: zone resource representation returned from the API
:type client: :class:`google.cloud.dns.client.Client`
:param client: Client which holds credentials and project
configuration for the zone.
:rtype: :class:`google.cloud.dns.zone.ManagedZone`
:returns: Zone parsed from ``resource``.
"""
name = resource.get("name")
dns_name = resource.get("dnsName")
if name is None or dns_name is None:
raise KeyError(
"Resource lacks required identity information:" '["name"]["dnsName"]'
)
zone = cls(name, dns_name, client=client)
zone._set_properties(resource)
return zone |
Update description of the zone.
:type value: str
:param value: (Optional) new description
:raises: ValueError for invalid value types.
def description(self, value):
"""Update description of the zone.
:type value: str
:param value: (Optional) new description
:raises: ValueError for invalid value types.
"""
if not isinstance(value, six.string_types) and value is not None:
raise ValueError("Pass a string, or None")
self._properties["description"] = value |
Update named set of DNS name servers.
:type value: str
:param value: (Optional) new title
:raises: ValueError for invalid value types.
def name_server_set(self, value):
"""Update named set of DNS name servers.
:type value: str
:param value: (Optional) new title
:raises: ValueError for invalid value types.
"""
if not isinstance(value, six.string_types) and value is not None:
raise ValueError("Pass a string, or None")
self._properties["nameServerSet"] = value |
Construct a resource record set bound to this zone.
:type name: str
:param name: Name of the record set.
:type record_type: str
:param record_type: RR type
:type ttl: int
:param ttl: TTL for the RR, in seconds
:type rrdatas: list of string
:param rrdatas: resource data for the RR
:rtype: :class:`google.cloud.dns.resource_record_set.ResourceRecordSet`
:returns: a new ``ResourceRecordSet`` instance
def resource_record_set(self, name, record_type, ttl, rrdatas):
"""Construct a resource record set bound to this zone.
:type name: str
:param name: Name of the record set.
:type record_type: str
:param record_type: RR type
:type ttl: int
:param ttl: TTL for the RR, in seconds
:type rrdatas: list of string
:param rrdatas: resource data for the RR
:rtype: :class:`google.cloud.dns.resource_record_set.ResourceRecordSet`
:returns: a new ``ResourceRecordSet`` instance
"""
return ResourceRecordSet(name, record_type, ttl, rrdatas, zone=self) |
Update properties from resource in body of ``api_response``
:type api_response: dict
:param api_response: response returned from an API call
def _set_properties(self, api_response):
"""Update properties from resource in body of ``api_response``
:type api_response: dict
:param api_response: response returned from an API call
"""
self._properties.clear()
cleaned = api_response.copy()
self.dns_name = cleaned.pop("dnsName", None)
if "creationTime" in cleaned:
cleaned["creationTime"] = _rfc3339_to_datetime(cleaned["creationTime"])
self._properties.update(cleaned) |
Generate a resource for ``create`` or ``update``.
def _build_resource(self):
"""Generate a resource for ``create`` or ``update``."""
resource = {"name": self.name}
if self.dns_name is not None:
resource["dnsName"] = self.dns_name
if self.description is not None:
resource["description"] = self.description
if self.name_server_set is not None:
resource["nameServerSet"] = self.name_server_set
return resource |
API call: create the zone via a PUT request
See
https://cloud.google.com/dns/api/v1/managedZones/create
:type client: :class:`google.cloud.dns.client.Client`
:param client:
(Optional) the client to use. If not passed, falls back to the
``client`` stored on the current zone.
def create(self, client=None):
"""API call: create the zone via a PUT request
See
https://cloud.google.com/dns/api/v1/managedZones/create
:type client: :class:`google.cloud.dns.client.Client`
:param client:
(Optional) the client to use. If not passed, falls back to the
``client`` stored on the current zone.
"""
client = self._require_client(client)
path = "/projects/%s/managedZones" % (self.project,)
api_response = client._connection.api_request(
method="POST", path=path, data=self._build_resource()
)
self._set_properties(api_response) |
API call: delete the zone via a DELETE request
See
https://cloud.google.com/dns/api/v1/managedZones/delete
:type client: :class:`google.cloud.dns.client.Client`
:param client:
(Optional) the client to use. If not passed, falls back to the
``client`` stored on the current zone.
def delete(self, client=None):
"""API call: delete the zone via a DELETE request
See
https://cloud.google.com/dns/api/v1/managedZones/delete
:type client: :class:`google.cloud.dns.client.Client`
:param client:
(Optional) the client to use. If not passed, falls back to the
``client`` stored on the current zone.
"""
client = self._require_client(client)
client._connection.api_request(method="DELETE", path=self.path) |
List resource record sets for this zone.
See
https://cloud.google.com/dns/api/v1/resourceRecordSets/list
:type max_results: int
:param max_results: Optional. The maximum number of resource record
sets to return. Defaults to a sensible value
set by the API.
:type page_token: str
:param page_token: Optional. If present, return the next batch of
resource record sets, using the value, which must correspond to
the ``nextPageToken`` value returned in the previous response.
Deprecated: use the ``pages`` property of the returned iterator
instead of manually passing the token.
:type client: :class:`google.cloud.dns.client.Client`
:param client:
(Optional) the client to use. If not passed, falls back to the
``client`` stored on the current zone.
:rtype: :class:`~google.api_core.page_iterator.Iterator`
:returns: Iterator of :class:`~.resource_record_set.ResourceRecordSet`
belonging to this zone.
def list_resource_record_sets(self, max_results=None, page_token=None, client=None):
"""List resource record sets for this zone.
See
https://cloud.google.com/dns/api/v1/resourceRecordSets/list
:type max_results: int
:param max_results: Optional. The maximum number of resource record
sets to return. Defaults to a sensible value
set by the API.
:type page_token: str
:param page_token: Optional. If present, return the next batch of
resource record sets, using the value, which must correspond to
the ``nextPageToken`` value returned in the previous response.
Deprecated: use the ``pages`` property of the returned iterator
instead of manually passing the token.
:type client: :class:`google.cloud.dns.client.Client`
:param client:
(Optional) the client to use. If not passed, falls back to the
``client`` stored on the current zone.
:rtype: :class:`~google.api_core.page_iterator.Iterator`
:returns: Iterator of :class:`~.resource_record_set.ResourceRecordSet`
belonging to this zone.
"""
client = self._require_client(client)
path = "/projects/%s/managedZones/%s/rrsets" % (self.project, self.name)
iterator = page_iterator.HTTPIterator(
client=client,
api_request=client._connection.api_request,
path=path,
item_to_value=_item_to_resource_record_set,
items_key="rrsets",
page_token=page_token,
max_results=max_results,
)
iterator.zone = self
return iterator |
Run image detection and annotation for an image.
Example:
>>> from google.cloud.vision_v1 import ImageAnnotatorClient
>>> client = ImageAnnotatorClient()
>>> request = {
... 'image': {
... 'source': {'image_uri': 'https://foo.com/image.jpg'},
... },
... }
>>> response = client.annotate_image(request)
Args:
request (:class:`~.vision_v1.types.AnnotateImageRequest`)
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
Returns:
:class:`~.vision_v1.types.AnnotateImageResponse` The API response.
def annotate_image(self, request, retry=None, timeout=None):
"""Run image detection and annotation for an image.
Example:
>>> from google.cloud.vision_v1 import ImageAnnotatorClient
>>> client = ImageAnnotatorClient()
>>> request = {
... 'image': {
... 'source': {'image_uri': 'https://foo.com/image.jpg'},
... },
... }
>>> response = client.annotate_image(request)
Args:
request (:class:`~.vision_v1.types.AnnotateImageRequest`)
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
Returns:
:class:`~.vision_v1.types.AnnotateImageResponse` The API response.
"""
# If the image is a file handler, set the content.
image = protobuf.get(request, "image")
if hasattr(image, "read"):
img_bytes = image.read()
protobuf.set(request, "image", {})
protobuf.set(request, "image.content", img_bytes)
image = protobuf.get(request, "image")
# If a filename is provided, read the file.
filename = protobuf.get(image, "source.filename", default=None)
if filename:
with io.open(filename, "rb") as img_file:
protobuf.set(request, "image.content", img_file.read())
protobuf.set(request, "image.source", None)
# This method allows features not to be specified, and you get all
# of them.
protobuf.setdefault(request, "features", self._get_all_features())
r = self.batch_annotate_images([request], retry=retry, timeout=timeout)
return r.responses[0] |
Sample ID: go/samples-tracker/1534
def delete_model(client, model_id):
"""Sample ID: go/samples-tracker/1534"""
# [START bigquery_delete_model]
from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()
# TODO(developer): Set model_id to the ID of the model to fetch.
# model_id = 'your-project.your_dataset.your_model'
client.delete_model(model_id)
print("Deleted model '{}'.".format(model_id)) |
Sample ID: go/samples-tracker/1512
def list_models(client, dataset_id):
"""Sample ID: go/samples-tracker/1512"""
# [START bigquery_list_models]
from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
# client = bigquery.Client()
# TODO(developer): Set dataset_id to the ID of the dataset that contains
# the models you are listing.
# dataset_id = 'your-project.your_dataset'
models = client.list_models(dataset_id)
print("Models contained in '{}':".format(dataset_id))
for model in models:
full_model_id = "{}.{}.{}".format(
model.project, model.dataset_id, model.model_id
)
friendly_name = model.friendly_name
print("{}: friendly_name='{}'".format(full_model_id, friendly_name)) |
Return a fully-qualified job string.
def job_path(cls, project, jobs):
"""Return a fully-qualified job string."""
return google.api_core.path_template.expand(
"projects/{project}/jobs/{jobs}", project=project, jobs=jobs
) |
Creates a new job.
Typically, the job becomes searchable within 10 seconds, but it may take
up to 5 minutes.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> # TODO: Initialize `job`:
>>> job = {}
>>>
>>> response = client.create_job(parent, job)
Args:
parent (str): Required.
The resource name of the project under which the job is created.
The format is "projects/{project\_id}", for example,
"projects/api-test-project".
job (Union[dict, ~google.cloud.talent_v4beta1.types.Job]): Required.
The Job to be created.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.Job`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Job` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def create_job(
self,
parent,
job,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Creates a new job.
Typically, the job becomes searchable within 10 seconds, but it may take
up to 5 minutes.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> # TODO: Initialize `job`:
>>> job = {}
>>>
>>> response = client.create_job(parent, job)
Args:
parent (str): Required.
The resource name of the project under which the job is created.
The format is "projects/{project\_id}", for example,
"projects/api-test-project".
job (Union[dict, ~google.cloud.talent_v4beta1.types.Job]): Required.
The Job to be created.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.Job`
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Job` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "create_job" not in self._inner_api_calls:
self._inner_api_calls[
"create_job"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.create_job,
default_retry=self._method_configs["CreateJob"].retry,
default_timeout=self._method_configs["CreateJob"].timeout,
client_info=self._client_info,
)
request = job_service_pb2.CreateJobRequest(parent=parent, job=job)
return self._inner_api_calls["create_job"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Retrieves the specified job, whose status is OPEN or recently EXPIRED
within the last 90 days.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> name = client.job_path('[PROJECT]', '[JOBS]')
>>>
>>> response = client.get_job(name)
Args:
name (str): Required.
The resource name of the job to retrieve.
The format is "projects/{project\_id}/jobs/{job\_id}", for example,
"projects/api-test-project/jobs/1234".
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Job` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def get_job(
self,
name,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Retrieves the specified job, whose status is OPEN or recently EXPIRED
within the last 90 days.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> name = client.job_path('[PROJECT]', '[JOBS]')
>>>
>>> response = client.get_job(name)
Args:
name (str): Required.
The resource name of the job to retrieve.
The format is "projects/{project\_id}/jobs/{job\_id}", for example,
"projects/api-test-project/jobs/1234".
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.cloud.talent_v4beta1.types.Job` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "get_job" not in self._inner_api_calls:
self._inner_api_calls[
"get_job"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.get_job,
default_retry=self._method_configs["GetJob"].retry,
default_timeout=self._method_configs["GetJob"].timeout,
client_info=self._client_info,
)
request = job_service_pb2.GetJobRequest(name=name)
return self._inner_api_calls["get_job"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Deletes a list of ``Job``\ s by filter.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> # TODO: Initialize `filter_`:
>>> filter_ = ''
>>>
>>> client.batch_delete_jobs(parent, filter_)
Args:
parent (str): Required.
The resource name of the project under which the job is created.
The format is "projects/{project\_id}", for example,
"projects/api-test-project".
filter_ (str): Required.
The filter string specifies the jobs to be deleted.
Supported operator: =, AND
The fields eligible for filtering are:
- ``companyName`` (Required)
- ``requisitionId`` (Required)
Sample Query: companyName = "projects/api-test-project/companies/123"
AND requisitionId = "req-1"
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def batch_delete_jobs(
self,
parent,
filter_,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Deletes a list of ``Job``\ s by filter.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> # TODO: Initialize `filter_`:
>>> filter_ = ''
>>>
>>> client.batch_delete_jobs(parent, filter_)
Args:
parent (str): Required.
The resource name of the project under which the job is created.
The format is "projects/{project\_id}", for example,
"projects/api-test-project".
filter_ (str): Required.
The filter string specifies the jobs to be deleted.
Supported operator: =, AND
The fields eligible for filtering are:
- ``companyName`` (Required)
- ``requisitionId`` (Required)
Sample Query: companyName = "projects/api-test-project/companies/123"
AND requisitionId = "req-1"
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "batch_delete_jobs" not in self._inner_api_calls:
self._inner_api_calls[
"batch_delete_jobs"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.batch_delete_jobs,
default_retry=self._method_configs["BatchDeleteJobs"].retry,
default_timeout=self._method_configs["BatchDeleteJobs"].timeout,
client_info=self._client_info,
)
request = job_service_pb2.BatchDeleteJobsRequest(parent=parent, filter=filter_)
self._inner_api_calls["batch_delete_jobs"](
request, retry=retry, timeout=timeout, metadata=metadata
) |
Searches for jobs using the provided ``SearchJobsRequest``.
This call constrains the ``visibility`` of jobs present in the database,
and only returns jobs that the caller has permission to search against.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> # TODO: Initialize `request_metadata`:
>>> request_metadata = {}
>>>
>>> # Iterate over all results
>>> for element in client.search_jobs(parent, request_metadata):
... # process element
... pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.search_jobs(parent, request_metadata).pages:
... for element in page:
... # process element
... pass
Args:
parent (str): Required.
The resource name of the project to search within.
The format is "projects/{project\_id}", for example,
"projects/api-test-project".
request_metadata (Union[dict, ~google.cloud.talent_v4beta1.types.RequestMetadata]): Required.
The meta information collected about the job searcher, used to improve
the search quality of the service.. The identifiers, (such as
``user_id``) are provided by users, and must be unique and consistent.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.RequestMetadata`
search_mode (~google.cloud.talent_v4beta1.types.SearchMode): Optional.
Mode of a search.
Defaults to ``SearchMode.JOB_SEARCH``.
job_query (Union[dict, ~google.cloud.talent_v4beta1.types.JobQuery]): Optional.
Query used to search against jobs, such as keyword, location filters, etc.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.JobQuery`
enable_broadening (bool): Optional.
Controls whether to broaden the search when it produces sparse results.
Broadened queries append results to the end of the matching results
list.
Defaults to false.
require_precise_result_size (bool): Optional.
Controls if the search job request requires the return of a precise
count of the first 300 results. Setting this to ``true`` ensures
consistency in the number of results per page. Best practice is to set
this value to true if a client allows users to jump directly to a
non-sequential search results page.
Enabling this flag may adversely impact performance.
Defaults to false.
histogram_queries (list[Union[dict, ~google.cloud.talent_v4beta1.types.HistogramQuery]]): Optional.
An expression specifies a histogram request against matching jobs.
Expression syntax is an aggregation function call with histogram facets
and other options.
Available aggregation function calls are: \*
``count(string_histogram_facet)``: Count the number of matching
entities, for each distinct attribute value. \*
``count(numeric_histogram_facet, list of buckets)``: Count the number of
matching entities within each bucket.
Data types:
- Histogram facet: facet names with format [a-zA-Z][a-zA-Z0-9\_]+.
- String: string like "any string with backslash escape for quote(")."
- Number: whole number and floating point number like 10, -1 and -0.01.
- List: list of elements with comma(,) separator surrounded by square
brackets, for example, [1, 2, 3] and ["one", "two", "three"].
Built-in constants:
- MIN (minimum number similar to java Double.MIN\_VALUE)
- MAX (maximum number similar to java Double.MAX\_VALUE)
Built-in functions:
- bucket(start, end[, label]): bucket built-in function creates a
bucket with range of \`start, end). Note that the end is exclusive,
for example, bucket(1, MAX, "positive number") or bucket(1, 10).
Job histogram facets:
- company\_id: histogram by [Job.distributor\_company\_id\`.
- company\_display\_name: histogram by ``Job.company_display_name``.
- employment\_type: histogram by ``Job.employment_types``, for example,
"FULL\_TIME", "PART\_TIME".
- company\_size: histogram by ``CompanySize``, for example, "SMALL",
"MEDIUM", "BIG".
- publish\_time\_in\_month: histogram by the ``Job.publish_time`` in
months. Must specify list of numeric buckets in spec.
- publish\_time\_in\_year: histogram by the ``Job.publish_time`` in
years. Must specify list of numeric buckets in spec.
- degree\_type: histogram by the ``Job.degree_type``, for example,
"Bachelors", "Masters".
- job\_level: histogram by the ``Job.job_level``, for example, "Entry
Level".
- country: histogram by the country code of jobs, for example, "US",
"FR".
- admin1: histogram by the admin1 code of jobs, which is a global
placeholder referring to the state, province, or the particular term
a country uses to define the geographic structure below the country
level, for example, "CA", "IL".
- city: histogram by a combination of the "city name, admin1 code". For
example, "Mountain View, CA", "New York, NY".
- admin1\_country: histogram by a combination of the "admin1 code,
country", for example, "CA, US", "IL, US".
- city\_coordinate: histogram by the city center's GPS coordinates
(latitude and longitude), for example, 37.4038522,-122.0987765. Since
the coordinates of a city center can change, customers may need to
refresh them periodically.
- locale: histogram by the ``Job.language_code``, for example, "en-US",
"fr-FR".
- language: histogram by the language subtag of the
``Job.language_code``, for example, "en", "fr".
- category: histogram by the ``JobCategory``, for example,
"COMPUTER\_AND\_IT", "HEALTHCARE".
- base\_compensation\_unit: histogram by the ``CompensationUnit`` of
base salary, for example, "WEEKLY", "MONTHLY".
- base\_compensation: histogram by the base salary. Must specify list
of numeric buckets to group results by.
- annualized\_base\_compensation: histogram by the base annualized
salary. Must specify list of numeric buckets to group results by.
- annualized\_total\_compensation: histogram by the total annualized
salary. Must specify list of numeric buckets to group results by.
- string\_custom\_attribute: histogram by string
``Job.custom_attributes``. Values can be accessed via square bracket
notations like string\_custom\_attribute["key1"].
- numeric\_custom\_attribute: histogram by numeric
``Job.custom_attributes``. Values can be accessed via square bracket
notations like numeric\_custom\_attribute["key1"]. Must specify list
of numeric buckets to group results by.
Example expressions: \* count(admin1) \* count(base\_compensation,
[bucket(1000, 10000), bucket(10000, 100000), bucket(100000, MAX)]) \*
count(string\_custom\_attribute["some-string-custom-attribute"]) \*
count(numeric\_custom\_attribute["some-numeric-custom-attribute"],
[bucket(MIN, 0, "negative"), bucket(0, MAX, "non-negative"])
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.HistogramQuery`
job_view (~google.cloud.talent_v4beta1.types.JobView): Optional.
The desired job attributes returned for jobs in the search response.
Defaults to ``JobView.SMALL`` if no value is specified.
offset (int): Optional.
An integer that specifies the current offset (that is, starting result
location, amongst the jobs deemed by the API as relevant) in search
results. This field is only considered if ``page_token`` is unset.
For example, 0 means to return results starting from the first matching
job, and 10 means to return from the 11th job. This can be used for
pagination, (for example, pageSize = 10 and offset = 10 means to return
from the second page).
page_size (int): The maximum number of resources contained in the
underlying API response. If page streaming is performed per-
resource, this parameter does not affect the return value. If page
streaming is performed per-page, this determines the maximum number
of resources in a page.
order_by (str): Optional.
The criteria determining how search results are sorted. Default is
"relevance desc".
Supported options are:
- "relevance desc": By relevance descending, as determined by the API
algorithms. Relevance thresholding of query results is only available
with this ordering.
- "posting``_``\ publish\ ``_``\ time desc": By
``Job.posting_publish_time`` descending.
- "posting``_``\ update\ ``_``\ time desc": By
``Job.posting_update_time`` descending.
- "title": By ``Job.title`` ascending.
- "title desc": By ``Job.title`` descending.
- "annualized``_``\ base\ ``_``\ compensation": By job's
``CompensationInfo.annualized_base_compensation_range`` ascending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "annualized``_``\ base\ ``_``\ compensation desc": By job's
``CompensationInfo.annualized_base_compensation_range`` descending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "annualized``_``\ total\ ``_``\ compensation": By job's
``CompensationInfo.annualized_total_compensation_range`` ascending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "annualized``_``\ total\ ``_``\ compensation desc": By job's
``CompensationInfo.annualized_total_compensation_range`` descending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "custom``_``\ ranking desc": By the relevance score adjusted to the
``SearchJobsRequest.custom_ranking_info.ranking_expression`` with
weight factor assigned by
``SearchJobsRequest.custom_ranking_info.importance_level`` in
descending order.
- "location``_``\ distance": By the distance between the location on
jobs and locations specified in the
``SearchJobsRequest.job_query.location_filters``. When this order is
selected, the ``SearchJobsRequest.job_query.location_filters`` must
not be empty. When a job has multiple locations, the location closest
to one of the locations specified in the location filter will be used
to calculate location distance. Distance is calculated by the
distance between two lat/long coordinates, with a precision of 10e-4
degrees (11.3 meters). Jobs that don't have locations specified will
be ranked below jobs having locations. Diversification strategy is
still applied unless explicitly disabled in
``SearchJobsRequest.diversification_level``.
diversification_level (~google.cloud.talent_v4beta1.types.DiversificationLevel): Optional.
Controls whether highly similar jobs are returned next to each other in
the search results. Jobs are identified as highly similar based on their
titles, job categories, and locations. Highly similar results are
clustered so that only one representative job of the cluster is
displayed to the job seeker higher up in the results, with the other
jobs being displayed lower down in the results.
Defaults to ``DiversificationLevel.SIMPLE`` if no value is specified.
custom_ranking_info (Union[dict, ~google.cloud.talent_v4beta1.types.CustomRankingInfo]): Optional.
Controls over how job documents get ranked on top of existing relevance
score (determined by API algorithm).
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.CustomRankingInfo`
disable_keyword_match (bool): Optional.
Controls whether to disable exact keyword match on ``Job.job_title``,
``Job.description``, ``Job.company_display_name``, [Job.locations][0],
``Job.qualifications``. When disable keyword match is turned off, a
keyword match returns jobs that do not match given category filters when
there are matching keywords. For example, for the query "program
manager," a result is returned even if the job posting has the title
"software developer," which doesn't fall into "program manager"
ontology, but does have "program manager" appearing in its description.
For queries like "cloud" that don't contain title or location specific
ontology, jobs with "cloud" keyword matches are returned regardless of
this flag's value.
Please use ``Company.keyword_searchable_custom_fields`` or
``Company.keyword_searchable_custom_attributes`` if company specific
globally matched custom field/attribute string values is needed.
Enabling keyword match improves recall of subsequent search requests.
Defaults to false.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.talent_v4beta1.types.MatchingJob` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
def search_jobs(
self,
parent,
request_metadata,
search_mode=None,
job_query=None,
enable_broadening=None,
require_precise_result_size=None,
histogram_queries=None,
job_view=None,
offset=None,
page_size=None,
order_by=None,
diversification_level=None,
custom_ranking_info=None,
disable_keyword_match=None,
retry=google.api_core.gapic_v1.method.DEFAULT,
timeout=google.api_core.gapic_v1.method.DEFAULT,
metadata=None,
):
"""
Searches for jobs using the provided ``SearchJobsRequest``.
This call constrains the ``visibility`` of jobs present in the database,
and only returns jobs that the caller has permission to search against.
Example:
>>> from google.cloud import talent_v4beta1
>>>
>>> client = talent_v4beta1.JobServiceClient()
>>>
>>> parent = client.project_path('[PROJECT]')
>>>
>>> # TODO: Initialize `request_metadata`:
>>> request_metadata = {}
>>>
>>> # Iterate over all results
>>> for element in client.search_jobs(parent, request_metadata):
... # process element
... pass
>>>
>>>
>>> # Alternatively:
>>>
>>> # Iterate over results one page at a time
>>> for page in client.search_jobs(parent, request_metadata).pages:
... for element in page:
... # process element
... pass
Args:
parent (str): Required.
The resource name of the project to search within.
The format is "projects/{project\_id}", for example,
"projects/api-test-project".
request_metadata (Union[dict, ~google.cloud.talent_v4beta1.types.RequestMetadata]): Required.
The meta information collected about the job searcher, used to improve
the search quality of the service.. The identifiers, (such as
``user_id``) are provided by users, and must be unique and consistent.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.RequestMetadata`
search_mode (~google.cloud.talent_v4beta1.types.SearchMode): Optional.
Mode of a search.
Defaults to ``SearchMode.JOB_SEARCH``.
job_query (Union[dict, ~google.cloud.talent_v4beta1.types.JobQuery]): Optional.
Query used to search against jobs, such as keyword, location filters, etc.
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.JobQuery`
enable_broadening (bool): Optional.
Controls whether to broaden the search when it produces sparse results.
Broadened queries append results to the end of the matching results
list.
Defaults to false.
require_precise_result_size (bool): Optional.
Controls if the search job request requires the return of a precise
count of the first 300 results. Setting this to ``true`` ensures
consistency in the number of results per page. Best practice is to set
this value to true if a client allows users to jump directly to a
non-sequential search results page.
Enabling this flag may adversely impact performance.
Defaults to false.
histogram_queries (list[Union[dict, ~google.cloud.talent_v4beta1.types.HistogramQuery]]): Optional.
An expression specifies a histogram request against matching jobs.
Expression syntax is an aggregation function call with histogram facets
and other options.
Available aggregation function calls are: \*
``count(string_histogram_facet)``: Count the number of matching
entities, for each distinct attribute value. \*
``count(numeric_histogram_facet, list of buckets)``: Count the number of
matching entities within each bucket.
Data types:
- Histogram facet: facet names with format [a-zA-Z][a-zA-Z0-9\_]+.
- String: string like "any string with backslash escape for quote(")."
- Number: whole number and floating point number like 10, -1 and -0.01.
- List: list of elements with comma(,) separator surrounded by square
brackets, for example, [1, 2, 3] and ["one", "two", "three"].
Built-in constants:
- MIN (minimum number similar to java Double.MIN\_VALUE)
- MAX (maximum number similar to java Double.MAX\_VALUE)
Built-in functions:
- bucket(start, end[, label]): bucket built-in function creates a
bucket with range of \`start, end). Note that the end is exclusive,
for example, bucket(1, MAX, "positive number") or bucket(1, 10).
Job histogram facets:
- company\_id: histogram by [Job.distributor\_company\_id\`.
- company\_display\_name: histogram by ``Job.company_display_name``.
- employment\_type: histogram by ``Job.employment_types``, for example,
"FULL\_TIME", "PART\_TIME".
- company\_size: histogram by ``CompanySize``, for example, "SMALL",
"MEDIUM", "BIG".
- publish\_time\_in\_month: histogram by the ``Job.publish_time`` in
months. Must specify list of numeric buckets in spec.
- publish\_time\_in\_year: histogram by the ``Job.publish_time`` in
years. Must specify list of numeric buckets in spec.
- degree\_type: histogram by the ``Job.degree_type``, for example,
"Bachelors", "Masters".
- job\_level: histogram by the ``Job.job_level``, for example, "Entry
Level".
- country: histogram by the country code of jobs, for example, "US",
"FR".
- admin1: histogram by the admin1 code of jobs, which is a global
placeholder referring to the state, province, or the particular term
a country uses to define the geographic structure below the country
level, for example, "CA", "IL".
- city: histogram by a combination of the "city name, admin1 code". For
example, "Mountain View, CA", "New York, NY".
- admin1\_country: histogram by a combination of the "admin1 code,
country", for example, "CA, US", "IL, US".
- city\_coordinate: histogram by the city center's GPS coordinates
(latitude and longitude), for example, 37.4038522,-122.0987765. Since
the coordinates of a city center can change, customers may need to
refresh them periodically.
- locale: histogram by the ``Job.language_code``, for example, "en-US",
"fr-FR".
- language: histogram by the language subtag of the
``Job.language_code``, for example, "en", "fr".
- category: histogram by the ``JobCategory``, for example,
"COMPUTER\_AND\_IT", "HEALTHCARE".
- base\_compensation\_unit: histogram by the ``CompensationUnit`` of
base salary, for example, "WEEKLY", "MONTHLY".
- base\_compensation: histogram by the base salary. Must specify list
of numeric buckets to group results by.
- annualized\_base\_compensation: histogram by the base annualized
salary. Must specify list of numeric buckets to group results by.
- annualized\_total\_compensation: histogram by the total annualized
salary. Must specify list of numeric buckets to group results by.
- string\_custom\_attribute: histogram by string
``Job.custom_attributes``. Values can be accessed via square bracket
notations like string\_custom\_attribute["key1"].
- numeric\_custom\_attribute: histogram by numeric
``Job.custom_attributes``. Values can be accessed via square bracket
notations like numeric\_custom\_attribute["key1"]. Must specify list
of numeric buckets to group results by.
Example expressions: \* count(admin1) \* count(base\_compensation,
[bucket(1000, 10000), bucket(10000, 100000), bucket(100000, MAX)]) \*
count(string\_custom\_attribute["some-string-custom-attribute"]) \*
count(numeric\_custom\_attribute["some-numeric-custom-attribute"],
[bucket(MIN, 0, "negative"), bucket(0, MAX, "non-negative"])
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.HistogramQuery`
job_view (~google.cloud.talent_v4beta1.types.JobView): Optional.
The desired job attributes returned for jobs in the search response.
Defaults to ``JobView.SMALL`` if no value is specified.
offset (int): Optional.
An integer that specifies the current offset (that is, starting result
location, amongst the jobs deemed by the API as relevant) in search
results. This field is only considered if ``page_token`` is unset.
For example, 0 means to return results starting from the first matching
job, and 10 means to return from the 11th job. This can be used for
pagination, (for example, pageSize = 10 and offset = 10 means to return
from the second page).
page_size (int): The maximum number of resources contained in the
underlying API response. If page streaming is performed per-
resource, this parameter does not affect the return value. If page
streaming is performed per-page, this determines the maximum number
of resources in a page.
order_by (str): Optional.
The criteria determining how search results are sorted. Default is
"relevance desc".
Supported options are:
- "relevance desc": By relevance descending, as determined by the API
algorithms. Relevance thresholding of query results is only available
with this ordering.
- "posting``_``\ publish\ ``_``\ time desc": By
``Job.posting_publish_time`` descending.
- "posting``_``\ update\ ``_``\ time desc": By
``Job.posting_update_time`` descending.
- "title": By ``Job.title`` ascending.
- "title desc": By ``Job.title`` descending.
- "annualized``_``\ base\ ``_``\ compensation": By job's
``CompensationInfo.annualized_base_compensation_range`` ascending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "annualized``_``\ base\ ``_``\ compensation desc": By job's
``CompensationInfo.annualized_base_compensation_range`` descending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "annualized``_``\ total\ ``_``\ compensation": By job's
``CompensationInfo.annualized_total_compensation_range`` ascending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "annualized``_``\ total\ ``_``\ compensation desc": By job's
``CompensationInfo.annualized_total_compensation_range`` descending.
Jobs whose annualized base compensation is unspecified are put at the
end of search results.
- "custom``_``\ ranking desc": By the relevance score adjusted to the
``SearchJobsRequest.custom_ranking_info.ranking_expression`` with
weight factor assigned by
``SearchJobsRequest.custom_ranking_info.importance_level`` in
descending order.
- "location``_``\ distance": By the distance between the location on
jobs and locations specified in the
``SearchJobsRequest.job_query.location_filters``. When this order is
selected, the ``SearchJobsRequest.job_query.location_filters`` must
not be empty. When a job has multiple locations, the location closest
to one of the locations specified in the location filter will be used
to calculate location distance. Distance is calculated by the
distance between two lat/long coordinates, with a precision of 10e-4
degrees (11.3 meters). Jobs that don't have locations specified will
be ranked below jobs having locations. Diversification strategy is
still applied unless explicitly disabled in
``SearchJobsRequest.diversification_level``.
diversification_level (~google.cloud.talent_v4beta1.types.DiversificationLevel): Optional.
Controls whether highly similar jobs are returned next to each other in
the search results. Jobs are identified as highly similar based on their
titles, job categories, and locations. Highly similar results are
clustered so that only one representative job of the cluster is
displayed to the job seeker higher up in the results, with the other
jobs being displayed lower down in the results.
Defaults to ``DiversificationLevel.SIMPLE`` if no value is specified.
custom_ranking_info (Union[dict, ~google.cloud.talent_v4beta1.types.CustomRankingInfo]): Optional.
Controls over how job documents get ranked on top of existing relevance
score (determined by API algorithm).
If a dict is provided, it must be of the same form as the protobuf
message :class:`~google.cloud.talent_v4beta1.types.CustomRankingInfo`
disable_keyword_match (bool): Optional.
Controls whether to disable exact keyword match on ``Job.job_title``,
``Job.description``, ``Job.company_display_name``, [Job.locations][0],
``Job.qualifications``. When disable keyword match is turned off, a
keyword match returns jobs that do not match given category filters when
there are matching keywords. For example, for the query "program
manager," a result is returned even if the job posting has the title
"software developer," which doesn't fall into "program manager"
ontology, but does have "program manager" appearing in its description.
For queries like "cloud" that don't contain title or location specific
ontology, jobs with "cloud" keyword matches are returned regardless of
this flag's value.
Please use ``Company.keyword_searchable_custom_fields`` or
``Company.keyword_searchable_custom_attributes`` if company specific
globally matched custom field/attribute string values is needed.
Enabling keyword match improves recall of subsequent search requests.
Defaults to false.
retry (Optional[google.api_core.retry.Retry]): A retry object used
to retry requests. If ``None`` is specified, requests will not
be retried.
timeout (Optional[float]): The amount of time, in seconds, to wait
for the request to complete. Note that if ``retry`` is
specified, the timeout applies to each individual attempt.
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.talent_v4beta1.types.MatchingJob` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If the parameters are invalid.
"""
# Wrap the transport method to add retry and timeout logic.
if "search_jobs" not in self._inner_api_calls:
self._inner_api_calls[
"search_jobs"
] = google.api_core.gapic_v1.method.wrap_method(
self.transport.search_jobs,
default_retry=self._method_configs["SearchJobs"].retry,
default_timeout=self._method_configs["SearchJobs"].timeout,
client_info=self._client_info,
)
request = job_service_pb2.SearchJobsRequest(
parent=parent,
request_metadata=request_metadata,
search_mode=search_mode,
job_query=job_query,
enable_broadening=enable_broadening,
require_precise_result_size=require_precise_result_size,
histogram_queries=histogram_queries,
job_view=job_view,
offset=offset,
page_size=page_size,
order_by=order_by,
diversification_level=diversification_level,
custom_ranking_info=custom_ranking_info,
disable_keyword_match=disable_keyword_match,
)
iterator = google.api_core.page_iterator.GRPCIterator(
client=None,
method=functools.partial(
self._inner_api_calls["search_jobs"],
retry=retry,
timeout=timeout,
metadata=metadata,
),
request=request,
items_field="matching_jobs",
request_token_field="page_token",
response_token_field="next_page_token",
)
return iterator |
Compute a type URL for a klass.
:type klass: type
:param klass: class to be used as a factory for the given type
:type prefix: str
:param prefix: URL prefix for the type
:rtype: str
:returns: the URL, prefixed as appropriate
def _compute_type_url(klass, prefix=_GOOGLE_APIS_PREFIX):
"""Compute a type URL for a klass.
:type klass: type
:param klass: class to be used as a factory for the given type
:type prefix: str
:param prefix: URL prefix for the type
:rtype: str
:returns: the URL, prefixed as appropriate
"""
name = klass.DESCRIPTOR.full_name
return "%s/%s" % (prefix, name) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.