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

🐛 Destination BigQuery: Handle embedded project ID in dataset ID during normalization #11077

Merged
merged 5 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,24 @@ def get_ssh_altered_config(config: Dict[str, Any], port_key: str = "port", host_
def transform_bigquery(config: Dict[str, Any]):
print("transform_bigquery")
# https://docs.getdbt.com/reference/warehouse-profiles/bigquery-profile

project_id = config["project_id"]
dataset_id = config["dataset_id"]

if ":" in config["dataset_id"]:
splits = config["dataset_id"].split(":")
if len(splits) > 2:
raise ValueError("Invalid format for dataset ID (expected at most one colon)")
project_id, dataset_id = splits
if project_id != config["project_id"]:
raise ValueError(
f"Project ID in dataset ID did not match explicitly-provided project ID: {project_id} and {config['project_id']}"
)

dbt_config = {
"type": "bigquery",
"project": config["project_id"],
"dataset": config["dataset_id"],
"project": project_id,
"dataset": dataset_id,
"priority": config.get("transformation_priority", "interactive"),
"threads": 8,
"retries": 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,41 @@ def test_transform_bigquery_no_credentials(self):
assert expected_output == actual_output
assert extract_schema(actual_output) == "my_dataset_id"

def test_transform_bigquery_with_embedded_project_id(self):
input = {"project_id": "my_project_id", "dataset_id": "my_project_id:my_dataset_id"}

actual_output = TransformConfig().transform_bigquery(input)
expected_output = {
"type": "bigquery",
"method": "oauth",
"project": "my_project_id",
"dataset": "my_dataset_id",
"priority": "interactive",
"retries": 3,
"threads": 8,
}

assert expected_output == actual_output
assert extract_schema(actual_output) == "my_dataset_id"

def test_transform_bigquery_with_embedded_mismatched_project_id(self):
input = {"project_id": "my_project_id", "dataset_id": "bad_project_id:my_dataset_id"}

try:
TransformConfig().transform_bigquery(input)
assert False, "transform_bigquery should have raised an exception"
except ValueError:
pass

def test_transform_bigquery_with_invalid_format(self):
input = {"project_id": "my_project_id", "dataset_id": "foo:bar:baz"}

try:
TransformConfig().transform_bigquery(input)
assert False, "transform_bigquery should have raised an exception"
except ValueError:
pass

def test_transform_postgres(self):
input = {
"host": "airbyte.io",
Expand Down