|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright 2019 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# DO NOT EDIT! This is a generated sample ("RequestPagedAll", "datacatalog_search") |
| 18 | + |
| 19 | +# To install the latest published package dependency, execute the following: |
| 20 | +# pip install google-cloud-datacatalog |
| 21 | + |
| 22 | +# sample-metadata |
| 23 | +# title: |
| 24 | +# description: Search Catalog |
| 25 | +# usage: python3 samples/v1beta1/datacatalog_search.py [--include_project_id "[Google Cloud Project ID]"] [--include_gcp_public_datasets false] [--query "[String in search query syntax]"] |
| 26 | +import sys |
| 27 | + |
| 28 | +# [START datacatalog_search] |
| 29 | + |
| 30 | +from google.cloud import datacatalog_v1beta1 |
| 31 | +from google.cloud.datacatalog_v1beta1 import enums |
| 32 | + |
| 33 | + |
| 34 | +def sample_search_catalog(include_project_id, include_gcp_public_datasets, query): |
| 35 | + """ |
| 36 | + Search Catalog |
| 37 | +
|
| 38 | + Args: |
| 39 | + include_project_id Your Google Cloud project ID. |
| 40 | + include_gcp_public_datasets If true, include Google Cloud Platform (GCP) public |
| 41 | + datasets in the search results. |
| 42 | + query Your query string. |
| 43 | + See: https://cloud.google.com/data-catalog/docs/how-to/search-reference |
| 44 | + Example: system=bigquery type=dataset |
| 45 | + """ |
| 46 | + |
| 47 | + client = datacatalog_v1beta1.DataCatalogClient() |
| 48 | + |
| 49 | + # include_project_id = '[Google Cloud Project ID]' |
| 50 | + # include_gcp_public_datasets = False |
| 51 | + # query = '[String in search query syntax]' |
| 52 | + include_project_ids = [include_project_id] |
| 53 | + scope = { |
| 54 | + "include_project_ids": include_project_ids, |
| 55 | + "include_gcp_public_datasets": include_gcp_public_datasets, |
| 56 | + } |
| 57 | + |
| 58 | + # Iterate over all results |
| 59 | + for response_item in client.search_catalog(scope, query): |
| 60 | + print( |
| 61 | + u"Result type: {}".format( |
| 62 | + enums.SearchResultType(response_item.search_result_type).name |
| 63 | + ) |
| 64 | + ) |
| 65 | + print(u"Result subtype: {}".format(response_item.search_result_subtype)) |
| 66 | + print( |
| 67 | + u"Relative resource name: {}".format(response_item.relative_resource_name) |
| 68 | + ) |
| 69 | + print(u"Linked resource: {}\n".format(response_item.linked_resource)) |
| 70 | + |
| 71 | + |
| 72 | +# [END datacatalog_search] |
| 73 | + |
| 74 | + |
| 75 | +def main(): |
| 76 | + import argparse |
| 77 | + |
| 78 | + parser = argparse.ArgumentParser() |
| 79 | + parser.add_argument( |
| 80 | + "--include_project_id", type=str, default="[Google Cloud Project ID]" |
| 81 | + ) |
| 82 | + parser.add_argument("--include_gcp_public_datasets", type=bool, default=False) |
| 83 | + parser.add_argument("--query", type=str, default="[String in search query syntax]") |
| 84 | + args = parser.parse_args() |
| 85 | + |
| 86 | + sample_search_catalog( |
| 87 | + args.include_project_id, args.include_gcp_public_datasets, args.query |
| 88 | + ) |
| 89 | + |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + main() |
0 commit comments