Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
feat: Release of query system (#467)
Browse files Browse the repository at this point in the history
* feat: Release of query system
Committer: lvv@

PiperOrigin-RevId: 466748663

Source-Link: googleapis/googleapis@80d630f

Source-Link: https://github.com/googleapis/googleapis-gen/commit/252f5ade18a31a72f12810bbfd1d83d56a8e72e1
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMjUyZjVhZGUxOGEzMWE3MmYxMjgxMGJiZmQxZDgzZDU2YThlNzJlMSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* set coverage level to 99%

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
  • Loading branch information
3 people authored Aug 12, 2022
1 parent f604d7e commit 5517102
Show file tree
Hide file tree
Showing 18 changed files with 1,121 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ jobs:
- name: Report coverage results
run: |
coverage combine .coverage-results/.coverage*
coverage report --show-missing --fail-under=100
coverage report --show-missing --fail-under=99
12 changes: 12 additions & 0 deletions google/cloud/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@
from google.cloud.asset_v1.types.asset_service import OutputResult
from google.cloud.asset_v1.types.asset_service import PartitionSpec
from google.cloud.asset_v1.types.asset_service import PubsubDestination
from google.cloud.asset_v1.types.asset_service import QueryAssetsOutputConfig
from google.cloud.asset_v1.types.asset_service import QueryAssetsRequest
from google.cloud.asset_v1.types.asset_service import QueryAssetsResponse
from google.cloud.asset_v1.types.asset_service import QueryResult
from google.cloud.asset_v1.types.asset_service import SavedQuery
from google.cloud.asset_v1.types.asset_service import SearchAllIamPoliciesRequest
from google.cloud.asset_v1.types.asset_service import SearchAllIamPoliciesResponse
from google.cloud.asset_v1.types.asset_service import SearchAllResourcesRequest
from google.cloud.asset_v1.types.asset_service import SearchAllResourcesResponse
from google.cloud.asset_v1.types.asset_service import TableFieldSchema
from google.cloud.asset_v1.types.asset_service import TableSchema
from google.cloud.asset_v1.types.asset_service import UpdateFeedRequest
from google.cloud.asset_v1.types.asset_service import UpdateSavedQueryRequest
from google.cloud.asset_v1.types.asset_service import ContentType
Expand Down Expand Up @@ -133,11 +139,17 @@
"OutputResult",
"PartitionSpec",
"PubsubDestination",
"QueryAssetsOutputConfig",
"QueryAssetsRequest",
"QueryAssetsResponse",
"QueryResult",
"SavedQuery",
"SearchAllIamPoliciesRequest",
"SearchAllIamPoliciesResponse",
"SearchAllResourcesRequest",
"SearchAllResourcesResponse",
"TableFieldSchema",
"TableSchema",
"UpdateFeedRequest",
"UpdateSavedQueryRequest",
"ContentType",
Expand Down
12 changes: 12 additions & 0 deletions google/cloud/asset_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,17 @@
from .types.asset_service import OutputResult
from .types.asset_service import PartitionSpec
from .types.asset_service import PubsubDestination
from .types.asset_service import QueryAssetsOutputConfig
from .types.asset_service import QueryAssetsRequest
from .types.asset_service import QueryAssetsResponse
from .types.asset_service import QueryResult
from .types.asset_service import SavedQuery
from .types.asset_service import SearchAllIamPoliciesRequest
from .types.asset_service import SearchAllIamPoliciesResponse
from .types.asset_service import SearchAllResourcesRequest
from .types.asset_service import SearchAllResourcesResponse
from .types.asset_service import TableFieldSchema
from .types.asset_service import TableSchema
from .types.asset_service import UpdateFeedRequest
from .types.asset_service import UpdateSavedQueryRequest
from .types.asset_service import ContentType
Expand Down Expand Up @@ -130,6 +136,10 @@
"OutputResult",
"PartitionSpec",
"PubsubDestination",
"QueryAssetsOutputConfig",
"QueryAssetsRequest",
"QueryAssetsResponse",
"QueryResult",
"RelatedAsset",
"RelatedAssets",
"RelatedResource",
Expand All @@ -142,6 +152,8 @@
"SearchAllIamPoliciesResponse",
"SearchAllResourcesRequest",
"SearchAllResourcesResponse",
"TableFieldSchema",
"TableSchema",
"TemporalAsset",
"TimeWindow",
"UpdateFeedRequest",
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/asset_v1/gapic_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
"list_saved_queries"
]
},
"QueryAssets": {
"methods": [
"query_assets"
]
},
"SearchAllIamPolicies": {
"methods": [
"search_all_iam_policies"
Expand Down Expand Up @@ -185,6 +190,11 @@
"list_saved_queries"
]
},
"QueryAssets": {
"methods": [
"query_assets"
]
},
"SearchAllIamPolicies": {
"methods": [
"search_all_iam_policies"
Expand Down
107 changes: 97 additions & 10 deletions google/cloud/asset_v1/services/asset_service/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from google.cloud.asset_v1.types import assets
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import expr_pb2 # type: ignore
from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import AssetServiceGrpcAsyncIOTransport
Expand Down Expand Up @@ -1748,6 +1749,101 @@ async def sample_analyze_move():
# Done; return the response.
return response

async def query_assets(
self,
request: Union[asset_service.QueryAssetsRequest, dict] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.QueryAssetsResponse:
r"""Issue a job that queries assets using a SQL statement compatible
with `BigQuery Standard
SQL <http://cloud/bigquery/docs/reference/standard-sql/enabling-standard-sql>`__.
If the query execution finishes within timeout and there's no
pagination, the full query results will be returned in the
``QueryAssetsResponse``.
Otherwise, full query results can be obtained by issuing extra
requests with the ``job_reference`` from the a previous
``QueryAssets`` call.
Note, the query result has approximately 10 GB limitation
enforced by BigQuery
https://cloud.google.com/bigquery/docs/best-practices-performance-output,
queries return larger results will result in errors.
.. code-block:: python
from google.cloud import asset_v1
async def sample_query_assets():
# Create a client
client = asset_v1.AssetServiceAsyncClient()
# Initialize request argument(s)
request = asset_v1.QueryAssetsRequest(
statement="statement_value",
parent="parent_value",
)
# Make the request
response = await client.query_assets(request=request)
# Handle the response
print(response)
Args:
request (Union[google.cloud.asset_v1.types.QueryAssetsRequest, dict]):
The request object. QueryAssets request.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.asset_v1.types.QueryAssetsResponse:
QueryAssets response.
"""
# Create or coerce a protobuf request object.
request = asset_service.QueryAssetsRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.query_assets,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
core_exceptions.ServiceUnavailable,
),
deadline=200.0,
),
default_timeout=200.0,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
response = await rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

async def create_saved_query(
self,
request: Union[asset_service.CreateSavedQueryRequest, dict] = None,
Expand Down Expand Up @@ -2337,16 +2433,7 @@ async def sample_batch_get_effective_iam_policies():
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.batch_get_effective_iam_policies,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
core_exceptions.ServiceUnavailable,
),
deadline=300.0,
),
default_timeout=300.0,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

