Skip to content

Commit

Permalink
Add 'search' sample (via synth). (#8793)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and busunkim96 committed Jul 26, 2019
1 parent 746b21b commit 77de091
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-
#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# DO NOT EDIT! This is a generated sample ("RequestPagedAll", "datacatalog_search")

# To install the latest published package dependency, execute the following:
# pip install google-cloud-datacatalog

# sample-metadata
# title:
# description: Search Catalog
# 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]"]
import sys

# [START datacatalog_search]

from google.cloud import datacatalog_v1beta1
from google.cloud.datacatalog_v1beta1 import enums


def sample_search_catalog(include_project_id, include_gcp_public_datasets, query):
"""
Search Catalog
Args:
include_project_id Your Google Cloud project ID.
include_gcp_public_datasets If true, include Google Cloud Platform (GCP) public
datasets in the search results.
query Your query string.
See: https://cloud.google.com/data-catalog/docs/how-to/search-reference
Example: system=bigquery type=dataset
"""

client = datacatalog_v1beta1.DataCatalogClient()

# include_project_id = '[Google Cloud Project ID]'
# include_gcp_public_datasets = False
# query = '[String in search query syntax]'
include_project_ids = [include_project_id]
scope = {
"include_project_ids": include_project_ids,
"include_gcp_public_datasets": include_gcp_public_datasets,
}

# Iterate over all results
for response_item in client.search_catalog(scope, query):
print(
u"Result type: {}".format(
enums.SearchResultType(response_item.search_result_type).name
)
)
print(u"Result subtype: {}".format(response_item.search_result_subtype))
print(
u"Relative resource name: {}".format(response_item.relative_resource_name)
)
print(u"Linked resource: {}\n".format(response_item.linked_resource))


# [END datacatalog_search]


def main():
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
"--include_project_id", type=str, default="[Google Cloud Project ID]"
)
parser.add_argument("--include_gcp_public_datasets", type=bool, default=False)
parser.add_argument("--query", type=str, default="[String in search query syntax]")
args = parser.parse_args()

sample_search_catalog(
args.include_project_id, args.include_gcp_public_datasets, args.query
)


if __name__ == "__main__":
main()
10 changes: 5 additions & 5 deletions packages/google-cloud-datacatalog/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"updateTime": "2019-07-20T12:17:02.340446Z",
"updateTime": "2019-07-26T12:17:03.436639Z",
"sources": [
{
"generator": {
"name": "artman",
"version": "0.30.1",
"dockerImage": "googleapis/artman@sha256:f1a2e851e5e012c59e1da4125480bb19878f86a4e7fac4f375f2e819956b5aa3"
"version": "0.31.0",
"dockerImage": "googleapis/artman@sha256:9aed6bbde54e26d2fcde7aa86d9f64c0278f741e58808c46573e488cbf6098f0"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "184ab77f4cee62332f8f9a689c70c9bea441f836",
"internalRef": "259048326"
"sha": "0906a9e74f4db789aee7fc5016ab828d3dd24f03",
"internalRef": "260061471"
}
},
{
Expand Down

0 comments on commit 77de091

Please sign in to comment.