Skip to content

Commit

Permalink
trying workaround for labeling scheduled queries
Browse files Browse the repository at this point in the history
  • Loading branch information
cleentfaar committed Dec 11, 2024
1 parent a350020 commit 7629703
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions terraform/bigquery_scheduled_data_transfer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ resource "google_bigquery_data_transfer_config" "default" {
destination_dataset_id = var.destination_dataset_id

params = {
destination_table_name_template = var.destination_table_name_template
query = templatefile(
var.query_template,
merge(var.query_variables, { interval = try(local.bigquery_interval_mappings[var.interval], var.interval) })
"./scheduled_query_with_labels.sql",
{
LABELS_STRING = join("\n", [for key, value in var.labels : format("SET @@query_label = \"%s:%s\";", key, value)])
ORIGINAL_QUERY = templatefile(
var.query_template,
merge(var.query_variables, { interval = try(local.bigquery_interval_mappings[var.interval], var.interval) })
)
}
)
destination_table_name_template = var.destination_table_name_template
write_disposition = var.write_disposition
write_disposition = var.write_disposition
}

# formatting rules are quite hard to generalize, see: https://cloud.google.com/appengine/docs/flexible/scheduling-jobs-with-cron-yaml#cron_yaml_The_schedule_format
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
${LABELS_STRING}
${ORIGINAL_QUERY}

0 comments on commit 7629703

Please sign in to comment.