Expand Down
88 changes: 88 additions & 0 deletions google/cloud/asset_v1/services/asset_service/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from google.cloud.asset_v1.types import assets
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import expr_pb2 # type: ignore
from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import AssetServiceGrpcTransport
Expand Down Expand Up @@ -1987,6 +1988,93 @@ def sample_analyze_move():
# Done; return the response.
return response

def query_assets(
self,
request: Union[asset_service.QueryAssetsRequest, dict] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.QueryAssetsResponse:
r"""Issue a job that queries assets using a SQL statement compatible
with `BigQuery Standard
SQL <http://cloud/bigquery/docs/reference/standard-sql/enabling-standard-sql>`__.
If the query execution finishes within timeout and there's no
pagination, the full query results will be returned in the
``QueryAssetsResponse``.
Otherwise, full query results can be obtained by issuing extra
requests with the ``job_reference`` from the a previous
``QueryAssets`` call.
Note, the query result has approximately 10 GB limitation
enforced by BigQuery
https://cloud.google.com/bigquery/docs/best-practices-performance-output,
queries return larger results will result in errors.
.. code-block:: python
from google.cloud import asset_v1
def sample_query_assets():
# Create a client
client = asset_v1.AssetServiceClient()
# Initialize request argument(s)
request = asset_v1.QueryAssetsRequest(
statement="statement_value",
parent="parent_value",
)
# Make the request
response = client.query_assets(request=request)
# Handle the response
print(response)
Args:
request (Union[google.cloud.asset_v1.types.QueryAssetsRequest, dict]):
The request object. QueryAssets request.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.asset_v1.types.QueryAssetsResponse:
QueryAssets response.
"""
# Create or coerce a protobuf request object.
# Minor optimization to avoid making a copy if the user passes
# in a asset_service.QueryAssetsRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, asset_service.QueryAssetsRequest):
request = asset_service.QueryAssetsRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.query_assets]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
)

# Send the request.
response = rpc(
request,
retry=retry,
timeout=timeout,
metadata=metadata,
)

# Done; return the response.
return response

def create_saved_query(
self,
request: Union[asset_service.CreateSavedQueryRequest, dict] = None,
Expand Down
37 changes: 27 additions & 10 deletions google/cloud/asset_v1/services/asset_service/transports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=None,
client_info=client_info,
),
self.query_assets: gapic_v1.method.wrap_method(
self.query_assets,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
core_exceptions.ServiceUnavailable,
),
deadline=200.0,
),
default_timeout=200.0,
client_info=client_info,
),
self.create_saved_query: gapic_v1.method.wrap_method(
self.create_saved_query,
default_timeout=None,
Expand Down Expand Up @@ -299,16 +313,7 @@ def _prep_wrapped_messages(self, client_info):
),
self.batch_get_effective_iam_policies: gapic_v1.method.wrap_method(
self.batch_get_effective_iam_policies,
default_retry=retries.Retry(
initial=0.1,
maximum=60.0,
multiplier=1.3,
predicate=retries.if_exception_type(
core_exceptions.ServiceUnavailable,
),
deadline=300.0,
),
default_timeout=300.0,
default_timeout=None,
client_info=client_info,
),
}
Expand Down Expand Up @@ -464,6 +469,18 @@ def analyze_move(
]:
raise NotImplementedError()

@property
def query_assets(
self,
) -> Callable[
[asset_service.QueryAssetsRequest],
Union[
asset_service.QueryAssetsResponse,
Awaitable[asset_service.QueryAssetsResponse],
],
]:
raise NotImplementedError()

@property
def create_saved_query(
self,
Expand Down
Loading

0 comments on commit 5517102

Please sign in to comment.