-
Notifications
You must be signed in to change notification settings - Fork 286
feat(bigquery): Add example for running a query job #912
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure you want to actually include job_id here. I see it's used in the example, but I haven't tried this out. If I look at the rest resource it's definitely not including something for query about the job_id. I suspect it might work once but if you ran it again it would fail. I think if you remove it, it will consistently work, but I could be wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Job ID is required. Agreed, you can't re-run without iterating on the job ID. Looks like maybe I could use https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/uuid to generate a unique ID? Let me give that a try.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, that would be helpful. Thank you! |
||
|
|
||
| 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;" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: the other samples have slightly different SQL, the majority do a LIMIT 100 so would be helpful to do the same here. |
||
| } | ||
| } | ||
| # [END bigquery_query] | ||
Uh oh!
There was an error while loading. Please reload this page.