Skip to content

Commit 77de091

Browse files
yoshi-automationbusunkim96
authored andcommitted
Add 'search' sample (via synth). (#8793)
1 parent 746b21b commit 77de091

2 files changed

Lines changed: 97 additions & 5 deletions

File tree

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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()

packages/google-cloud-datacatalog/synth.metadata

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"updateTime": "2019-07-20T12:17:02.340446Z",
2+
"updateTime": "2019-07-26T12:17:03.436639Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.30.1",
8-
"dockerImage": "googleapis/artman@sha256:f1a2e851e5e012c59e1da4125480bb19878f86a4e7fac4f375f2e819956b5aa3"
7+
"version": "0.31.0",
8+
"dockerImage": "googleapis/artman@sha256:9aed6bbde54e26d2fcde7aa86d9f64c0278f741e58808c46573e488cbf6098f0"
99
}
1010
},
1111
{
1212
"git": {
1313
"name": "googleapis",
1414
"remote": "https://github.com/googleapis/googleapis.git",
15-
"sha": "184ab77f4cee62332f8f9a689c70c9bea441f836",
16-
"internalRef": "259048326"
15+
"sha": "0906a9e74f4db789aee7fc5016ab828d3dd24f03",
16+
"internalRef": "260061471"
1717
}
1818
},
1919
{

0 commit comments

Comments
 (0)