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

Add target project which differs from source in sandbox #353

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .sqlfluff
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ unwrap_wrapped_queries = True
[sqlfluff:templater:python:context]
project_id = project_id
dataset_id = dataset_id
target_project = target_project
target_dataset = target_dataset
table_id = table_id
batch_id = batch_id
Expand Down
2 changes: 1 addition & 1 deletion dags/queries/create_table.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create or replace table `{project_id}.{target_dataset}.{table_id}`
create or replace table `{target_project}.{target_dataset}.{table_id}`
partition by date_trunc(batch_run_date, day)
options (partition_expiration_days = 180) as (
select *
Expand Down
2 changes: 1 addition & 1 deletion dags/queries/create_view.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
create or replace view `{project_id}.{target_dataset}.{table_id}` as (
create or replace view `{target_project}.{target_dataset}.{table_id}` as (
select * from `{project_id}.{dataset_id}.{table_id}`
)
4 changes: 2 additions & 2 deletions dags/queries/update_table.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
insert into {project_id}.{target_dataset}.{table_id}
insert into `{target_project}.{target_dataset}.{table_id}`
select *
from {project_id}.{dataset_id}.{table_id}
from `{project_id}.{dataset_id}.{table_id}`
where date_trunc(batch_run_date, day) = date_trunc(cast('{batch_run_date}' as datetime), day)
3 changes: 3 additions & 0 deletions dags/sandbox_create_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
) as dag:
PROJECT = Variable.get("public_project")
DATASET = Variable.get("public_dataset")
SANDBOX_PROJECT = Variable.get("bq_project")
SANDBOX_DATASET = Variable.get("sandbox_dataset")
DBT_DATASET = Variable.get("dbt_mart_dataset")
TABLES_ID = Variable.get("table_ids", deserialize_json=True)
Expand All @@ -47,6 +48,7 @@
"project_id": PROJECT,
"dataset_id": DATASET,
"table_id": TABLES_ID[table_id],
"target_project": SANDBOX_PROJECT,
"target_dataset": SANDBOX_DATASET,
}
query = query.format(**sql_params)
Expand All @@ -70,6 +72,7 @@
"project_id": PROJECT,
"dataset_id": DBT_DATASET,
"table_id": DBT_TABLES[dbt_table],
"target_project": SANDBOX_PROJECT,
"target_dataset": SANDBOX_DATASET,
}
query = query.format(**sql_params)
Expand Down
2 changes: 2 additions & 0 deletions dags/sandbox_update_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
TABLES_ID = Variable.get("table_ids", deserialize_json=True)
PROJECT = Variable.get("public_project")
BQ_DATASET = Variable.get("public_dataset")
SANDBOX_PROJECT = Variable.get("bq_project")
SANDBOX_DATASET = Variable.get("sandbox_dataset")

batch_run_date = "{{ batch_run_date_as_datetime_string(dag, data_interval_start) }}"
Expand All @@ -63,6 +64,7 @@
"project_id": PROJECT,
"dataset_id": BQ_DATASET,
"table_id": TABLES_ID[table_id],
"target_project": SANDBOX_PROJECT,
"target_dataset": SANDBOX_DATASET,
"batch_run_date": batch_run_date,
}
Expand Down
Loading