Skip to content

Commit ceafb90

Browse files
committed
feat(dataplex): add sample for creating a global data profile scan
- Adds `create_data_profile_scan.py` demonstrating how to create a Dataplex Data Profile Scan using global API endpoint routing.
1 parent d2ce99a commit ceafb90

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START dataplex_create_data_profile_scan_global]
16+
import google.api_core.exceptions
17+
from google.cloud import dataplex_v1
18+
19+
20+
def create_data_profile_scan_global(
21+
project_id: str,
22+
dataset_id: str,
23+
table_id: str,
24+
location: str,
25+
) -> None:
26+
"""Creates a Dataplex Data Profile Scan using global API endpoint routing.
27+
28+
Args:
29+
project_id (str): GCP project ID where the scan is created.
30+
dataset_id (str): Target BigQuery dataset ID.
31+
table_id (str): Target BigQuery table ID to scan.
32+
location (str): GCP region where serverless compute runs.
33+
"""
34+
client = dataplex_v1.DataScanServiceClient()
35+
36+
parent = client.common_location_path(project=project_id, location=location)
37+
38+
bigquery_table = (
39+
f"//bigquery.googleapis.com/projects/{project_id}"
40+
f"/datasets/{dataset_id}/tables/{table_id}"
41+
)
42+
43+
data_profile_spec = dataplex_v1.DataProfileSpec(sampling_percent=100.0)
44+
45+
data_scan = dataplex_v1.DataScan(
46+
display_name="Global Data Profile Scan",
47+
description="Regional data profile scan generating automated table statistics.",
48+
data=dataplex_v1.DataSource(resource=bigquery_table),
49+
data_profile_spec=data_profile_spec,
50+
)
51+
52+
request = dataplex_v1.CreateDataScanRequest(
53+
parent=parent,
54+
data_scan=data_scan,
55+
)
56+
57+
try:
58+
operation = client.create_data_scan(request=request)
59+
print(operation.result())
60+
61+
except google.api_core.exceptions.AlreadyExists:
62+
print("A scan with this ID already exists.")
63+
except google.api_core.exceptions.InvalidArgument as e:
64+
print(f"Your scan configuration is invalid: {e}")
65+
except google.api_core.exceptions.GoogleAPIError as e:
66+
print(f"Unexpected exception: {e}")
67+
68+
69+
# [END dataplex_create_data_profile_scan_global]

0 commit comments

Comments
 (0)