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-bigquery-migration #10260

Merged
merged 31 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2604a48
docs(samples): add create_migration_workflow snippet (#71)
steffnay May 20, 2022
f4c5a74
chore(deps): update all dependencies (#73)
renovate-bot May 22, 2022
89d7c57
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot May 25, 2022
cd5db84
chore(deps): update all dependencies (#93)
renovate-bot May 27, 2022
76b97a2
chore(deps): update all dependencies (#111)
renovate-bot Aug 2, 2022
d7fb80f
chore(deps): update all dependencies (#113)
renovate-bot Aug 5, 2022
3697ef4
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Aug 16, 2022
f22d37e
chore(deps): update dependency google-api-core to v2.10.0 (#126)
renovate-bot Sep 2, 2022
e1bc989
chore(deps): update dependency pytest to v7.1.3 (#130)
renovate-bot Sep 6, 2022
643ee60
chore(deps): update dependency google-api-core to v2.10.1 (#135)
renovate-bot Sep 14, 2022
e89ad52
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Oct 4, 2022
657bda8
chore(deps): update dependency google-api-core to v2.10.2 (#141)
renovate-bot Oct 8, 2022
5be63cb
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Oct 10, 2022
8444057
chore(deps): update dependency pytest to v7.2.0 (#143)
renovate-bot Oct 26, 2022
bfbcea7
chore(deps): update dependency google-cloud-storage to v2.6.0 (#146)
renovate-bot Nov 21, 2022
6f9eab4
chore(deps): update dependency google-api-core to v2.11.0 (#151)
renovate-bot Dec 15, 2022
2fddf56
chore(deps): update dependency google-cloud-storage to v2.7.0 (#154)
renovate-bot Dec 15, 2022
dd1a164
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Dec 16, 2022
46a18a6
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Jan 11, 2023
aef0887
chore(deps): update dependency pytest to v7.2.1 (#160)
renovate-bot Jan 14, 2023
791ab4a
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Jan 23, 2023
76da3d5
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Mar 1, 2023
92e58f6
chore(deps): update dependency pytest to v7.2.2 (#173)
renovate-bot Mar 4, 2023
84cbefc
chore(deps): update dependency google-cloud-bigquery-migration to v0.…
renovate-bot Mar 28, 2023
3590d9b
chore(deps): update dependency google-cloud-storage to v2.8.0 (#179)
renovate-bot Apr 6, 2023
cef10fc
chore(deps): update dependency pytest to v7.3.1 (#180)
renovate-bot Apr 15, 2023
3553843
chore(deps): update dependency google-cloud-storage to v2.9.0 (#184)
renovate-bot Jun 1, 2023
b88278a
chore(deps): update dependency pytest to v7.3.2 (#186)
renovate-bot Jun 13, 2023
b736583
skip python-2.7 and python-3.6 in sample test
dizcology Jun 16, 2023
b8aa0d2
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Jun 20, 2023
328f00d
update CODEOWNERS for bigquery-migration
dizcology Jul 11, 2023
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 @@ -99,6 +99,7 @@
/cloud-media-livestream/**/* @GoogleCloudPlatform/cloud-media-team @GoogleCloudPlatform/python-samples-reviewers
/bigquery-connection/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/bigquery-datatransfer/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/bigquery-migration/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/dlp/**/* @GoogleCloudPlatform/googleapis-dlp @GoogleCloudPlatform/python-samples-reviewers
/functions/spanner/* @GoogleCloudPlatform/api-spanner-python @GoogleCloudPlatform/functions-framework-google @GoogleCloudPlatform/python-samples-reviewers
/healthcare/**/* @GoogleCloudPlatform/healthcare-life-sciences @GoogleCloudPlatform/python-samples-reviewers
Expand Down
15 changes: 15 additions & 0 deletions bigquery-migration/snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
#
# Copyright 2022 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.
73 changes: 73 additions & 0 deletions bigquery-migration/snippets/create_migration_workflow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright 2022 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.


# [START bigquery_migration_create_workflow]
def create_migration_workflow(
gcs_input_path: str, gcs_output_path: str, project_id: str
) -> None:
"""Creates a migration workflow of a Batch SQL Translation and prints the response."""

from google.cloud import bigquery_migration_v2

parent = f"projects/{project_id}/locations/us"

# Construct a BigQuery Migration client object.
client = bigquery_migration_v2.MigrationServiceClient()

# Set the source dialect to Teradata SQL.
source_dialect = bigquery_migration_v2.Dialect()
source_dialect.teradata_dialect = bigquery_migration_v2.TeradataDialect(
mode=bigquery_migration_v2.TeradataDialect.Mode.SQL
)

# Set the target dialect to BigQuery dialect.
target_dialect = bigquery_migration_v2.Dialect()
target_dialect.bigquery_dialect = bigquery_migration_v2.BigQueryDialect()

# Prepare the config proto.
translation_config = bigquery_migration_v2.TranslationConfigDetails(
gcs_source_path=gcs_input_path,
gcs_target_path=gcs_output_path,
source_dialect=source_dialect,
target_dialect=target_dialect,
)

# Prepare the task.
migration_task = bigquery_migration_v2.MigrationTask(
type_="Translation_Teradata2BQ", translation_config_details=translation_config
)

# Prepare the workflow.
workflow = bigquery_migration_v2.MigrationWorkflow(
display_name="demo-workflow-python-example-Teradata2BQ"
)

workflow.tasks["translation-task"] = migration_task # type: ignore

# Prepare the API request to create a migration workflow.
request = bigquery_migration_v2.CreateMigrationWorkflowRequest(
parent=parent,
migration_workflow=workflow,
)

response = client.create_migration_workflow(request=request)

print("Created workflow:")
print(response.display_name)
print("Current state:")
print(response.State(response.state))


# [END bigquery_migration_create_workflow]
66 changes: 66 additions & 0 deletions bigquery-migration/snippets/create_migration_workflow_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2022 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.


from typing import Iterable, List, Optional

from google.api_core.exceptions import (
InternalServerError,
ServiceUnavailable,
TooManyRequests,
)
from google.cloud import storage
import pytest
from test_utils.retry import RetryErrors
from test_utils.system import unique_resource_id

from . import create_migration_workflow

retry_storage_errors = RetryErrors(
(TooManyRequests, InternalServerError, ServiceUnavailable)
)

storage_client = storage.Client()
PROJECT_ID = storage_client.project


def _create_bucket(bucket_name: str, location: Optional[str] = None) -> storage.Bucket:
bucket = storage_client.bucket(bucket_name)
retry_storage_errors(storage_client.create_bucket)(bucket_name, location=location)

return bucket


@pytest.fixture
def buckets_to_delete() -> Iterable[List]:
doomed = []
yield doomed
for item in doomed:
if isinstance(item, storage.Bucket):
retry_storage_errors(item.delete)(force=True)


def test_create_migration_workflow(
capsys: pytest.CaptureFixture, buckets_to_delete: List[storage.Bucket]
) -> None:
bucket_name = "bq_migration_create_workflow_test" + unique_resource_id()
path = f"gs://{PROJECT_ID}/{bucket_name}"
bucket = _create_bucket(bucket_name)
buckets_to_delete.extend([bucket])

create_migration_workflow.create_migration_workflow(path, path, PROJECT_ID)
out, _ = capsys.readouterr()

assert "demo-workflow-python-example-Teradata2BQ" in out
assert "Current state:" in out
38 changes: 38 additions & 0 deletions bigquery-migration/snippets/noxfile_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2021 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
#
# http://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.

# Default TEST_CONFIG_OVERRIDE for python repos.

# You can copy this file into your directory, then it will be inported from
# the noxfile.py.

# The source of truth:
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py

TEST_CONFIG_OVERRIDE = {
# You can opt out from the test for specific Python versions.
"ignored_versions": ["2.7", "3.6"],
# Old samples are opted out of enforcing Python type hints
# All new samples should feature them
"enforce_type_hints": True,
# An envvar key for determining the project id to use. Change it
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
# build specific Cloud project. You can also use your own string
# to use your own Cloud project.
# "gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
# A dictionary you want to inject into your test. Don't put any
# secrets here. These values will override predefined values.
"envs": {},
}
4 changes: 4 additions & 0 deletions bigquery-migration/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest==7.3.2
google-cloud-testutils==1.3.3
google-api-core==2.11.0
google-cloud-storage==2.9.0
1 change: 1 addition & 0 deletions bigquery-migration/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-cloud-bigquery-migration==0.11.0