Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/python-datacatalog #8508

Merged
merged 109 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 107 commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
8ba5fd1
Add generated samples (via synth). (#8710)
yoshi-automation Jul 19, 2019
cc0bec4
Add get_entry sample (via synth). (#8725)
yoshi-automation Jul 22, 2019
f195ada
Add 'search' sample (via synth). (#8793)
yoshi-automation Jul 26, 2019
6d5b3cf
Remove unused import from samples (via synth). (#9110)
yoshi-automation Aug 27, 2019
810a09b
feat(datacatalog): add sample to create an entry group (#9584)
ricardolsmendes Nov 1, 2019
c2ab241
feat(datacatalog): add sample to create a fileset entry (#9590)
ricardolsmendes Nov 5, 2019
b99022b
feat(datacatalog): add sample for create a fileset entry quickstart (…
mesmacosta Dec 18, 2019
305260a
feat(datacatalog): undeprecate resource name helper methods, bump cop…
yoshi-automation Jan 29, 2020
0092efc
Add samples for Data Catalog lookup_entry [(#2148)](https://github.co…
May 10, 2019
5c4fdea
Add region tags to support Data Catalog docs [(#2169)](https://github…
May 21, 2019
12f0dcd
Adds updates including compute [(#2436)](https://github.com/GoogleClo…
gguuss Oct 23, 2019
540fd59
Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPla…
dpebot Dec 21, 2019
e3f508e
chore(deps): update dependency google-cloud-datacatalog to v0.6.0 [(#…
renovate-bot Mar 10, 2020
377744e
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
ab8f43a
Update dependency google-cloud-datacatalog to v0.7.0 [(#3320)](https:…
renovate-bot Apr 9, 2020
270481f
Update Data Catalog samples to V1 [(#3382)](https://github.com/Google…
mesmacosta Apr 23, 2020
23dbd9b
chore(deps): update dependency google-cloud-datacatalog to v0.8.0 [(#…
renovate-bot May 20, 2020
baa8c1c
Update dependency google-cloud-datacatalog to v1 [(#4115)](https://gi…
renovate-bot Jun 19, 2020
b4fb822
chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://git…
renovate-bot Jul 12, 2020
99d4fee
Update dependency pytest to v6 [(#4390)](https://github.com/GoogleClo…
renovate-bot Aug 1, 2020
8222b6d
chore: update templates
hkdevandla Aug 12, 2020
f24d507
feat: Migrate API client to Microgenerator (#54)
hkdevandla Aug 20, 2020
e2afbda
chore(deps): update dependency google-cloud-datacatalog to v2 (#61)
renovate-bot Oct 16, 2020
a9f9df6
feat!: add common resource paths; expose client transport; rename ``t…
yoshi-automation Nov 17, 2020
963c929
chore(deps): update dependency google-cloud-datacatalog to v3 (#73)
renovate-bot Nov 25, 2020
904fdee
chore: update templates (#83)
yoshi-automation Dec 29, 2020
1228f5f
chore: add 3.9 to noxfile template (#101)
yoshi-automation Jan 21, 2021
870535c
chore(deps): update dependency google-cloud-datacatalog to v3.1.0 (#123)
renovate-bot Mar 22, 2021
08f702c
chore(deps): update dependency google-cloud-datacatalog to v3.1.1 (#130)
renovate-bot Apr 1, 2021
6f3428d
chore: add constraints file check for python samples (#137)
yoshi-automation Apr 13, 2021
ff93213
chore(deps): update dependency pytest to v6.2.3 (#138)
renovate-bot Apr 13, 2021
be6ef73
chore(deps): update dependency pytest to v6.2.4 (#152)
renovate-bot May 6, 2021
e72dab7
chore: new owl bot post processor docker image (#165)
gcf-owl-bot[bot] May 22, 2021
69001c4
chore(deps): update dependency google-cloud-datacatalog to v3.2.0 (#170)
renovate-bot Jun 9, 2021
7a2ec24
chore(deps): update dependency google-cloud-datacatalog to v3.2.1 (#172)
renovate-bot Jun 18, 2021
d387a89
chore(deps): update dependency google-cloud-datacatalog to v3.3.0 (#183)
renovate-bot Jul 13, 2021
f4f252f
feat: add Samples section to CONTRIBUTING.rst (#187)
gcf-owl-bot[bot] Jul 22, 2021
f171872
chore(deps): update dependency google-cloud-datacatalog to v3.3.1 (#189)
renovate-bot Jul 22, 2021
81cdee5
chore(deps): update dependency google-cloud-datacatalog to v3.3.2 (#195)
renovate-bot Jul 28, 2021
c24681c
chore(deps): update dependency google-cloud-datacatalog to v3.4.0 (#198)
renovate-bot Jul 29, 2021
59ff57f
docs(samples): add samples from docs & reorganize all samples for tes…
steffnay Aug 11, 2021
bd1153e
chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#201)
gcf-owl-bot[bot] Aug 11, 2021
ed26248
chore(deps): update dependency google-cloud-bigquery to v2.23.3 (#203)
renovate-bot Aug 12, 2021
d597899
chore: drop mention of Python 2.7 from templates (#207)
gcf-owl-bot[bot] Aug 13, 2021
e2053c5
fix: make datacatalog == datacatalog_v1 (#206)
busunkim96 Aug 13, 2021
9bc4975
chore(deps): update dependency google-cloud-bigquery to v2.24.0 (#205)
renovate-bot Aug 16, 2021
29a62e5
chore(deps): update dependency google-cloud-bigquery to v2.24.1 (#208)
renovate-bot Aug 19, 2021
7ba6be3
chore(deps): update dependency google-cloud-bigquery to v2.25.1 (#212)
renovate-bot Aug 30, 2021
85652b5
chore(deps): update dependency pytest to v6.2.5 (#216)
renovate-bot Aug 30, 2021
6cfd2ec
chore(deps): update dependency google-cloud-bigquery to v2.25.2 (#217)
renovate-bot Sep 1, 2021
0041c18
docs(samples): add entry group greation to custom entry sample (#215)
steffnay Sep 2, 2021
5b3f35e
chore(deps): update all dependencies (#220)
renovate-bot Sep 3, 2021
50adab5
chore: blacken samples noxfile template (#225)
gcf-owl-bot[bot] Sep 17, 2021
4f70fa0
chore(deps): update dependency google-cloud-bigquery to v2.27.0 (#229)
renovate-bot Sep 28, 2021
8f7183d
chore(deps): update all dependencies (#231)
renovate-bot Sep 28, 2021
e00a482
chore: fail samples nox session if python version is missing (#234)
gcf-owl-bot[bot] Sep 30, 2021
4023cba
chore(deps): update dependency google-cloud-bigquery to v2.28.0 (#235)
renovate-bot Sep 30, 2021
f33da0f
chore(deps): update dependency google-cloud-datacatalog to v3.4.3 (#237)
renovate-bot Oct 7, 2021
0fc544f
chore(python): Add kokoro configs for python 3.10 samples testing (#241)
gcf-owl-bot[bot] Oct 8, 2021
c908b79
chore(deps): update dependency google-cloud-bigquery to v2.28.1 (#239)
renovate-bot Oct 11, 2021
5c5f500
chore(deps): update dependency google-cloud-bigquery to v2.29.0 (#247)
renovate-bot Oct 28, 2021
3b536d9
chore(deps): update dependency google-cloud-datacatalog to v3.5.0 (#250)
renovate-bot Nov 3, 2021
c78c52a
chore(deps): update dependency google-cloud-bigquery to v2.30.0 (#252)
renovate-bot Nov 4, 2021
3f47e03
chore(deps): update all dependencies (#253)
renovate-bot Nov 5, 2021
57a4be9
chore(deps): update dependency google-cloud-datacatalog to v3.6.0 (#258)
renovate-bot Nov 8, 2021
2ca0fb1
chore(python): run blacken session for all directories with a noxfile…
gcf-owl-bot[bot] Nov 11, 2021
28f0e67
chore(deps): update dependency google-cloud-datacatalog to v3.6.1 (#266)
renovate-bot Nov 16, 2021
4d85fcd
chore(deps): update dependency google-cloud-bigquery to v2.31.0 (#270)
renovate-bot Dec 3, 2021
817486e
docs(samples): Add sample for PolicyTagManagerClient.create_taxonomy …
ricardolsmendes Dec 28, 2021
3e5bae9
chore: use python-samples-reviewers (#278)
gcf-owl-bot[bot] Jan 6, 2022
ef099d7
chore(samples): Add check for tests in directory (#280)
gcf-owl-bot[bot] Jan 11, 2022
aeca576
chore(deps): update dependency google-cloud-bigquery to v2.32.0 (#282)
renovate-bot Jan 13, 2022
7d8a3f8
chore(deps): update dependency google-cloud-datacatalog to v3.6.2 (#284)
renovate-bot Jan 15, 2022
e34e9b9
chore(python): Noxfile recognizes that tests can live in a folder (#287)
gcf-owl-bot[bot] Jan 22, 2022
8062842
chore(deps): update dependency pytest to v7 (#296)
renovate-bot Feb 8, 2022
edb2fd0
chore(deps): update all dependencies (#299)
renovate-bot Feb 28, 2022
135540d
chore(deps): update all dependencies (#304)
renovate-bot Feb 28, 2022
7f82ee1
chore(deps): update all dependencies (#309)
renovate-bot Mar 3, 2022
bc9ad77
chore: Adding support for pytest-xdist and pytest-parallel (#312)
gcf-owl-bot[bot] Mar 4, 2022
2e1a22a
chore(deps): update all dependencies (#315)
renovate-bot Mar 8, 2022
1b418ce
chore(deps): update dependency pytest to v7.1.0 (#319)
renovate-bot Mar 13, 2022
183fae7
chore(deps): update dependency pytest to v7.1.1 (#320)
renovate-bot Mar 19, 2022
25c11f5
chore(python): use black==22.3.0 (#327)
gcf-owl-bot[bot] Mar 28, 2022
af019bd
chore(deps): update dependency google-cloud-bigquery to v3 (#328)
renovate-bot Mar 30, 2022
f57c8b7
chore(python): add nox session to sort python imports (#344)
gcf-owl-bot[bot] Apr 21, 2022
0fc981b
chore(deps): update dependency pytest to v7.1.2 (#347)
renovate-bot Apr 25, 2022
d33c971
chore(deps): update dependency google-cloud-bigquery to v3.1.0 (#352)
renovate-bot May 9, 2022
1ba6e3f
chore(deps): update dependency google-cloud-datacatalog to v3.8.0 (#353)
renovate-bot May 19, 2022
df94b94
fix: require python 3.7+ (#403)
gcf-owl-bot[bot] Jul 10, 2022
2fdf5dc
chore(deps): update all dependencies (#391)
renovate-bot Jul 16, 2022
a5385af
chore(deps): update all dependencies (#408)
renovate-bot Aug 2, 2022
1a77c5d
chore(deps): update all dependencies (#410)
renovate-bot Aug 9, 2022
2aea143
chore(deps): update dependency google-cloud-datacatalog to v3.9.1 (#415)
renovate-bot Aug 17, 2022
00fc3ee
chore(deps): update dependency google-cloud-bigquery to v3.3.2 (#416)
renovate-bot Aug 19, 2022
11d4f37
chore(deps): update dependency pytest to v7.1.3 (#426)
renovate-bot Sep 6, 2022
e1babb8
chore: detect samples tests in nested directories (#430)
gcf-owl-bot[bot] Sep 13, 2022
a7dd6cf
chore(deps): update dependency google-cloud-bigquery to v3.3.3 (#434)
renovate-bot Oct 3, 2022
598195f
chore(deps): update dependency google-cloud-datacatalog to v3.9.2 (#436)
renovate-bot Oct 4, 2022
169212b
chore(deps): update all dependencies (#439)
renovate-bot Oct 18, 2022
354395f
chore(deps): update dependency pytest to v7.2.0 (#440)
renovate-bot Oct 26, 2022
ee24322
Merge remote-tracking branch 'migration/main' into python-datacatalog…
msampathkumar Nov 14, 2022
ce660e9
Update license header
msampathkumar Nov 14, 2022
281424c
Remove (redundant) noxfile.py
msampathkumar Nov 14, 2022
e2b5574
Update lookup_entry.py region tag
msampathkumar Nov 14, 2022
00402f5
Update CODEOWNERS & blunderbuss.yml
msampathkumar Nov 15, 2022
16e19f7
Merge branch 'main' into python-datacatalog-migration
msampathkumar Nov 15, 2022
88d1095
Update .github/CODEOWNERS
dandhlee Nov 15, 2022
7ac00aa
Merge branch 'main' into python-datacatalog-migration
dandhlee Nov 15, 2022
074f650
Merge branch 'main' into python-datacatalog-migration
dandhlee Nov 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@
/talent/**/* @GoogleCloudPlatform/python-samples-reviewers
/vision/**/* @GoogleCloudPlatform/python-samples-reviewers
/workflows/**/* @GoogleCloudPlatform/python-samples-reviewers
/datacatalog/**/* @GoogleCloudPlatform/python-samples-reviewers
/kms/**/** @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
4 changes: 4 additions & 0 deletions .github/blunderbuss.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ assign_issues_by:
- 'api: monitoring'
to:
- GoogleCloudPlatform/dee-observability
- labels:
- 'api: datacatalog'
to:
- GoogleCloudPlatform/python-samples-reviewers
- labels:
- 'api: kms'
- 'api: cloudkms'
Expand Down
76 changes: 76 additions & 0 deletions datacatalog/quickstart/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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.


import datetime
import uuid

import google.auth
from google.cloud import bigquery, datacatalog_v1
import pytest


def temp_suffix():
now = datetime.datetime.now()
return "{}_{}".format(now.strftime("%Y%m%d%H%M%S"), uuid.uuid4().hex[:8])


@pytest.fixture(scope="session")
def client(credentials):
return datacatalog_v1.DataCatalogClient(credentials=credentials)


@pytest.fixture(scope="session")
def bigquery_client(credentials, project_id):
return bigquery.Client(project=project_id, credentials=credentials)


@pytest.fixture(scope="session")
def default_credentials():
return google.auth.default(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
)


@pytest.fixture(scope="session")
def credentials(default_credentials):
return default_credentials[0]


@pytest.fixture(scope="session")
def project_id(default_credentials):
return default_credentials[1]


@pytest.fixture
def dataset_id(bigquery_client):
dataset_id = f"python_data_catalog_sample_{temp_suffix()}"
dataset = bigquery_client.create_dataset(dataset_id)
yield dataset.dataset_id
bigquery_client.delete_dataset(dataset, delete_contents=True, not_found_ok=True)


@pytest.fixture
def table_id(bigquery_client, project_id, dataset_id):
table_id = f"python_data_catalog_sample_{temp_suffix()}"
table = bigquery.Table("{}.{}.{}".format(project_id, dataset_id, table_id))
table = bigquery_client.create_table(table)
yield table.table_id
bigquery_client.delete_table(table, not_found_ok=True)


@pytest.fixture
def random_tag_template_id():
random_tag_template_id = f"python_sample_{temp_suffix()}"
yield random_tag_template_id
131 changes: 131 additions & 0 deletions datacatalog/quickstart/quickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# 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.


def quickstart(override_values):
"""Creates a tag template and attach a tag to a BigQuery table."""
# [START data_catalog_quickstart]
# Import required modules.
from google.cloud import datacatalog_v1

# TODO: Set these values before running the sample.
# Google Cloud Platform project.
project_id = "my_project"
# Set dataset_id to the ID of existing dataset.
dataset_id = "demo_dataset"
# Set table_id to the ID of existing table.
table_id = "trips"
# Tag template to create.
tag_template_id = "example_tag_template"

# [END data_catalog_quickstart]

# To facilitate testing, we replace values with alternatives
# provided by the testing harness.
project_id = override_values.get("project_id", project_id)
dataset_id = override_values.get("dataset_id", dataset_id)
table_id = override_values.get("table_id", table_id)
tag_template_id = override_values.get("tag_template_id", tag_template_id)

# [START data_catalog_quickstart]
# For all regions available, see:
# https://cloud.google.com/data-catalog/docs/concepts/regions
location = "us-central1"

# Use Application Default Credentials to create a new
# Data Catalog client. GOOGLE_APPLICATION_CREDENTIALS
# environment variable must be set with the location
# of a service account key file.
datacatalog_client = datacatalog_v1.DataCatalogClient()

# Create a Tag Template.
tag_template = datacatalog_v1.types.TagTemplate()

tag_template.display_name = "Demo Tag Template"

tag_template.fields["source"] = datacatalog_v1.types.TagTemplateField()
tag_template.fields["source"].display_name = "Source of data asset"
tag_template.fields[
"source"
].type_.primitive_type = datacatalog_v1.types.FieldType.PrimitiveType.STRING

tag_template.fields["num_rows"] = datacatalog_v1.types.TagTemplateField()
tag_template.fields["num_rows"].display_name = "Number of rows in data asset"
tag_template.fields[
"num_rows"
].type_.primitive_type = datacatalog_v1.types.FieldType.PrimitiveType.DOUBLE

tag_template.fields["has_pii"] = datacatalog_v1.types.TagTemplateField()
tag_template.fields["has_pii"].display_name = "Has PII"
tag_template.fields[
"has_pii"
].type_.primitive_type = datacatalog_v1.types.FieldType.PrimitiveType.BOOL

tag_template.fields["pii_type"] = datacatalog_v1.types.TagTemplateField()
tag_template.fields["pii_type"].display_name = "PII type"

for display_name in ["EMAIL", "SOCIAL SECURITY NUMBER", "NONE"]:
enum_value = datacatalog_v1.types.FieldType.EnumType.EnumValue(
display_name=display_name
)
tag_template.fields["pii_type"].type_.enum_type.allowed_values.append(
enum_value
)

expected_template_name = datacatalog_v1.DataCatalogClient.tag_template_path(
project_id, location, tag_template_id
)

# Create the Tag Template.
try:
tag_template = datacatalog_client.create_tag_template(
parent=f"projects/{project_id}/locations/{location}",
tag_template_id=tag_template_id,
tag_template=tag_template,
)
print(f"Created template: {tag_template.name}")
except OSError as e:
print(f"Cannot create template: {expected_template_name}")
print(f"{e}")

# Lookup Data Catalog's Entry referring to the table.
resource_name = (
f"//bigquery.googleapis.com/projects/{project_id}"
f"/datasets/{dataset_id}/tables/{table_id}"
)
table_entry = datacatalog_client.lookup_entry(
request={"linked_resource": resource_name}
)

# Attach a Tag to the table.
tag = datacatalog_v1.types.Tag()

tag.template = tag_template.name
tag.name = "my_super_cool_tag"

tag.fields["source"] = datacatalog_v1.types.TagField()
tag.fields["source"].string_value = "Copied from tlc_yellow_trips_2018"

tag.fields["num_rows"] = datacatalog_v1.types.TagField()
tag.fields["num_rows"].double_value = 113496874

tag.fields["has_pii"] = datacatalog_v1.types.TagField()
tag.fields["has_pii"].bool_value = False

tag.fields["pii_type"] = datacatalog_v1.types.TagField()
tag.fields["pii_type"].enum_value.display_name = "NONE"

tag = datacatalog_client.create_tag(parent=table_entry.name, tag=tag)
print(f"Created tag: {tag.name}")
# [END data_catalog_quickstart]
35 changes: 35 additions & 0 deletions datacatalog/quickstart/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.

import quickstart


def test_quickstart(
capsys, client, project_id, dataset_id, table_id, random_tag_template_id
):
location = "us-central1"
override_values = {
"project_id": project_id,
"dataset_id": dataset_id,
"table_id": table_id,
"tag_template_id": random_tag_template_id,
}
tag_template_name = client.tag_template_path(
project_id, location, random_tag_template_id
)
quickstart.quickstart(override_values)
out, err = capsys.readouterr()
assert "Created template: {}".format(tag_template_name) in out
assert "Created tag:" in out
client.delete_tag_template(name=tag_template_name, force=True)
2 changes: 2 additions & 0 deletions datacatalog/quickstart/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==7.2.0
google-cloud-bigquery==3.3.5
1 change: 1 addition & 0 deletions datacatalog/quickstart/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-cloud-datacatalog==3.9.3
Loading