From 827e6a552a2ebb2cf2366264e43ec67fb6d14c2f Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Thu, 11 Aug 2022 11:36:30 -0400 Subject: [PATCH 01/13] fix: uses function more appropriate to the described title --- samples/create_job.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/samples/create_job.py b/samples/create_job.py index 39922f7ae..c3c3a287b 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -26,20 +26,26 @@ def create_job() -> "bigquery.QueryJob": # Construct a BigQuery client object. client = bigquery.Client() - query_job = client.query( - "SELECT country_name from `bigquery-public-data.utility_us.country_code_iso`", - # Explicitly force job execution to be routed to a specific processing - # location. - location="US", - # Specify a job configuration to set optional job resource properties. - job_config=bigquery.QueryJobConfig( - labels={"example-label": "example-value"}, maximum_bytes_billed=1000000 - ), - # The client libraries automatically generate a job ID. Override the - # generated ID with either the job_id_prefix or job_id parameters. - job_id_prefix="code_sample_", + query_job = client.create_job( + # Specify a job configuration, providing both query + # and to set optional job resource properties, if needed. + # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob + # Here, we demonstrate a "query" job. + job_config={ + "query": { + "query": + """ + SELECT country_name + FROM `bigquery-public-data.utility_us.country_code_iso` + LIMIT 5 + """, + }, + "labels": {"example-label": "example-value"}, + "maximum_bytes_billed": 10000000 + } ) # Make an API request. print("Started job: {}".format(query_job.job_id)) # [END bigquery_create_job] + return query_job From bab1dbddfcc13730254c21a61c14c8e820797b8e Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Thu, 11 Aug 2022 11:50:40 -0400 Subject: [PATCH 02/13] adds additional explanation for the end users --- samples/create_job.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/samples/create_job.py b/samples/create_job.py index c3c3a287b..07c680e9b 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -31,6 +31,12 @@ def create_job() -> "bigquery.QueryJob": # and to set optional job resource properties, if needed. # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob # Here, we demonstrate a "query" job. + # NOTE: the preferred approach is to use one of the dedicated API calls: + # client.query() + # client.extract_table() + # client.copy_table() + # client.load_table_file(), client.load_table_from_dataframe(), etc + job_config={ "query": { "query": From 4aa34c1bbdfd69d32ac89a6284895b94b2580cfd Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Thu, 11 Aug 2022 14:27:20 -0400 Subject: [PATCH 03/13] adds REST API URL for reference --- samples/create_job.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/create_job.py b/samples/create_job.py index 07c680e9b..2a5da10d6 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -31,6 +31,8 @@ def create_job() -> "bigquery.QueryJob": # and to set optional job resource properties, if needed. # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob # Here, we demonstrate a "query" job. + # Reference: https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client.create_job + # # NOTE: the preferred approach is to use one of the dedicated API calls: # client.query() # client.extract_table() From 9ca399db9f1c789de2231e6c082233ac20a87572 Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Thu, 11 Aug 2022 14:49:24 -0400 Subject: [PATCH 04/13] corrects flake 8 linter errors --- samples/create_job.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/samples/create_job.py b/samples/create_job.py index 2a5da10d6..647b61b5b 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -27,9 +27,9 @@ def create_job() -> "bigquery.QueryJob": client = bigquery.Client() query_job = client.create_job( - # Specify a job configuration, providing both query + # Specify a job configuration, providing both query # and to set optional job resource properties, if needed. - # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob + # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob # Here, we demonstrate a "query" job. # Reference: https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client.create_job # @@ -37,20 +37,19 @@ def create_job() -> "bigquery.QueryJob": # client.query() # client.extract_table() # client.copy_table() - # client.load_table_file(), client.load_table_from_dataframe(), etc + # client.load_table_file(), client.load_table_from_dataframe(), etc job_config={ - "query": { - "query": - """ - SELECT country_name - FROM `bigquery-public-data.utility_us.country_code_iso` - LIMIT 5 - """, - }, + "query": { + "query": """ + SELECT country_name + FROM `bigquery-public-data.utility_us.country_code_iso` + LIMIT 5 + """, + }, "labels": {"example-label": "example-value"}, - "maximum_bytes_billed": 10000000 - } + "maximum_bytes_billed": 10000000 + } ) # Make an API request. print("Started job: {}".format(query_job.job_id)) From d270a5735bd95c267fecabbd7ac9f8e58feb5255 Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Fri, 12 Aug 2022 12:02:51 -0400 Subject: [PATCH 05/13] blackens file --- samples/create_job.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/create_job.py b/samples/create_job.py index 647b61b5b..0b714e1a7 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -38,7 +38,6 @@ def create_job() -> "bigquery.QueryJob": # client.extract_table() # client.copy_table() # client.load_table_file(), client.load_table_from_dataframe(), etc - job_config={ "query": { "query": """ @@ -48,7 +47,7 @@ def create_job() -> "bigquery.QueryJob": """, }, "labels": {"example-label": "example-value"}, - "maximum_bytes_billed": 10000000 + "maximum_bytes_billed": 10000000, } ) # Make an API request. From 5064f0e3d32c1c64a6bdbad0565c6ab4f3dfb7ef Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Mon, 29 Aug 2022 15:51:04 +0000 Subject: [PATCH 06/13] adds type hints --- samples/create_job.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/create_job.py b/samples/create_job.py index 0b714e1a7..789248e96 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -13,12 +13,14 @@ # limitations under the License. import typing +from typing import Union if typing.TYPE_CHECKING: from google.cloud import bigquery + from google.cloud.bigquery import LoadJob, CopyJob, ExtractJob, QueryJob -def create_job() -> "bigquery.QueryJob": +def create_job() -> "Union[LoadJob, CopyJob, ExtractJob, QueryJob]": # [START bigquery_create_job] from google.cloud import bigquery From 65773896d4d642123cf5d9b56573394a81d4de21 Mon Sep 17 00:00:00 2001 From: Chalmer Date: Mon, 29 Aug 2022 16:03:50 +0000 Subject: [PATCH 07/13] avoids unreliable version of grpcio --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index c6f7c76b1..f353abe77 100644 --- a/noxfile.py +++ b/noxfile.py @@ -288,7 +288,7 @@ def prerelease_deps(session): "google-cloud-bigquery-storage", "google-cloud-core", "google-resumable-media", - "grpcio", + "grpcio==1.48.0rc1", ) session.install( "freezegun", From b34b63f1556e1f36f92a9b169fa368aa0bde740a Mon Sep 17 00:00:00 2001 From: Chalmer Date: Mon, 29 Aug 2022 16:42:15 +0000 Subject: [PATCH 08/13] updates imports to fix linting error --- samples/create_job.py | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/create_job.py b/samples/create_job.py index 789248e96..4d2c43fa1 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -16,7 +16,6 @@ from typing import Union if typing.TYPE_CHECKING: - from google.cloud import bigquery from google.cloud.bigquery import LoadJob, CopyJob, ExtractJob, QueryJob From 3e4e8ce0c4ce1cac86bc1e6eb8b484c013c2f81b Mon Sep 17 00:00:00 2001 From: Chalmer Date: Mon, 29 Aug 2022 18:27:40 +0000 Subject: [PATCH 09/13] better method to avoid grpcio 1.49.0rc1 --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index f353abe77..81ff63baa 100644 --- a/noxfile.py +++ b/noxfile.py @@ -288,7 +288,7 @@ def prerelease_deps(session): "google-cloud-bigquery-storage", "google-cloud-core", "google-resumable-media", - "grpcio==1.48.0rc1", + "grpcio!=1.49.0rc1", ) session.install( "freezegun", From 5d93700d1b993fc70047f0f66a2ee2e8b88ae8ba Mon Sep 17 00:00:00 2001 From: Chalmer Lowe Date: Wed, 31 Aug 2022 08:25:13 -0400 Subject: [PATCH 10/13] Update samples/create_job.py Co-authored-by: Dan Lee <71398022+dandhlee@users.noreply.github.com> --- samples/create_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/create_job.py b/samples/create_job.py index 4d2c43fa1..11ab7aadc 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -52,7 +52,7 @@ def create_job() -> "Union[LoadJob, CopyJob, ExtractJob, QueryJob]": } ) # Make an API request. - print("Started job: {}".format(query_job.job_id)) + print(f"Started job: {query_job.job_id}") # [END bigquery_create_job] return query_job From acc7a01c2052ca5d1d1f1794494cbfe82e677385 Mon Sep 17 00:00:00 2001 From: Chalmer Date: Thu, 1 Sep 2022 16:39:06 +0000 Subject: [PATCH 11/13] adds further explanation on when/why to use create_jobs --- samples/create_job.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/samples/create_job.py b/samples/create_job.py index 11ab7aadc..f5527261c 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -28,13 +28,20 @@ def create_job() -> "Union[LoadJob, CopyJob, ExtractJob, QueryJob]": client = bigquery.Client() query_job = client.create_job( - # Specify a job configuration, providing both query - # and to set optional job resource properties, if needed. + # Specify a job configuration, providing a query + # and/or optional job resource properties, as needed. # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob # Here, we demonstrate a "query" job. # Reference: https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client.create_job # - # NOTE: the preferred approach is to use one of the dedicated API calls: + # Example use cases for .create_job() include: + # * to retry failed jobs + # * to generate jobs with an experimental API property that hasn't + # been added to one of the manually written job configuration + # classes yet + # + # NOTE: unless it is necessary to create a job in this way, the + # preferred approach is to use one of the dedicated API calls: # client.query() # client.extract_table() # client.copy_table() From 34bcf923b3d73a7468c3eea3f41e9777fdedd390 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Thu, 1 Sep 2022 16:41:09 +0000 Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- samples/create_job.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/create_job.py b/samples/create_job.py index f5527261c..781419a2b 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -40,7 +40,7 @@ def create_job() -> "Union[LoadJob, CopyJob, ExtractJob, QueryJob]": # been added to one of the manually written job configuration # classes yet # - # NOTE: unless it is necessary to create a job in this way, the + # NOTE: unless it is necessary to create a job in this way, the # preferred approach is to use one of the dedicated API calls: # client.query() # client.extract_table() From fb0f1f5b30c59d72a54f6b26d393ced6727aa628 Mon Sep 17 00:00:00 2001 From: Chalmer Date: Thu, 1 Sep 2022 17:37:01 +0000 Subject: [PATCH 13/13] updates references --- samples/create_job.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/create_job.py b/samples/create_job.py index 781419a2b..129a08a1b 100644 --- a/samples/create_job.py +++ b/samples/create_job.py @@ -32,7 +32,9 @@ def create_job() -> "Union[LoadJob, CopyJob, ExtractJob, QueryJob]": # and/or optional job resource properties, as needed. # The job instance can be a LoadJob, CopyJob, ExtractJob, QueryJob # Here, we demonstrate a "query" job. - # Reference: https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client.create_job + # References: + # https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.client.Client.html#google.cloud.bigquery.client.Client.create_job + # https://cloud.google.com/bigquery/docs/reference/rest/v2/Job # # Example use cases for .create_job() include: # * to retry failed jobs