From 0ce3268cf3c9b788d78a7f7becd55d467c664e9d Mon Sep 17 00:00:00 2001 From: Christa Carpentiere Date: Thu, 11 Dec 2025 23:11:14 +0000 Subject: [PATCH 1/3] feat(bigquery): Add example for running a query job --- bigquery/bigquery_query/main.tf | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bigquery/bigquery_query/main.tf diff --git a/bigquery/bigquery_query/main.tf b/bigquery/bigquery_query/main.tf new file mode 100644 index 00000000..20833bff --- /dev/null +++ b/bigquery/bigquery_query/main.tf @@ -0,0 +1,26 @@ +/** +* Copyright 2025 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. +*/ + + +# [START bigquery_query] +resource "google_bigquery_job" "my_query_job" { + job_id = "my_query_job" + + query { + query = "SELECT name, SUM(number) AS total FROM `bigquery-public-data.usa_names.usa_1910_2013` GROUP BY name ORDER BY total DESC LIMIT 10;" + } +} +# [END bigquery_query] From 88db01f800841a27f77c8e6a9eef437322c1e40d Mon Sep 17 00:00:00 2001 From: Christa Carpentiere Date: Tue, 16 Dec 2025 21:49:33 +0000 Subject: [PATCH 2/3] feat(bigquery): Add example for running a query job --- bigquery/bigquery_query/main.tf | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bigquery/bigquery_query/main.tf b/bigquery/bigquery_query/main.tf index 20833bff..c474c116 100644 --- a/bigquery/bigquery_query/main.tf +++ b/bigquery/bigquery_query/main.tf @@ -14,13 +14,25 @@ * limitations under the License. */ - # [START bigquery_query] + +resource "random_string" "job_id" { + lower = true + length = 16 + special = false + + keepers = { + uuid = uuid() + } +} + +# Create a query. resource "google_bigquery_job" "my_query_job" { - job_id = "my_query_job" + job_id = random_string.job_id.id query { - query = "SELECT name, SUM(number) AS total FROM `bigquery-public-data.usa_names.usa_1910_2013` GROUP BY name ORDER BY total DESC LIMIT 10;" + query = "SELECT name, SUM(number) AS total FROM `bigquery-public-data.usa_names.usa_1910_2013` GROUP BY name ORDER BY total DESC LIMIT 100;" } } + # [END bigquery_query] From 14783d3800be9bceba89daaf809b21d514f3bc6c Mon Sep 17 00:00:00 2001 From: Christa Carpentiere Date: Tue, 16 Dec 2025 21:56:28 +0000 Subject: [PATCH 3/3] feat(bigquery): Add example for running a query job --- bigquery/bigquery_query/main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bigquery/bigquery_query/main.tf b/bigquery/bigquery_query/main.tf index c474c116..67bbf306 100644 --- a/bigquery/bigquery_query/main.tf +++ b/bigquery/bigquery_query/main.tf @@ -16,6 +16,7 @@ # [START bigquery_query] +# Generate a unique job ID. resource "random_string" "job_id" { lower = true length = 16 @@ -26,7 +27,7 @@ resource "random_string" "job_id" { } } -# Create a query. +# Create a query using the generated job ID. resource "google_bigquery_job" "my_query_job" { job_id = random_string.job_id.id